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 * 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 dst->lockPixels(); | 77 dst->lockPixels(); |
| 78 return true; | 78 return true; |
| 79 } | 79 } |
| 80 | 80 |
| 81 private: | 81 private: |
| 82 SkImageInfo m_info; | 82 SkImageInfo m_info; |
| 83 void* m_pixels; | 83 void* m_pixels; |
| 84 size_t m_rowBytes; | 84 size_t m_rowBytes; |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 static bool updateYUVComponentSizes(ImageDecoder* decoder, SkISize componentSize s[3], ImageDecoder::SizeType sizeType) | 87 static bool updateYUVComponentSizes(ImageDecoder* decoder, SkISize componentSize s[3], size_t componentWidthBytes[3]) |
| 88 { | 88 { |
| 89 if (!decoder->canDecodeToYUV()) | 89 if (!decoder->canDecodeToYUV()) |
| 90 return false; | 90 return false; |
| 91 | 91 |
| 92 IntSize size = decoder->decodedYUVSize(0, sizeType); | 92 IntSize size = decoder->decodedYUVSize(0); |
| 93 componentSizes[0].set(size.width(), size.height()); | 93 componentSizes[0].set(size.width(), size.height()); |
| 94 size = decoder->decodedYUVSize(1, sizeType); | 94 componentWidthBytes[0] = decoder->decodedYUVWidthBytes(0); |
| 95 size = decoder->decodedYUVSize(1); | |
| 95 componentSizes[1].set(size.width(), size.height()); | 96 componentSizes[1].set(size.width(), size.height()); |
| 96 size = decoder->decodedYUVSize(2, sizeType); | 97 componentWidthBytes[1] = decoder->decodedYUVWidthBytes(1); |
| 98 size = decoder->decodedYUVSize(2); | |
| 97 componentSizes[2].set(size.width(), size.height()); | 99 componentSizes[2].set(size.width(), size.height()); |
| 100 componentWidthBytes[2] = decoder->decodedYUVWidthBytes(2); | |
| 98 return true; | 101 return true; |
| 99 } | 102 } |
| 100 | 103 |
| 101 ImageFrameGenerator::ImageFrameGenerator(const SkISize& fullSize, PassRefPtr<Sha redBuffer> data, bool allDataReceived, bool isMultiFrame) | 104 ImageFrameGenerator::ImageFrameGenerator(const SkISize& fullSize, PassRefPtr<Sha redBuffer> data, bool allDataReceived, bool isMultiFrame) |
| 102 : m_fullSize(fullSize) | 105 : m_fullSize(fullSize) |
| 103 , m_data(adoptRef(new ThreadSafeDataTransport())) | 106 , m_data(adoptRef(new ThreadSafeDataTransport())) |
| 104 , m_isMultiFrame(isMultiFrame) | 107 , m_isMultiFrame(isMultiFrame) |
| 105 , m_decodeFailed(false) | 108 , m_decodeFailed(false) |
| 106 , m_frameCount(0) | 109 , m_frameCount(0) |
| 107 , m_encodedData(nullptr) | 110 , m_encodedData(nullptr) |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 199 // Check to see if the decoder has written directly to the pixel memory | 202 // Check to see if the decoder has written directly to the pixel memory |
| 200 // provided. If not, make a copy. | 203 // provided. If not, make a copy. |
| 201 ASSERT(bitmap.width() == scaledSize.width()); | 204 ASSERT(bitmap.width() == scaledSize.width()); |
| 202 ASSERT(bitmap.height() == scaledSize.height()); | 205 ASSERT(bitmap.height() == scaledSize.height()); |
| 203 SkAutoLockPixels bitmapLock(bitmap); | 206 SkAutoLockPixels bitmapLock(bitmap); |
| 204 if (bitmap.getPixels() != pixels) | 207 if (bitmap.getPixels() != pixels) |
| 205 return bitmap.copyPixelsTo(pixels, rowBytes * info.height(), rowBytes); | 208 return bitmap.copyPixelsTo(pixels, rowBytes * info.height(), rowBytes); |
| 206 return true; | 209 return true; |
| 207 } | 210 } |
| 208 | 211 |
| 209 bool ImageFrameGenerator::decodeToYUV(size_t index, SkISize componentSizes[3], v oid* planes[3], size_t rowBytes[3]) | 212 bool ImageFrameGenerator::decodeToYUV(size_t index, const SkISize componentSizes [3], void* planes[3], const size_t rowBytes[3]) |
| 210 { | 213 { |
| 211 // Prevent concurrent decode or scale operations on the same image data. | 214 // Prevent concurrent decode or scale operations on the same image data. |
| 212 MutexLocker lock(m_decodeMutex); | 215 MutexLocker lock(m_decodeMutex); |
| 213 | 216 |
| 214 if (m_decodeFailed) | 217 if (m_decodeFailed) |
| 215 return false; | 218 return false; |
| 216 | 219 |
| 217 TRACE_EVENT1("blink", "ImageFrameGenerator::decodeToYUV", "frame index", sta tic_cast<int>(index)); | 220 TRACE_EVENT1("blink", "ImageFrameGenerator::decodeToYUV", "frame index", sta tic_cast<int>(index)); |
| 218 | 221 |
| 219 if (!planes || !planes[0] || !planes[1] || !planes[2] | 222 if (!planes || !planes[0] || !planes[1] || !planes[2] |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 230 | 233 |
| 231 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*data, ImageDecoder::Alp haPremultiplied, ImageDecoder::GammaAndColorProfileApplied); | 234 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*data, ImageDecoder::Alp haPremultiplied, ImageDecoder::GammaAndColorProfileApplied); |
| 232 if (!decoder) | 235 if (!decoder) |
| 233 return false; | 236 return false; |
| 234 | 237 |
| 235 decoder->setData(data, allDataReceived); | 238 decoder->setData(data, allDataReceived); |
| 236 | 239 |
| 237 OwnPtr<ImagePlanes> imagePlanes = adoptPtr(new ImagePlanes(planes, rowBytes) ); | 240 OwnPtr<ImagePlanes> imagePlanes = adoptPtr(new ImagePlanes(planes, rowBytes) ); |
| 238 decoder->setImagePlanes(imagePlanes.release()); | 241 decoder->setImagePlanes(imagePlanes.release()); |
| 239 | 242 |
| 240 bool sizeUpdated = updateYUVComponentSizes(decoder.get(), componentSizes, Im ageDecoder::ActualSize); | |
| 241 RELEASE_ASSERT(sizeUpdated); | |
|
Noel Gordon
2016/03/03 01:25:28
We lost an ASSERT here. Something like this
msarett
2016/03/04 19:49:08
Added the assert for canDecodeToYUV(). That gives
| |
| 242 | |
| 243 if (decoder->decodeToYUV()) { | 243 if (decoder->decodeToYUV()) { |
| 244 setHasAlpha(0, false); // YUV is always opaque | 244 setHasAlpha(0, false); // YUV is always opaque |
| 245 return true; | 245 return true; |
| 246 } | 246 } |
| 247 | 247 |
| 248 ASSERT(decoder->failed()); | 248 ASSERT(decoder->failed()); |
| 249 m_decodeFailed = true; | 249 m_decodeFailed = true; |
| 250 return false; | 250 return false; |
| 251 } | 251 } |
| 252 | 252 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 } | 382 } |
| 383 | 383 |
| 384 bool ImageFrameGenerator::hasAlpha(size_t index) | 384 bool ImageFrameGenerator::hasAlpha(size_t index) |
| 385 { | 385 { |
| 386 MutexLocker lock(m_alphaMutex); | 386 MutexLocker lock(m_alphaMutex); |
| 387 if (index < m_hasAlpha.size()) | 387 if (index < m_hasAlpha.size()) |
| 388 return m_hasAlpha[index]; | 388 return m_hasAlpha[index]; |
| 389 return true; | 389 return true; |
| 390 } | 390 } |
| 391 | 391 |
| 392 bool ImageFrameGenerator::getYUVComponentSizes(SkISize componentSizes[3]) | 392 bool ImageFrameGenerator::getYUVComponentSizes(SkYUVSizeInfo* sizeInfo) |
| 393 { | 393 { |
| 394 TRACE_EVENT2("blink", "ImageFrameGenerator::getYUVComponentSizes", "width", m_fullSize.width(), "height", m_fullSize.height()); | 394 TRACE_EVENT2("blink", "ImageFrameGenerator::getYUVComponentSizes", "width", m_fullSize.width(), "height", m_fullSize.height()); |
| 395 | 395 |
| 396 SharedBuffer* data = 0; | 396 SharedBuffer* data = 0; |
| 397 bool allDataReceived = false; | 397 bool allDataReceived = false; |
| 398 m_data->data(&data, &allDataReceived); | 398 m_data->data(&data, &allDataReceived); |
| 399 | 399 |
| 400 // FIXME: YUV decoding does not currently support progressive decoding. | 400 // FIXME: YUV decoding does not currently support progressive decoding. |
| 401 if (!allDataReceived) | 401 if (!allDataReceived) |
| 402 return false; | 402 return false; |
| 403 | 403 |
| 404 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*data, ImageDecoder::Alp haPremultiplied, ImageDecoder::GammaAndColorProfileApplied); | 404 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*data, ImageDecoder::Alp haPremultiplied, ImageDecoder::GammaAndColorProfileApplied); |
| 405 if (!decoder) | 405 if (!decoder) |
| 406 return false; | 406 return false; |
| 407 | 407 |
| 408 // Setting a dummy ImagePlanes object signals to the decoder that we want to do YUV decoding. | 408 // Setting a dummy ImagePlanes object signals to the decoder that we want to do YUV decoding. |
| 409 decoder->setData(data, allDataReceived); | 409 decoder->setData(data, allDataReceived); |
| 410 OwnPtr<ImagePlanes> dummyImagePlanes = adoptPtr(new ImagePlanes); | 410 OwnPtr<ImagePlanes> dummyImagePlanes = adoptPtr(new ImagePlanes); |
| 411 decoder->setImagePlanes(dummyImagePlanes.release()); | 411 decoder->setImagePlanes(dummyImagePlanes.release()); |
| 412 | 412 |
| 413 ASSERT(componentSizes); | 413 return updateYUVComponentSizes(decoder.get(), sizeInfo->fSizes, sizeInfo->fW idthBytes); |
| 414 return updateYUVComponentSizes(decoder.get(), componentSizes, ImageDecoder:: SizeForMemoryAllocation); | |
| 415 } | 414 } |
| 416 | 415 |
| 417 } // namespace blink | 416 } // namespace blink |
| OLD | NEW |