| 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 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 dst->lockPixels(); | 62 dst->lockPixels(); |
| 63 return true; | 63 return true; |
| 64 } | 64 } |
| 65 | 65 |
| 66 private: | 66 private: |
| 67 SkImageInfo m_info; | 67 SkImageInfo m_info; |
| 68 void* m_pixels; | 68 void* m_pixels; |
| 69 size_t m_rowBytes; | 69 size_t m_rowBytes; |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 static void updateYUVComponentSizes(const ImageDecoder* decoder, SkISize compone
ntSizes[3], ImageDecoder::SizeType sizeType) |
| 73 { |
| 74 IntSize size = decoder->decodedYUVSize(0, sizeType); |
| 75 componentSizes[0].set(size.width(), size.height()); |
| 76 size = decoder->decodedYUVSize(1, sizeType); |
| 77 componentSizes[1].set(size.width(), size.height()); |
| 78 size = decoder->decodedYUVSize(2, sizeType); |
| 79 componentSizes[2].set(size.width(), size.height()); |
| 80 } |
| 81 |
| 72 ImageFrameGenerator::ImageFrameGenerator(const SkISize& fullSize, PassRefPtr<Sha
redBuffer> data, bool allDataReceived, bool isMultiFrame) | 82 ImageFrameGenerator::ImageFrameGenerator(const SkISize& fullSize, PassRefPtr<Sha
redBuffer> data, bool allDataReceived, bool isMultiFrame) |
| 73 : m_fullSize(fullSize) | 83 : m_fullSize(fullSize) |
| 74 , m_isMultiFrame(isMultiFrame) | 84 , m_isMultiFrame(isMultiFrame) |
| 75 , m_decodeFailedAndEmpty(false) | 85 , m_decodeFailedAndEmpty(false) |
| 76 , m_decodeCount(0) | 86 , m_decodeCount(0) |
| 77 { | 87 { |
| 78 setData(data.get(), allDataReceived); | 88 setData(data.get(), allDataReceived); |
| 79 } | 89 } |
| 80 | 90 |
| 81 ImageFrameGenerator::~ImageFrameGenerator() | 91 ImageFrameGenerator::~ImageFrameGenerator() |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 ASSERT(bitmap.height() == scaledSize.height()); | 136 ASSERT(bitmap.height() == scaledSize.height()); |
| 127 | 137 |
| 128 bool result = true; | 138 bool result = true; |
| 129 // Check to see if decoder has written directly to the memory provided | 139 // Check to see if decoder has written directly to the memory provided |
| 130 // by Skia. If not make a copy. | 140 // by Skia. If not make a copy. |
| 131 if (bitmap.getPixels() != pixels) | 141 if (bitmap.getPixels() != pixels) |
| 132 result = bitmap.copyPixelsTo(pixels, rowBytes * info.fHeight, rowBytes); | 142 result = bitmap.copyPixelsTo(pixels, rowBytes * info.fHeight, rowBytes); |
| 133 return result; | 143 return result; |
| 134 } | 144 } |
| 135 | 145 |
| 136 bool ImageFrameGenerator::decodeToYUV(void* planes[3], size_t rowBytes[3]) | 146 bool ImageFrameGenerator::decodeToYUV(SkISize componentSizes[3], void* planes[3]
, size_t rowBytes[3]) |
| 137 { | 147 { |
| 138 // This method is called to populate a discardable memory owned by Skia. | 148 // This method is called to populate a discardable memory owned by Skia. |
| 139 | 149 |
| 140 // Prevents concurrent decode or scale operations on the same image data. | 150 // Prevents concurrent decode or scale operations on the same image data. |
| 141 MutexLocker lock(m_decodeMutex); | 151 MutexLocker lock(m_decodeMutex); |
| 142 | 152 |
| 143 if (m_decodeFailedAndEmpty) | 153 if (m_decodeFailedAndEmpty) |
| 144 return false; | 154 return false; |
| 145 | 155 |
| 146 TRACE_EVENT2("blink", "ImageFrameGenerator::decodeToYUV", "generator", this,
"decodeCount", static_cast<int>(m_decodeCount)); | 156 TRACE_EVENT2("blink", "ImageFrameGenerator::decodeToYUV", "generator", this,
"decodeCount", static_cast<int>(m_decodeCount)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 158 ASSERT(allDataReceived); | 168 ASSERT(allDataReceived); |
| 159 | 169 |
| 160 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*data, ImageSource::Alph
aPremultiplied, ImageSource::GammaAndColorProfileApplied); | 170 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*data, ImageSource::Alph
aPremultiplied, ImageSource::GammaAndColorProfileApplied); |
| 161 if (!decoder) | 171 if (!decoder) |
| 162 return false; | 172 return false; |
| 163 | 173 |
| 164 decoder->setData(data, allDataReceived); | 174 decoder->setData(data, allDataReceived); |
| 165 | 175 |
| 166 OwnPtr<ImagePlanes> imagePlanes = adoptPtr(new ImagePlanes(planes, rowBytes)
); | 176 OwnPtr<ImagePlanes> imagePlanes = adoptPtr(new ImagePlanes(planes, rowBytes)
); |
| 167 decoder->setImagePlanes(imagePlanes.release()); | 177 decoder->setImagePlanes(imagePlanes.release()); |
| 178 bool sizeIsAvailable = decoder->isSizeAvailable(); |
| 179 ASSERT(sizeIsAvailable); |
| 180 if (sizeIsAvailable) |
| 181 updateYUVComponentSizes(decoder.get(), componentSizes, ImageDecoder::Act
ualSize); |
| 168 bool yuvDecoded = decoder->decodeToYUV(); | 182 bool yuvDecoded = decoder->decodeToYUV(); |
| 169 if (yuvDecoded) | 183 if (yuvDecoded) |
| 170 setHasAlpha(0, false); // YUV is always opaque | 184 setHasAlpha(0, false); // YUV is always opaque |
| 171 return yuvDecoded; | 185 return yuvDecoded; |
| 172 } | 186 } |
| 173 | 187 |
| 174 SkBitmap ImageFrameGenerator::tryToResumeDecode(const SkISize& scaledSize, size_
t index) | 188 SkBitmap ImageFrameGenerator::tryToResumeDecode(const SkISize& scaledSize, size_
t index) |
| 175 { | 189 { |
| 176 TRACE_EVENT1("blink", "ImageFrameGenerator::tryToResumeDecodeAndScale", "ind
ex", static_cast<int>(index)); | 190 TRACE_EVENT1("blink", "ImageFrameGenerator::tryToResumeDecodeAndScale", "ind
ex", static_cast<int>(index)); |
| 177 | 191 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 // Setting a dummy ImagePlanes object signals to the decoder that we want to
do YUV decoding. | 326 // Setting a dummy ImagePlanes object signals to the decoder that we want to
do YUV decoding. |
| 313 decoder->setData(data, allDataReceived); | 327 decoder->setData(data, allDataReceived); |
| 314 OwnPtr<ImagePlanes> dummyImagePlanes = adoptPtr(new ImagePlanes); | 328 OwnPtr<ImagePlanes> dummyImagePlanes = adoptPtr(new ImagePlanes); |
| 315 decoder->setImagePlanes(dummyImagePlanes.release()); | 329 decoder->setImagePlanes(dummyImagePlanes.release()); |
| 316 | 330 |
| 317 // canDecodeToYUV() has to be called AFTER isSizeAvailable(), | 331 // canDecodeToYUV() has to be called AFTER isSizeAvailable(), |
| 318 // otherwise the output color space may not be set in the decoder. | 332 // otherwise the output color space may not be set in the decoder. |
| 319 if (!decoder->isSizeAvailable() || !decoder->canDecodeToYUV()) | 333 if (!decoder->isSizeAvailable() || !decoder->canDecodeToYUV()) |
| 320 return false; | 334 return false; |
| 321 | 335 |
| 322 IntSize size = decoder->decodedYUVSize(0); | 336 updateYUVComponentSizes(decoder.get(), componentSizes, ImageDecoder::ActualS
ize); |
| 323 componentSizes[0].set(size.width(), size.height()); | |
| 324 size = decoder->decodedYUVSize(1); | |
| 325 componentSizes[1].set(size.width(), size.height()); | |
| 326 size = decoder->decodedYUVSize(2); | |
| 327 componentSizes[2].set(size.width(), size.height()); | |
| 328 return true; | 337 return true; |
| 329 } | 338 } |
| 330 | 339 |
| 331 } // namespace blink | 340 } // namespace blink |
| OLD | NEW |