Chromium Code Reviews| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 // this. skbug.com/5485 | 63 // this. skbug.com/5485 |
| 64 if (ctx && !m_allDataReceived) | 64 if (ctx && !m_allDataReceived) |
| 65 return nullptr; | 65 return nullptr; |
| 66 | 66 |
| 67 // Other clients are serializers, which want the data even if it requires | 67 // Other clients are serializers, which want the data even if it requires |
| 68 // copying, and even if the data is incomplete. (Otherwise they would | 68 // copying, and even if the data is incomplete. (Otherwise they would |
| 69 // potentially need to decode the partial image in order to re-encode it.) | 69 // potentially need to decode the partial image in order to re-encode it.) |
| 70 return m_data->getAsSkData().release(); | 70 return m_data->getAsSkData().release(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, | 73 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& dstInfo, |
| 74 void* pixels, | 74 void* pixels, |
| 75 size_t rowBytes, | 75 size_t rowBytes, |
| 76 SkPMColor table[], | 76 SkPMColor*, |
| 77 int* tableCount) { | 77 int*) { |
| 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 | 81 // Implementation doesn't support scaling yet, so make sure we're not given a |
| 82 // different size. | 82 // different size. |
| 83 if (info.width() != getInfo().width() || info.height() != getInfo().height()) | 83 if (dstInfo.width() != getInfo().width() || |
|
scroggo_chromium
2017/04/10 17:31:24
nit: you can call dimensions() for both, cutting t
msarett1
2017/04/10 21:34:26
Done.
| |
| 84 dstInfo.height() != getInfo().height()) { | |
| 84 return false; | 85 return false; |
| 86 } | |
| 85 | 87 |
| 86 if (info.colorType() != getInfo().colorType()) { | 88 if (kN32_SkColorType != dstInfo.colorType()) { |
| 87 // blink::ImageFrame may have changed the owning SkBitmap to | |
| 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. | |
| 91 return false; | 89 return false; |
| 92 } | 90 } |
| 93 | 91 |
| 92 // Skip the check for alphaType. blink::ImageFrame may have changed the | |
| 93 // owning SkBitmap to kOpaque_SkAlphaType after fully decoding the image | |
| 94 // frame, so if we see a request for opaque, that is ok even if our initial | |
| 95 // alpha type was not opaque. | |
| 96 | |
| 97 // Pass decodeColorSpace to the decoder. That is what we can expect the | |
| 98 // output to be. | |
| 99 sk_sp<SkColorSpace> decodeColorSpace = getInfo().refColorSpace(); | |
|
scroggo_chromium
2017/04/10 17:31:24
nit: Why do you call refColorSpace (and store in a
msarett1
2017/04/10 21:34:26
You're right, done.
| |
| 100 SkImageInfo decodeInfo = dstInfo.makeColorSpace(decodeColorSpace); | |
| 101 | |
| 102 const bool needsColorXform = | |
| 103 decodeColorSpace && dstInfo.colorSpace() && | |
| 104 !SkColorSpace::Equals(decodeColorSpace.get(), dstInfo.colorSpace()); | |
| 105 ImageDecoder::AlphaOption alphaOption = ImageDecoder::AlphaPremultiplied; | |
| 106 if (needsColorXform && !decodeInfo.isOpaque()) { | |
| 107 alphaOption = ImageDecoder::AlphaNotPremultiplied; | |
| 108 decodeInfo = decodeInfo.makeAlphaType(kUnpremul_SkAlphaType); | |
| 109 } | |
| 110 | |
| 94 PlatformInstrumentation::willDecodeLazyPixelRef(uniqueID()); | 111 PlatformInstrumentation::willDecodeLazyPixelRef(uniqueID()); |
| 95 bool decoded = m_frameGenerator->decodeAndScale( | 112 bool decoded = m_frameGenerator->decodeAndScale( |
| 96 m_data.get(), m_allDataReceived, m_frameIndex, getInfo(), pixels, | 113 m_data.get(), m_allDataReceived, m_frameIndex, decodeInfo, pixels, |
| 97 rowBytes); | 114 rowBytes, alphaOption); |
| 98 PlatformInstrumentation::didDecodeLazyPixelRef(); | 115 PlatformInstrumentation::didDecodeLazyPixelRef(); |
| 99 | 116 |
| 100 return decoded; | 117 if (!decoded) { |
| 118 return false; | |
| 119 } | |
| 120 | |
| 121 if (needsColorXform) { | |
|
scroggo_chromium
2017/04/10 17:31:24
nit/suggestion: If you changed the above if to
msarett1
2017/04/10 21:34:26
Done.
| |
| 122 std::unique_ptr<SkColorSpaceXform> xform = | |
| 123 SkColorSpaceXform::New(decodeColorSpace.get(), dstInfo.colorSpace()); | |
| 124 | |
| 125 uint32_t* row = (uint32_t*)pixels; | |
|
scroggo_chromium
2017/04/10 17:31:24
C++ style cast. Same down below.
msarett1
2017/04/10 21:34:26
Done.
| |
| 126 for (int y = 0; y < dstInfo.height(); y++) { | |
| 127 SkColorSpaceXform::ColorFormat format = | |
| 128 SkColorSpaceXform::kRGBA_8888_ColorFormat; | |
| 129 if (kN32_SkColorType == kBGRA_8888_SkColorType) { | |
| 130 format = SkColorSpaceXform::kBGRA_8888_ColorFormat; | |
| 131 } | |
| 132 SkAlphaType alphaType = | |
| 133 dstInfo.isOpaque() ? kOpaque_SkAlphaType : kUnpremul_SkAlphaType; | |
| 134 bool xformed = | |
| 135 xform->apply(format, row, format, row, dstInfo.width(), alphaType); | |
| 136 DCHECK(xformed); | |
| 137 | |
| 138 // To be compatible with dst space blending, premultiply in the dst space. | |
| 139 if (kPremul_SkAlphaType == dstInfo.alphaType()) { | |
| 140 for (int x = 0; x < dstInfo.width(); x++) { | |
| 141 row[x] = | |
| 142 SkPreMultiplyARGB(SkGetPackedA32(row[x]), SkGetPackedR32(row[x]), | |
| 143 SkGetPackedG32(row[x]), SkGetPackedB32(row[x])); | |
| 144 } | |
| 145 } | |
| 146 | |
| 147 row = (uint32_t*)(((uint8_t*)row) + rowBytes); | |
| 148 } | |
| 149 } | |
| 150 | |
| 151 return true; | |
| 101 } | 152 } |
| 102 | 153 |
| 103 bool DecodingImageGenerator::onQueryYUV8(SkYUVSizeInfo* sizeInfo, | 154 bool DecodingImageGenerator::onQueryYUV8(SkYUVSizeInfo* sizeInfo, |
| 104 SkYUVColorSpace* colorSpace) const { | 155 SkYUVColorSpace* colorSpace) const { |
| 105 // YUV decoding does not currently support progressive decoding. See comment | 156 // YUV decoding does not currently support progressive decoding. See comment |
| 106 // in ImageFrameGenerator.h. | 157 // in ImageFrameGenerator.h. |
| 107 if (!m_canYUVDecode || !m_allDataReceived) | 158 if (!m_canYUVDecode || !m_allDataReceived) |
| 108 return false; | 159 return false; |
| 109 | 160 |
| 110 TRACE_EVENT1("blink", "DecodingImageGenerator::queryYUV8", "sizes", | 161 TRACE_EVENT1("blink", "DecodingImageGenerator::queryYUV8", "sizes", |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 ImageFrameGenerator::create(SkISize::Make(size.width(), size.height()), | 206 ImageFrameGenerator::create(SkISize::Make(size.width(), size.height()), |
| 156 false, decoder->colorBehavior()); | 207 false, decoder->colorBehavior()); |
| 157 if (!frame) | 208 if (!frame) |
| 158 return nullptr; | 209 return nullptr; |
| 159 | 210 |
| 160 return new DecodingImageGenerator(frame, info, segmentReader.release(), true, | 211 return new DecodingImageGenerator(frame, info, segmentReader.release(), true, |
| 161 0); | 212 0); |
| 162 } | 213 } |
| 163 | 214 |
| 164 } // namespace blink | 215 } // namespace blink |
| OLD | NEW |