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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 // This method is called to populate a discardable memory owned by Skia. | 126 // This method is called to populate a discardable memory owned by Skia. |
| 127 | 127 |
| 128 // Prevents concurrent decode or scale operations on the same image data. | 128 // Prevents concurrent decode or scale operations on the same image data. |
| 129 MutexLocker lock(m_decodeMutex); | 129 MutexLocker lock(m_decodeMutex); |
| 130 | 130 |
| 131 // This implementation does not support scaling so check the requested size. | 131 // This implementation does not support scaling so check the requested size. |
| 132 SkISize scaledSize = SkISize::Make(info.fWidth, info.fHeight); | 132 SkISize scaledSize = SkISize::Make(info.fWidth, info.fHeight); |
| 133 ASSERT(m_fullSize == scaledSize); | 133 ASSERT(m_fullSize == scaledSize); |
| 134 | 134 |
| 135 if (m_decodeFailedAndEmpty) | 135 if (m_decodeFailedAndEmpty) |
| 136 return 0; | 136 return false; |
| 137 | 137 |
| 138 TRACE_EVENT2("blink", "ImageFrameGenerator::decodeAndScale", "generator", th is, "decodeCount", static_cast<int>(m_decodeCount)); | 138 TRACE_EVENT2("blink", "ImageFrameGenerator::decodeAndScale", "generator", th is, "decodeCount", static_cast<int>(m_decodeCount)); |
| 139 | 139 |
| 140 // Don't use discardable memory for decoding if Skia is providing output | 140 // Don't use discardable memory for decoding if Skia is providing output |
| 141 // memory. Instead use ExternalMemoryAllocator such that we can | 141 // memory. Instead use ExternalMemoryAllocator such that we can |
| 142 // write directly to the memory given by Skia. | 142 // write directly to the memory given by Skia. |
| 143 // | 143 // |
| 144 // TODO: | 144 // TODO: |
| 145 // This is not pretty because this class is used in two different code | 145 // This is not pretty because this class is used in two different code |
| 146 // paths: discardable memory decoding on Android and discardable memory | 146 // paths: discardable memory decoding on Android and discardable memory |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 162 | 162 |
| 163 bool result = true; | 163 bool result = true; |
| 164 // Check to see if decoder has written directly to the memory provided | 164 // Check to see if decoder has written directly to the memory provided |
| 165 // by Skia. If not make a copy. | 165 // by Skia. If not make a copy. |
| 166 if (cachedImage->bitmap().getPixels() != pixels) | 166 if (cachedImage->bitmap().getPixels() != pixels) |
| 167 result = cachedImage->bitmap().copyPixelsTo(pixels, rowBytes * info.fHei ght, rowBytes); | 167 result = cachedImage->bitmap().copyPixelsTo(pixels, rowBytes * info.fHei ght, rowBytes); |
| 168 ImageDecodingStore::instance()->unlockCache(this, cachedImage); | 168 ImageDecodingStore::instance()->unlockCache(this, cachedImage); |
| 169 return result; | 169 return result; |
| 170 } | 170 } |
| 171 | 171 |
| 172 bool ImageFrameGenerator::decodeAndScale(void* planes[3], size_t rowBytes[3]) | |
| 173 { | |
| 174 // This method is called to populate a discardable memory owned by Skia. | |
| 175 | |
| 176 // Prevents concurrent decode or scale operations on the same image data. | |
| 177 MutexLocker lock(m_decodeMutex); | |
| 178 | |
| 179 if (m_decodeFailedAndEmpty) | |
| 180 return false; | |
| 181 | |
| 182 TRACE_EVENT2("blink", "ImageFrameGenerator::decodeAndScale", "generator", th is, "decodeCount", static_cast<int>(m_decodeCount)); | |
| 183 | |
| 184 m_hardwareDecoding = (0 != planes) && (0 != planes[0]) && (0 != planes[1]) & & (0 != planes[2]) && (0 != rowBytes) && (0 != rowBytes[0]) && (0 != rowBytes[1] ) && (0 != rowBytes[2]); | |
| 185 if (!m_hardwareDecoding) { | |
| 186 return false; | |
| 187 } | |
| 188 | |
| 189 DecodingBuffers* decodingBuffers = new DecodingBuffers; | |
| 190 decodingBuffers->set(planes, rowBytes); | |
| 191 m_decodingBuffers = adoptPtr(decodingBuffers); | |
| 192 | |
| 193 ImageDecoder* decoder = 0; | |
| 194 const bool isCached = ImageDecodingStore::instance()->lockDecoder(this, m_fu llSize, &decoder); | |
| 195 ASSERT(!isCached || decoder); | |
| 196 | |
| 197 decode(0, &decoder); | |
| 198 | |
| 199 if (isCached) { | |
| 200 ImageDecodingStore::instance()->unlockDecoder(this, decoder); | |
| 201 } | |
| 202 | |
| 203 return m_hardwareDecoding; | |
|
Stephen White
2014/07/23 21:45:53
Naming nit: generally we use "accelerated" (or som
sugoi1
2014/07/24 15:48:29
Done.
| |
| 204 } | |
| 205 | |
| 172 const ScaledImageFragment* ImageFrameGenerator::tryToLockCompleteCache(const SkI Size& scaledSize, size_t index) | 206 const ScaledImageFragment* ImageFrameGenerator::tryToLockCompleteCache(const SkI Size& scaledSize, size_t index) |
| 173 { | 207 { |
| 174 const ScaledImageFragment* cachedImage = 0; | 208 const ScaledImageFragment* cachedImage = 0; |
| 175 if (ImageDecodingStore::instance()->lockCache(this, scaledSize, index, &cach edImage)) | 209 if (ImageDecodingStore::instance()->lockCache(this, scaledSize, index, &cach edImage)) |
| 176 return cachedImage; | 210 return cachedImage; |
| 177 return 0; | 211 return 0; |
| 178 } | 212 } |
| 179 | 213 |
| 180 const ScaledImageFragment* ImageFrameGenerator::tryToResumeDecode(const SkISize& scaledSize, size_t index) | 214 const ScaledImageFragment* ImageFrameGenerator::tryToResumeDecode(const SkISize& scaledSize, size_t index) |
| 181 { | 215 { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 255 if (!m_isMultiFrame && newDecoder && allDataReceived) { | 289 if (!m_isMultiFrame && newDecoder && allDataReceived) { |
| 256 // If we're using an external memory allocator that means we're decoding | 290 // If we're using an external memory allocator that means we're decoding |
| 257 // directly into the output memory and we can save one memcpy. | 291 // directly into the output memory and we can save one memcpy. |
| 258 canSkipBitmapCopy = true; | 292 canSkipBitmapCopy = true; |
| 259 if (m_externalAllocator) | 293 if (m_externalAllocator) |
| 260 (*decoder)->setMemoryAllocator(m_externalAllocator.get()); | 294 (*decoder)->setMemoryAllocator(m_externalAllocator.get()); |
| 261 else | 295 else |
| 262 (*decoder)->setMemoryAllocator(m_discardableAllocator.get()); | 296 (*decoder)->setMemoryAllocator(m_discardableAllocator.get()); |
| 263 } | 297 } |
| 264 (*decoder)->setData(data, allDataReceived); | 298 (*decoder)->setData(data, allDataReceived); |
| 299 if (m_hardwareDecoding) { | |
| 300 (*decoder)->setDecodingBuffers(m_decodingBuffers); | |
| 301 m_hardwareDecoding = (*decoder)->doHardwareDecoding(); | |
| 302 return nullptr; | |
| 303 } | |
| 265 // If this call returns a newly allocated DiscardablePixelRef, then | 304 // If this call returns a newly allocated DiscardablePixelRef, then |
| 266 // ImageFrame::m_bitmap and the contained DiscardablePixelRef are locked. | 305 // ImageFrame::m_bitmap and the contained DiscardablePixelRef are locked. |
| 267 // They will be unlocked when ImageDecoder is destroyed since ImageDecoder | 306 // They will be unlocked when ImageDecoder is destroyed since ImageDecoder |
| 268 // owns the ImageFrame. Partially decoded SkBitmap is thus inserted into the | 307 // owns the ImageFrame. Partially decoded SkBitmap is thus inserted into the |
| 269 // ImageDecodingStore while locked. | 308 // ImageDecodingStore while locked. |
| 270 ImageFrame* frame = (*decoder)->frameBufferAtIndex(index); | 309 ImageFrame* frame = (*decoder)->frameBufferAtIndex(index); |
| 271 (*decoder)->setData(0, false); // Unref SharedBuffer from ImageDecoder. | 310 (*decoder)->setData(0, false); // Unref SharedBuffer from ImageDecoder. |
| 272 (*decoder)->clearCacheExceptFrame(index); | 311 (*decoder)->clearCacheExceptFrame(index); |
| 273 (*decoder)->setMemoryAllocator(0); | 312 (*decoder)->setMemoryAllocator(0); |
| 274 | 313 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 } | 356 } |
| 318 | 357 |
| 319 bool ImageFrameGenerator::hasAlpha(size_t index) | 358 bool ImageFrameGenerator::hasAlpha(size_t index) |
| 320 { | 359 { |
| 321 MutexLocker lock(m_alphaMutex); | 360 MutexLocker lock(m_alphaMutex); |
| 322 if (index < m_hasAlpha.size()) | 361 if (index < m_hasAlpha.size()) |
| 323 return m_hasAlpha[index]; | 362 return m_hasAlpha[index]; |
| 324 return true; | 363 return true; |
| 325 } | 364 } |
| 326 | 365 |
| 366 bool ImageFrameGenerator::getComponentSizes(SkISize* componentSizes) | |
| 367 { | |
| 368 if (!componentSizes) { | |
| 369 return false; | |
| 370 } | |
| 371 | |
| 372 TRACE_EVENT2("webkit", "ImageFrameGenerator::getImageFormat", "width", m_ful lSize.width(), "height", m_fullSize.height()); | |
| 373 | |
| 374 ImageDecoder* decoder = 0; | |
| 375 const bool isCached = ImageDecodingStore::instance()->lockDecoder(this, m_fu llSize, &decoder); | |
| 376 ASSERT(!isCached || decoder); | |
| 377 | |
| 378 SharedBuffer* data = 0; | |
| 379 bool allDataReceived = false; | |
| 380 m_data.data(&data, &allDataReceived); | |
| 381 | |
| 382 // Try to create an ImageDecoder | |
|
Peter Kasting
2014/07/23 22:17:36
Nit: This comment adds little to the code.
sugoi1
2014/07/24 15:48:29
Done.
| |
| 383 if (!decoder && m_imageDecoderFactory) { | |
|
Peter Kasting
2014/07/23 22:17:37
Nit: No {} (several places)
sugoi1
2014/07/24 15:48:29
Done.
| |
| 384 decoder = m_imageDecoderFactory->create().leakPtr(); | |
| 385 } | |
| 386 | |
| 387 if (!decoder) { | |
| 388 decoder = ImageDecoder::create(*data, ImageSource::AlphaPremultiplied, I mageSource::GammaAndColorProfileApplied).leakPtr(); | |
| 389 } | |
| 390 | |
| 391 if (!decoder) { | |
|
Peter Kasting
2014/07/23 22:17:36
Nit: This can be moved inside the conditional abov
sugoi1
2014/07/24 15:48:29
Done.
| |
| 392 return false; | |
| 393 } | |
| 394 | |
| 395 // If the decoder isn't cached, take ownership of it here | |
|
Peter Kasting
2014/07/23 22:17:36
Nit: Another poor-quality comment.
sugoi1
2014/07/24 15:48:29
Done.
Peter Kasting
2014/07/24 18:08:13
Actually you don't seem to have removed or improve
| |
| 396 OwnPtr<ImageDecoder> decoderContainer; | |
|
Peter Kasting
2014/07/23 22:17:36
Nit: Instead of declaring this down here, why not
sugoi1
2014/07/24 15:48:29
Done.
| |
| 397 if (!isCached) { | |
| 398 decoderContainer = adoptPtr(decoder); | |
| 399 } | |
| 400 | |
| 401 decoder->setData(data, allDataReceived); | |
| 402 decoder->setHardwareDecoding(true); | |
| 403 bool canComputeSize = decoder->hardwareDecoding() && decoder->isSizeAvailabl e(); | |
| 404 if (canComputeSize) { | |
| 405 IntSize size = decoder->decodedSize(0); | |
| 406 componentSizes[0].set(size.width(), size.height()); | |
| 407 size = decoder->decodedSize(1); | |
| 408 componentSizes[1].set(size.width(), size.height()); | |
| 409 size = decoder->decodedSize(2); | |
| 410 componentSizes[2].set(size.width(), size.height()); | |
| 411 } | |
| 412 decoder->setData(0, false); // Unref SharedBuffer from ImageDecoder. | |
| 413 if (isCached) { | |
| 414 ImageDecodingStore::instance()->unlockDecoder(this, decoder); | |
| 415 } | |
| 416 return canComputeSize; | |
| 417 } | |
| 418 | |
| 327 } // namespace | 419 } // namespace |
| OLD | NEW |