| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 , m_isMultiFrame(isMultiFrame) | 87 , m_isMultiFrame(isMultiFrame) |
| 88 , m_decodeFailedAndEmpty(false) | 88 , m_decodeFailedAndEmpty(false) |
| 89 , m_decodeCount(0) | 89 , m_decodeCount(0) |
| 90 , m_frameCount(0) | 90 , m_frameCount(0) |
| 91 { | 91 { |
| 92 setData(data.get(), allDataReceived); | 92 setData(data.get(), allDataReceived); |
| 93 } | 93 } |
| 94 | 94 |
| 95 ImageFrameGenerator::~ImageFrameGenerator() | 95 ImageFrameGenerator::~ImageFrameGenerator() |
| 96 { | 96 { |
| 97 ImageDecodingStore::instance()->removeCacheIndexedByGenerator(this); | 97 ImageDecodingStore::instance().removeCacheIndexedByGenerator(this); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void ImageFrameGenerator::setData(PassRefPtr<SharedBuffer> data, bool allDataRec
eived) | 100 void ImageFrameGenerator::setData(PassRefPtr<SharedBuffer> data, bool allDataRec
eived) |
| 101 { | 101 { |
| 102 m_data.setData(data.get(), allDataReceived); | 102 m_data.setData(data.get(), allDataReceived); |
| 103 } | 103 } |
| 104 | 104 |
| 105 void ImageFrameGenerator::copyData(RefPtr<SharedBuffer>* data, bool* allDataRece
ived) | 105 void ImageFrameGenerator::copyData(RefPtr<SharedBuffer>* data, bool* allDataRece
ived) |
| 106 { | 106 { |
| 107 SharedBuffer* buffer = 0; | 107 SharedBuffer* buffer = 0; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 if (yuvDecoded) | 187 if (yuvDecoded) |
| 188 setHasAlpha(0, false); // YUV is always opaque | 188 setHasAlpha(0, false); // YUV is always opaque |
| 189 return yuvDecoded; | 189 return yuvDecoded; |
| 190 } | 190 } |
| 191 | 191 |
| 192 SkBitmap ImageFrameGenerator::tryToResumeDecode(const SkISize& scaledSize, size_
t index) | 192 SkBitmap ImageFrameGenerator::tryToResumeDecode(const SkISize& scaledSize, size_
t index) |
| 193 { | 193 { |
| 194 TRACE_EVENT1("blink", "ImageFrameGenerator::tryToResumeDecodeAndScale", "ind
ex", static_cast<int>(index)); | 194 TRACE_EVENT1("blink", "ImageFrameGenerator::tryToResumeDecodeAndScale", "ind
ex", static_cast<int>(index)); |
| 195 | 195 |
| 196 ImageDecoder* decoder = 0; | 196 ImageDecoder* decoder = 0; |
| 197 const bool resumeDecoding = ImageDecodingStore::instance()->lockDecoder(this
, m_fullSize, &decoder); | 197 const bool resumeDecoding = ImageDecodingStore::instance().lockDecoder(this,
m_fullSize, &decoder); |
| 198 ASSERT(!resumeDecoding || decoder); | 198 ASSERT(!resumeDecoding || decoder); |
| 199 | 199 |
| 200 SkBitmap fullSizeImage; | 200 SkBitmap fullSizeImage; |
| 201 bool complete = decode(index, &decoder, &fullSizeImage); | 201 bool complete = decode(index, &decoder, &fullSizeImage); |
| 202 | 202 |
| 203 if (!decoder) | 203 if (!decoder) |
| 204 return SkBitmap(); | 204 return SkBitmap(); |
| 205 if (index >= m_frameComplete.size()) | 205 if (index >= m_frameComplete.size()) |
| 206 m_frameComplete.resize(index + 1); | 206 m_frameComplete.resize(index + 1); |
| 207 m_frameComplete[index] = complete; | 207 m_frameComplete[index] = complete; |
| 208 | 208 |
| 209 // If we are not resuming decoding that means the decoder is freshly | 209 // If we are not resuming decoding that means the decoder is freshly |
| 210 // created and we have ownership. If we are resuming decoding then | 210 // created and we have ownership. If we are resuming decoding then |
| 211 // the decoder is owned by ImageDecodingStore. | 211 // the decoder is owned by ImageDecodingStore. |
| 212 OwnPtr<ImageDecoder> decoderContainer; | 212 OwnPtr<ImageDecoder> decoderContainer; |
| 213 if (!resumeDecoding) | 213 if (!resumeDecoding) |
| 214 decoderContainer = adoptPtr(decoder); | 214 decoderContainer = adoptPtr(decoder); |
| 215 | 215 |
| 216 if (fullSizeImage.isNull()) { | 216 if (fullSizeImage.isNull()) { |
| 217 // If decode has failed and resulted an empty image we can save work | 217 // If decode has failed and resulted an empty image we can save work |
| 218 // in the future by returning early. | 218 // in the future by returning early. |
| 219 m_decodeFailedAndEmpty = !m_isMultiFrame && decoder->failed(); | 219 m_decodeFailedAndEmpty = !m_isMultiFrame && decoder->failed(); |
| 220 | 220 |
| 221 if (resumeDecoding) | 221 if (resumeDecoding) |
| 222 ImageDecodingStore::instance()->unlockDecoder(this, decoder); | 222 ImageDecodingStore::instance().unlockDecoder(this, decoder); |
| 223 return SkBitmap(); | 223 return SkBitmap(); |
| 224 } | 224 } |
| 225 | 225 |
| 226 // If the image generated is complete then there is no need to keep | 226 // If the image generated is complete then there is no need to keep |
| 227 // the decoder. For multi-frame images, if all frames in the image are | 227 // the decoder. For multi-frame images, if all frames in the image are |
| 228 // decoded, we remove the decoder. | 228 // decoded, we remove the decoder. |
| 229 bool removeDecoder; | 229 bool removeDecoder; |
| 230 | 230 |
| 231 if (m_isMultiFrame) { | 231 if (m_isMultiFrame) { |
| 232 size_t decodedFrameCount = 0; | 232 size_t decodedFrameCount = 0; |
| 233 for (Vector<bool>::iterator it = m_frameComplete.begin(); it != m_frameC
omplete.end(); ++it) { | 233 for (Vector<bool>::iterator it = m_frameComplete.begin(); it != m_frameC
omplete.end(); ++it) { |
| 234 if (*it) | 234 if (*it) |
| 235 decodedFrameCount++; | 235 decodedFrameCount++; |
| 236 } | 236 } |
| 237 removeDecoder = m_frameCount && (decodedFrameCount == m_frameCount); | 237 removeDecoder = m_frameCount && (decodedFrameCount == m_frameCount); |
| 238 } else { | 238 } else { |
| 239 removeDecoder = complete; | 239 removeDecoder = complete; |
| 240 } | 240 } |
| 241 | 241 |
| 242 if (resumeDecoding) { | 242 if (resumeDecoding) { |
| 243 if (removeDecoder) { | 243 if (removeDecoder) { |
| 244 ImageDecodingStore::instance()->removeDecoder(this, decoder); | 244 ImageDecodingStore::instance().removeDecoder(this, decoder); |
| 245 m_frameComplete.clear(); | 245 m_frameComplete.clear(); |
| 246 } else { |
| 247 ImageDecodingStore::instance().unlockDecoder(this, decoder); |
| 246 } | 248 } |
| 247 else | |
| 248 ImageDecodingStore::instance()->unlockDecoder(this, decoder); | |
| 249 } else if (!removeDecoder) { | 249 } else if (!removeDecoder) { |
| 250 ImageDecodingStore::instance()->insertDecoder(this, decoderContainer.rel
ease()); | 250 ImageDecodingStore::instance().insertDecoder(this, decoderContainer.rele
ase()); |
| 251 } | 251 } |
| 252 return fullSizeImage; | 252 return fullSizeImage; |
| 253 } | 253 } |
| 254 | 254 |
| 255 void ImageFrameGenerator::setHasAlpha(size_t index, bool hasAlpha) | 255 void ImageFrameGenerator::setHasAlpha(size_t index, bool hasAlpha) |
| 256 { | 256 { |
| 257 MutexLocker lock(m_alphaMutex); | 257 MutexLocker lock(m_alphaMutex); |
| 258 if (index >= m_hasAlpha.size()) { | 258 if (index >= m_hasAlpha.size()) { |
| 259 const size_t oldSize = m_hasAlpha.size(); | 259 const size_t oldSize = m_hasAlpha.size(); |
| 260 m_hasAlpha.resize(index + 1); | 260 m_hasAlpha.resize(index + 1); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 | 357 |
| 358 // Setting a dummy ImagePlanes object signals to the decoder that we want to
do YUV decoding. | 358 // Setting a dummy ImagePlanes object signals to the decoder that we want to
do YUV decoding. |
| 359 decoder->setData(data, allDataReceived); | 359 decoder->setData(data, allDataReceived); |
| 360 OwnPtr<ImagePlanes> dummyImagePlanes = adoptPtr(new ImagePlanes); | 360 OwnPtr<ImagePlanes> dummyImagePlanes = adoptPtr(new ImagePlanes); |
| 361 decoder->setImagePlanes(dummyImagePlanes.release()); | 361 decoder->setImagePlanes(dummyImagePlanes.release()); |
| 362 | 362 |
| 363 return updateYUVComponentSizes(decoder.get(), componentSizes, ImageDecoder::
SizeForMemoryAllocation); | 363 return updateYUVComponentSizes(decoder.get(), componentSizes, ImageDecoder::
SizeForMemoryAllocation); |
| 364 } | 364 } |
| 365 | 365 |
| 366 } // namespace blink | 366 } // namespace blink |
| OLD | NEW |