| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| 11 * notice, this list of conditions and the following disclaimer in the | 11 * notice, this list of conditions and the following disclaimer in the |
| 12 * documentation and/or other materials provided with the distribution. | 12 * documentation and/or other materials provided with the distribution. |
| 13 * | 13 * |
| 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "platform/graphics/DecodingImageGenerator.h" | 26 #include "platform/graphics/DecodingImageGenerator.h" |
| 27 | 27 |
| 28 #include <memory> | 28 #include <memory> |
| 29 #include "platform/SharedBuffer.h" | 29 #include "platform/SharedBuffer.h" |
| 30 #include "platform/SharedBufferStep.h" |
| 30 #include "platform/graphics/ImageFrameGenerator.h" | 31 #include "platform/graphics/ImageFrameGenerator.h" |
| 31 #include "platform/image-decoders/ImageDecoder.h" | 32 #include "platform/image-decoders/ImageDecoder.h" |
| 32 #include "platform/image-decoders/SegmentReader.h" | 33 #include "platform/image-decoders/SegmentReader.h" |
| 33 #include "platform/instrumentation/PlatformInstrumentation.h" | 34 #include "platform/instrumentation/PlatformInstrumentation.h" |
| 34 #include "platform/instrumentation/tracing/TraceEvent.h" | 35 #include "platform/instrumentation/tracing/TraceEvent.h" |
| 35 #include "third_party/skia/include/core/SkData.h" | 36 #include "third_party/skia/include/core/SkData.h" |
| 36 | 37 |
| 37 namespace blink { | 38 namespace blink { |
| 38 | 39 |
| 39 DecodingImageGenerator::DecodingImageGenerator( | 40 DecodingImageGenerator::DecodingImageGenerator( |
| 40 PassRefPtr<ImageFrameGenerator> frame_generator, | 41 PassRefPtr<ImageFrameGenerator> frame_generator, |
| 41 const SkImageInfo& info, | 42 const SkImageInfo& info, |
| 42 PassRefPtr<SegmentReader> data, | 43 PassRefPtr<SegmentReader> reader, |
| 43 bool all_data_received, | 44 bool all_data_received, |
| 44 size_t index, | 45 size_t index, |
| 45 uint32_t unique_id) | 46 uint32_t unique_id) |
| 46 : SkImageGenerator(info, unique_id), | 47 : SkImageGenerator(info, unique_id), |
| 47 frame_generator_(std::move(frame_generator)), | 48 frame_generator_(std::move(frame_generator)), |
| 48 data_(std::move(data)), | 49 reader_(std::move(reader)), |
| 50 all_data_received_(all_data_received), |
| 51 frame_index_(index), |
| 52 can_yuv_decode_(false) {} |
| 53 |
| 54 DecodingImageGenerator::DecodingImageGenerator( |
| 55 PassRefPtr<ImageFrameGenerator> frame_generator, |
| 56 const SkImageInfo& info, |
| 57 PassRefPtr<SharedBuffer::ThreadSafeStepper> stepper, |
| 58 bool all_data_received, |
| 59 size_t index, |
| 60 uint32_t unique_id) |
| 61 : SkImageGenerator(info, unique_id), |
| 62 frame_generator_(std::move(frame_generator)), |
| 63 stepper_(std::move(stepper)), |
| 49 all_data_received_(all_data_received), | 64 all_data_received_(all_data_received), |
| 50 frame_index_(index), | 65 frame_index_(index), |
| 51 can_yuv_decode_(false) {} | 66 can_yuv_decode_(false) {} |
| 52 | 67 |
| 53 DecodingImageGenerator::~DecodingImageGenerator() {} | 68 DecodingImageGenerator::~DecodingImageGenerator() {} |
| 54 | 69 |
| 70 PassRefPtr<SegmentReader> DecodingImageGenerator::encoded_data() const { |
| 71 if (reader_) { |
| 72 return reader_; |
| 73 } |
| 74 |
| 75 RefPtr<SharedBufferStep> step = stepper_->current_step(); |
| 76 return SegmentReader::CreateFromSharedBufferStep(step); |
| 77 } |
| 78 |
| 55 SkData* DecodingImageGenerator::onRefEncodedData() { | 79 SkData* DecodingImageGenerator::onRefEncodedData() { |
| 56 TRACE_EVENT0("blink", "DecodingImageGenerator::refEncodedData"); | 80 TRACE_EVENT0("blink", "DecodingImageGenerator::refEncodedData"); |
| 57 | 81 |
| 58 // getAsSkData() may require copying, but the clients of this function are | 82 // getAsSkData() may require copying, but the clients of this function are |
| 59 // serializers, which want the data even if it requires copying, and even | 83 // serializers, which want the data even if it requires copying, and even |
| 60 // if the data is incomplete. (Otherwise they would potentially need to | 84 // if the data is incomplete. (Otherwise they would potentially need to |
| 61 // decode the partial image in order to re-encode it.) | 85 // decode the partial image in order to re-encode it.) |
| 62 return data_->GetAsSkData().release(); | 86 return encoded_data()->GetAsSkData().release(); |
| 63 } | 87 } |
| 64 | 88 |
| 65 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& dst_info, | 89 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& dst_info, |
| 66 void* pixels, | 90 void* pixels, |
| 67 size_t row_bytes, | 91 size_t row_bytes, |
| 68 const Options& options) { | 92 const Options& options) { |
| 69 TRACE_EVENT1("blink", "DecodingImageGenerator::getPixels", "frame index", | 93 TRACE_EVENT1("blink", "DecodingImageGenerator::getPixels", "frame index", |
| 70 static_cast<int>(frame_index_)); | 94 static_cast<int>(frame_index_)); |
| 71 | 95 |
| 72 // Implementation doesn't support scaling yet, so make sure we're not given a | 96 // Implementation doesn't support scaling yet, so make sure we're not given a |
| (...skipping 20 matching lines...) Expand all Loading... |
| 93 const bool needs_color_xform = | 117 const bool needs_color_xform = |
| 94 decode_color_space && dst_info.colorSpace() && | 118 decode_color_space && dst_info.colorSpace() && |
| 95 !SkColorSpace::Equals(decode_color_space, dst_info.colorSpace()); | 119 !SkColorSpace::Equals(decode_color_space, dst_info.colorSpace()); |
| 96 ImageDecoder::AlphaOption alpha_option = ImageDecoder::kAlphaPremultiplied; | 120 ImageDecoder::AlphaOption alpha_option = ImageDecoder::kAlphaPremultiplied; |
| 97 if (needs_color_xform && !decode_info.isOpaque()) { | 121 if (needs_color_xform && !decode_info.isOpaque()) { |
| 98 alpha_option = ImageDecoder::kAlphaNotPremultiplied; | 122 alpha_option = ImageDecoder::kAlphaNotPremultiplied; |
| 99 decode_info = decode_info.makeAlphaType(kUnpremul_SkAlphaType); | 123 decode_info = decode_info.makeAlphaType(kUnpremul_SkAlphaType); |
| 100 } | 124 } |
| 101 | 125 |
| 102 PlatformInstrumentation::WillDecodeLazyPixelRef(uniqueID()); | 126 PlatformInstrumentation::WillDecodeLazyPixelRef(uniqueID()); |
| 103 const bool decoded = frame_generator_->DecodeAndScale( | 127 RefPtr<SegmentReader> data = encoded_data(); |
| 104 data_.Get(), all_data_received_, frame_index_, decode_info, pixels, | 128 bool decoded = frame_generator_->DecodeAndScale( |
| 129 data.Get(), all_data_received_, frame_index_, decode_info, pixels, |
| 105 row_bytes, alpha_option); | 130 row_bytes, alpha_option); |
| 106 PlatformInstrumentation::DidDecodeLazyPixelRef(); | 131 PlatformInstrumentation::DidDecodeLazyPixelRef(); |
| 107 | 132 |
| 108 if (decoded && needs_color_xform) { | 133 if (decoded && needs_color_xform) { |
| 109 TRACE_EVENT0("blink", "DecodingImageGenerator::getPixels - apply xform"); | 134 TRACE_EVENT0("blink", "DecodingImageGenerator::getPixels - apply xform"); |
| 110 SkPixmap src(decode_info, pixels, row_bytes); | 135 SkPixmap src(decode_info, pixels, row_bytes); |
| 111 | 136 |
| 112 // kIgnore ensures that we perform the premultiply (if necessary) in the dst | 137 // kIgnore ensures that we perform the premultiply (if necessary) in the dst |
| 113 // space. | 138 // space. |
| 114 const bool converted = src.readPixels(dst_info, pixels, row_bytes, 0, 0, | 139 const bool converted = src.readPixels(dst_info, pixels, row_bytes, 0, 0, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 125 // in ImageFrameGenerator.h. | 150 // in ImageFrameGenerator.h. |
| 126 if (!can_yuv_decode_ || !all_data_received_) | 151 if (!can_yuv_decode_ || !all_data_received_) |
| 127 return false; | 152 return false; |
| 128 | 153 |
| 129 TRACE_EVENT1("blink", "DecodingImageGenerator::queryYUV8", "sizes", | 154 TRACE_EVENT1("blink", "DecodingImageGenerator::queryYUV8", "sizes", |
| 130 static_cast<int>(frame_index_)); | 155 static_cast<int>(frame_index_)); |
| 131 | 156 |
| 132 if (color_space) | 157 if (color_space) |
| 133 *color_space = kJPEG_SkYUVColorSpace; | 158 *color_space = kJPEG_SkYUVColorSpace; |
| 134 | 159 |
| 135 return frame_generator_->GetYUVComponentSizes(data_.Get(), size_info); | 160 RefPtr<SegmentReader> data = encoded_data(); |
| 161 return frame_generator_->GetYUVComponentSizes(data.Get(), size_info); |
| 136 } | 162 } |
| 137 | 163 |
| 138 bool DecodingImageGenerator::onGetYUV8Planes(const SkYUVSizeInfo& size_info, | 164 bool DecodingImageGenerator::onGetYUV8Planes(const SkYUVSizeInfo& size_info, |
| 139 void* planes[3]) { | 165 void* planes[3]) { |
| 140 // YUV decoding does not currently support progressive decoding. See comment | 166 // YUV decoding does not currently support progressive decoding. See comment |
| 141 // in ImageFrameGenerator.h. | 167 // in ImageFrameGenerator.h. |
| 142 DCHECK(can_yuv_decode_); | 168 DCHECK(can_yuv_decode_); |
| 143 DCHECK(all_data_received_); | 169 DCHECK(all_data_received_); |
| 144 | 170 |
| 145 TRACE_EVENT1("blink", "DecodingImageGenerator::getYUV8Planes", "frame index", | 171 TRACE_EVENT1("blink", "DecodingImageGenerator::getYUV8Planes", "frame index", |
| 146 static_cast<int>(frame_index_)); | 172 static_cast<int>(frame_index_)); |
| 147 | 173 |
| 148 PlatformInstrumentation::WillDecodeLazyPixelRef(uniqueID()); | 174 PlatformInstrumentation::WillDecodeLazyPixelRef(uniqueID()); |
| 175 RefPtr<SegmentReader> data = encoded_data(); |
| 149 bool decoded = | 176 bool decoded = |
| 150 frame_generator_->DecodeToYUV(data_.Get(), frame_index_, size_info.fSizes, | 177 frame_generator_->DecodeToYUV(data.Get(), frame_index_, size_info.fSizes, |
| 151 planes, size_info.fWidthBytes); | 178 planes, size_info.fWidthBytes); |
| 152 PlatformInstrumentation::DidDecodeLazyPixelRef(); | 179 PlatformInstrumentation::DidDecodeLazyPixelRef(); |
| 153 | 180 |
| 154 return decoded; | 181 return decoded; |
| 155 } | 182 } |
| 156 | 183 |
| 157 SkImageGenerator* DecodingImageGenerator::Create(SkData* data) { | 184 SkImageGenerator* DecodingImageGenerator::Create(SkData* data) { |
| 158 RefPtr<SegmentReader> segment_reader = | 185 RefPtr<SegmentReader> segment_reader = |
| 159 SegmentReader::CreateFromSkData(sk_ref_sp(data)); | 186 SegmentReader::CreateFromSkData(sk_ref_sp(data)); |
| 160 // We just need the size of the image, so we have to temporarily create an | 187 // We just need the size of the image, so we have to temporarily create an |
| (...skipping 14 matching lines...) Expand all Loading... |
| 175 ImageFrameGenerator::Create(SkISize::Make(size.Width(), size.Height()), | 202 ImageFrameGenerator::Create(SkISize::Make(size.Width(), size.Height()), |
| 176 false, decoder->GetColorBehavior()); | 203 false, decoder->GetColorBehavior()); |
| 177 if (!frame) | 204 if (!frame) |
| 178 return nullptr; | 205 return nullptr; |
| 179 | 206 |
| 180 return new DecodingImageGenerator(frame, info, std::move(segment_reader), | 207 return new DecodingImageGenerator(frame, info, std::move(segment_reader), |
| 181 true, 0); | 208 true, 0); |
| 182 } | 209 } |
| 183 | 210 |
| 184 } // namespace blink | 211 } // namespace blink |
| OLD | NEW |