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 "config.h" | 26 #include "config.h" |
27 #include "platform/graphics/DecodingImageGenerator.h" | 27 #include "platform/graphics/DecodingImageGenerator.h" |
28 | 28 |
29 #include "platform/PlatformInstrumentation.h" | 29 #include "platform/PlatformInstrumentation.h" |
30 #include "platform/RuntimeEnabledFeatures.h" | |
31 #include "platform/SharedBuffer.h" | 30 #include "platform/SharedBuffer.h" |
32 #include "platform/TraceEvent.h" | 31 #include "platform/TraceEvent.h" |
33 #include "platform/graphics/ImageFrameGenerator.h" | 32 #include "platform/graphics/ImageFrameGenerator.h" |
34 #include "platform/image-decoders/ImageDecoder.h" | 33 #include "platform/image-decoders/ImageDecoder.h" |
35 #include "third_party/skia/include/core/SkData.h" | 34 #include "third_party/skia/include/core/SkData.h" |
36 | 35 |
37 namespace blink { | 36 namespace blink { |
38 | 37 |
39 DecodingImageGenerator::DecodingImageGenerator(PassRefPtr<ImageFrameGenerator> f rameGenerator, const SkImageInfo& info, size_t index) | 38 DecodingImageGenerator::DecodingImageGenerator(PassRefPtr<ImageFrameGenerator> f rameGenerator, const SkImageInfo& info, size_t index) |
40 : SkImageGenerator(info) | 39 : SkImageGenerator(info) |
41 , m_frameGenerator(frameGenerator) | 40 , m_frameGenerator(frameGenerator) |
42 , m_frameIndex(index) | 41 , m_frameIndex(index) |
43 , m_generationId(0) | 42 , m_generationId(0) |
43 , m_canYUVDecode(false) | |
44 { | 44 { |
45 } | 45 } |
46 | 46 |
47 DecodingImageGenerator::~DecodingImageGenerator() | 47 DecodingImageGenerator::~DecodingImageGenerator() |
48 { | 48 { |
49 } | 49 } |
50 | 50 |
51 SkData* DecodingImageGenerator::onRefEncodedData() | 51 SkData* DecodingImageGenerator::onRefEncodedData() |
52 { | 52 { |
53 TRACE_EVENT0("blink", "DecodingImageGenerator::refEncodedData"); | 53 TRACE_EVENT0("blink", "DecodingImageGenerator::refEncodedData"); |
54 | 54 |
55 // FIXME: If the image has been clipped or scaled, do not return the origina l | 55 // FIXME: If the image has been clipped or scaled, do not return the origina l |
56 // encoded data, since on playback it will not be known how the clipping/sca ling | 56 // encoded data, since on playback it will not be known how the clipping/sca ling |
57 // was done. | 57 // was done. |
58 RefPtr<SharedBuffer> buffer = nullptr; | 58 RefPtr<SharedBuffer> buffer = nullptr; |
59 bool allDataReceived = false; | 59 bool allDataReceived = false; |
60 m_frameGenerator->copyData(&buffer, &allDataReceived); | 60 m_frameGenerator->copyData(&buffer, &allDataReceived); |
61 if (buffer && allDataReceived) | 61 if (buffer && allDataReceived) |
62 return SkData::NewWithCopy(buffer->data(), buffer->size()); | 62 return SkData::NewWithCopy(buffer->data(), buffer->size()); |
63 return 0; | 63 return 0; |
64 } | 64 } |
65 | 65 |
66 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, | 66 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkPMColor table[], int* tableCount) |
67 SkPMColor ctable[], int* ctableCount) | |
68 { | 67 { |
69 TRACE_EVENT1("blink", "DecodingImageGenerator::getPixels", "frame index", st atic_cast<int>(m_frameIndex)); | 68 TRACE_EVENT1("blink", "DecodingImageGenerator::getPixels", "frame index", st atic_cast<int>(m_frameIndex)); |
70 | 69 |
71 // Implementation doesn't support scaling yet so make sure we're not given a different size. | 70 // Implementation doesn't support scaling yet so make sure we're not given a different size. |
72 if (info.width() != getInfo().width() || info.height() != getInfo().height() ) | 71 if (info.width() != getInfo().width() || info.height() != getInfo().height() ) |
73 return false; | 72 return false; |
74 | 73 |
75 if (info.colorType() != getInfo().colorType()) { | 74 if (info.colorType() != getInfo().colorType()) { |
76 // ImageFrame may have changed the owning SkBitmap to kOpaque_SkAlphaTyp e after sniffing the encoded data, so if we see a request | 75 // blink::ImageFrame may have changed the owning SkBitmap to kOpaque_SkA lphaType after fully decoding the image frame, |
77 // for opaque, that is ok even if our initial alphatype was not opaque. | 76 // so if we see a request for opaque, that is ok even if our initial alp ha type was not opaque. |
78 return false; | 77 return false; |
Noel Gordon
2015/12/08 01:48:10
Tried to correct this comment for what blink::Imag
scroggo
2015/12/08 15:11:28
It's trying to explain why we check that the color
| |
79 } | 78 } |
80 | 79 |
81 PlatformInstrumentation::willDecodeLazyPixelRef(m_generationId); | 80 PlatformInstrumentation::willDecodeLazyPixelRef(m_generationId); |
82 bool decoded = m_frameGenerator->decodeAndScale(getInfo(), m_frameIndex, pix els, rowBytes); | 81 bool decoded = m_frameGenerator->decodeAndScale(getInfo(), m_frameIndex, pix els, rowBytes); |
83 PlatformInstrumentation::didDecodeLazyPixelRef(); | 82 PlatformInstrumentation::didDecodeLazyPixelRef(); |
84 | 83 |
85 return decoded; | 84 return decoded; |
86 } | 85 } |
87 | 86 |
88 bool DecodingImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], SkYUVColorSpace* colorSpace) | 87 bool DecodingImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], SkYUVColorSpace* colorSpace) |
89 { | 88 { |
90 if (!RuntimeEnabledFeatures::decodeToYUVEnabled()) | 89 if (!m_canYUVDecode) |
91 return false; | 90 return false; |
92 | 91 |
93 bool requestingYUVSizes = !planes || !planes[0]; | 92 bool requestingYUVSizes = !planes || !planes[0]; |
94 | 93 |
95 TRACE_EVENT1("blink", "DecodingImageGenerator::getYUV8Planes", requestingYUV Sizes ? "sizes" : "frame index", static_cast<int>(m_frameIndex)); | 94 TRACE_EVENT1("blink", "DecodingImageGenerator::getYUV8Planes", requestingYUV Sizes ? "sizes" : "frame index", static_cast<int>(m_frameIndex)); |
96 | 95 |
97 if (requestingYUVSizes) | 96 if (requestingYUVSizes) |
98 return m_frameGenerator->getYUVComponentSizes(sizes); | 97 return m_frameGenerator->getYUVComponentSizes(sizes); |
99 | 98 |
99 if (colorSpace) | |
100 *colorSpace = kJPEG_SkYUVColorSpace; | |
101 | |
100 PlatformInstrumentation::willDecodeLazyPixelRef(m_generationId); | 102 PlatformInstrumentation::willDecodeLazyPixelRef(m_generationId); |
101 bool decoded = m_frameGenerator->decodeToYUV(sizes, planes, rowBytes); | 103 bool decoded = m_frameGenerator->decodeToYUV(sizes, planes, rowBytes); |
102 PlatformInstrumentation::didDecodeLazyPixelRef(); | 104 PlatformInstrumentation::didDecodeLazyPixelRef(); |
103 if (colorSpace) | |
104 *colorSpace = kJPEG_SkYUVColorSpace; | |
105 | 105 |
106 return decoded; | 106 return decoded; |
107 } | 107 } |
108 | 108 |
109 SkImageGenerator* DecodingImageGenerator::create(SkData* data) | 109 SkImageGenerator* DecodingImageGenerator::create(SkData* data) |
110 { | 110 { |
111 RefPtr<SharedBuffer> buffer = SharedBuffer::create(data->bytes(), data->size ()); | 111 RefPtr<SharedBuffer> buffer = SharedBuffer::create(data->bytes(), data->size ()); |
112 | 112 |
113 // We just need the size of the image, so we have to temporarily create an I mageDecoder. Since | 113 // We just need the size of the image, so we have to temporarily create an I mageDecoder. Since |
114 // we only need the size, it doesn't really matter about premul or not, or g amma settings. | 114 // we only need the size, it doesn't really matter about premul or not, or g amma settings. |
115 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*buffer.get(), ImageDeco der::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileApplied); | 115 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*buffer.get(), ImageDeco der::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileApplied); |
116 if (!decoder) | 116 if (!decoder) |
117 return 0; | 117 return 0; |
118 | 118 |
119 decoder->setData(buffer.get(), true); | 119 decoder->setData(buffer.get(), true); |
120 if (!decoder->isSizeAvailable()) | 120 if (!decoder->isSizeAvailable()) |
121 return 0; | 121 return 0; |
122 | 122 |
123 const IntSize size = decoder->size(); | 123 const IntSize size = decoder->size(); |
124 const SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.heigh t()); | 124 const SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.heigh t()); |
125 | 125 |
126 RefPtr<ImageFrameGenerator> frame = ImageFrameGenerator::create(SkISize::Mak e(size.width(), size.height()), buffer, true, false); | 126 RefPtr<ImageFrameGenerator> frame = ImageFrameGenerator::create(SkISize::Mak e(size.width(), size.height()), buffer, true, false); |
127 if (!frame) | 127 if (!frame) |
128 return 0; | 128 return 0; |
129 | 129 |
130 return new DecodingImageGenerator(frame, info, 0); | 130 return new DecodingImageGenerator(frame, info, 0); |
131 } | 131 } |
132 | 132 |
133 } // namespace blink | 133 } // namespace blink |
OLD | NEW |