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 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 } | 71 } |
72 | 72 |
73 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, | 73 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, |
74 void* pixels, | 74 void* pixels, |
75 size_t rowBytes, | 75 size_t rowBytes, |
76 SkPMColor table[], | 76 SkPMColor table[], |
77 int* tableCount) { | 77 int* tableCount) { |
78 TRACE_EVENT1("blink", "DecodingImageGenerator::getPixels", "frame index", | 78 TRACE_EVENT1("blink", "DecodingImageGenerator::getPixels", "frame index", |
79 static_cast<int>(m_frameIndex)); | 79 static_cast<int>(m_frameIndex)); |
80 | 80 |
81 // Implementation doesn't support scaling yet so make sure we're not given a d
ifferent size. | 81 // Implementation doesn't support scaling yet, so make sure we're not given a |
| 82 // different size. |
82 if (info.width() != getInfo().width() || info.height() != getInfo().height()) | 83 if (info.width() != getInfo().width() || info.height() != getInfo().height()) |
83 return false; | 84 return false; |
84 | 85 |
85 if (info.colorType() != getInfo().colorType()) { | 86 if (info.colorType() != getInfo().colorType()) { |
86 // blink::ImageFrame may have changed the owning SkBitmap to kOpaque_SkAlpha
Type after fully decoding the image frame, | 87 // blink::ImageFrame may have changed the owning SkBitmap to |
87 // so if we see a request for opaque, that is ok even if our initial alpha t
ype was not opaque. | 88 // kOpaque_SkAlphaType after fully decoding the image frame, so if we see a |
| 89 // request for opaque, that is ok even if our initial alpha type was not |
| 90 // opaque. |
88 return false; | 91 return false; |
89 } | 92 } |
90 | 93 |
91 PlatformInstrumentation::willDecodeLazyPixelRef(uniqueID()); | 94 PlatformInstrumentation::willDecodeLazyPixelRef(uniqueID()); |
92 bool decoded = m_frameGenerator->decodeAndScale( | 95 bool decoded = m_frameGenerator->decodeAndScale( |
93 m_data.get(), m_allDataReceived, m_frameIndex, getInfo(), pixels, | 96 m_data.get(), m_allDataReceived, m_frameIndex, getInfo(), pixels, |
94 rowBytes); | 97 rowBytes); |
95 PlatformInstrumentation::didDecodeLazyPixelRef(); | 98 PlatformInstrumentation::didDecodeLazyPixelRef(); |
96 | 99 |
97 return decoded; | 100 return decoded; |
98 } | 101 } |
99 | 102 |
100 bool DecodingImageGenerator::onQueryYUV8(SkYUVSizeInfo* sizeInfo, | 103 bool DecodingImageGenerator::onQueryYUV8(SkYUVSizeInfo* sizeInfo, |
101 SkYUVColorSpace* colorSpace) const { | 104 SkYUVColorSpace* colorSpace) const { |
102 // YUV decoding does not currently support progressive decoding. See comment i
n ImageFrameGenerator.h. | 105 // YUV decoding does not currently support progressive decoding. See comment |
| 106 // in ImageFrameGenerator.h. |
103 if (!m_canYUVDecode || !m_allDataReceived) | 107 if (!m_canYUVDecode || !m_allDataReceived) |
104 return false; | 108 return false; |
105 | 109 |
106 TRACE_EVENT1("blink", "DecodingImageGenerator::queryYUV8", "sizes", | 110 TRACE_EVENT1("blink", "DecodingImageGenerator::queryYUV8", "sizes", |
107 static_cast<int>(m_frameIndex)); | 111 static_cast<int>(m_frameIndex)); |
108 | 112 |
109 if (colorSpace) | 113 if (colorSpace) |
110 *colorSpace = kJPEG_SkYUVColorSpace; | 114 *colorSpace = kJPEG_SkYUVColorSpace; |
111 | 115 |
112 return m_frameGenerator->getYUVComponentSizes(m_data.get(), sizeInfo); | 116 return m_frameGenerator->getYUVComponentSizes(m_data.get(), sizeInfo); |
113 } | 117 } |
114 | 118 |
115 bool DecodingImageGenerator::onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, | 119 bool DecodingImageGenerator::onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, |
116 void* planes[3]) { | 120 void* planes[3]) { |
117 // YUV decoding does not currently support progressive decoding. See comment i
n ImageFrameGenerator.h. | 121 // YUV decoding does not currently support progressive decoding. See comment |
| 122 // in ImageFrameGenerator.h. |
118 ASSERT(m_canYUVDecode && m_allDataReceived); | 123 ASSERT(m_canYUVDecode && m_allDataReceived); |
119 | 124 |
120 TRACE_EVENT1("blink", "DecodingImageGenerator::getYUV8Planes", "frame index", | 125 TRACE_EVENT1("blink", "DecodingImageGenerator::getYUV8Planes", "frame index", |
121 static_cast<int>(m_frameIndex)); | 126 static_cast<int>(m_frameIndex)); |
122 | 127 |
123 PlatformInstrumentation::willDecodeLazyPixelRef(uniqueID()); | 128 PlatformInstrumentation::willDecodeLazyPixelRef(uniqueID()); |
124 bool decoded = | 129 bool decoded = |
125 m_frameGenerator->decodeToYUV(m_data.get(), m_frameIndex, sizeInfo.fSizes, | 130 m_frameGenerator->decodeToYUV(m_data.get(), m_frameIndex, sizeInfo.fSizes, |
126 planes, sizeInfo.fWidthBytes); | 131 planes, sizeInfo.fWidthBytes); |
127 PlatformInstrumentation::didDecodeLazyPixelRef(); | 132 PlatformInstrumentation::didDecodeLazyPixelRef(); |
128 | 133 |
129 return decoded; | 134 return decoded; |
130 } | 135 } |
131 | 136 |
132 SkImageGenerator* DecodingImageGenerator::create(SkData* data) { | 137 SkImageGenerator* DecodingImageGenerator::create(SkData* data) { |
133 RefPtr<SegmentReader> segmentReader = | 138 RefPtr<SegmentReader> segmentReader = |
134 SegmentReader::createFromSkData(sk_ref_sp(data)); | 139 SegmentReader::createFromSkData(sk_ref_sp(data)); |
135 // We just need the size of the image, so we have to temporarily create an Ima
geDecoder. Since | 140 // We just need the size of the image, so we have to temporarily create an |
136 // we only need the size, it doesn't really matter about premul or not, or gam
ma settings. | 141 // ImageDecoder. Since we only need the size, the premul and gamma settings |
| 142 // don't really matter. |
137 std::unique_ptr<ImageDecoder> decoder = ImageDecoder::create( | 143 std::unique_ptr<ImageDecoder> decoder = ImageDecoder::create( |
138 segmentReader, true, ImageDecoder::AlphaPremultiplied, | 144 segmentReader, true, ImageDecoder::AlphaPremultiplied, |
139 ImageDecoder::GammaAndColorProfileApplied); | 145 ImageDecoder::GammaAndColorProfileApplied); |
140 if (!decoder || !decoder->isSizeAvailable()) | 146 if (!decoder || !decoder->isSizeAvailable()) |
141 return nullptr; | 147 return nullptr; |
142 | 148 |
143 const IntSize size = decoder->size(); | 149 const IntSize size = decoder->size(); |
144 const SkImageInfo info = | 150 const SkImageInfo info = |
145 SkImageInfo::MakeN32Premul(size.width(), size.height()); | 151 SkImageInfo::MakeN32Premul(size.width(), size.height()); |
146 | 152 |
147 RefPtr<ImageFrameGenerator> frame = ImageFrameGenerator::create( | 153 RefPtr<ImageFrameGenerator> frame = ImageFrameGenerator::create( |
148 SkISize::Make(size.width(), size.height()), false); | 154 SkISize::Make(size.width(), size.height()), false); |
149 if (!frame) | 155 if (!frame) |
150 return nullptr; | 156 return nullptr; |
151 | 157 |
152 return new DecodingImageGenerator(frame, info, segmentReader.release(), true, | 158 return new DecodingImageGenerator(frame, info, segmentReader.release(), true, |
153 0); | 159 0); |
154 } | 160 } |
155 | 161 |
156 } // namespace blink | 162 } // namespace blink |
OLD | NEW |