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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 cachedImage = tryToScale(0, scaledSize, index); | 98 cachedImage = tryToScale(0, scaledSize, index); |
99 if (cachedImage) | 99 if (cachedImage) |
100 return cachedImage; | 100 return cachedImage; |
101 | 101 |
102 cachedImage = tryToResumeDecodeAndScale(scaledSize, index); | 102 cachedImage = tryToResumeDecodeAndScale(scaledSize, index); |
103 if (cachedImage) | 103 if (cachedImage) |
104 return cachedImage; | 104 return cachedImage; |
105 return 0; | 105 return 0; |
106 } | 106 } |
107 | 107 |
| 108 bool ImageFrameGenerator::decodeAndScale(const SkImageInfo& info, size_t index,
void* pixels, size_t rowBytes) |
| 109 { |
| 110 // This method is called to populate a discardable memory owned by Skia. |
| 111 // Ideally we want the decoder to write directly to |pixels| but this |
| 112 // simple implementation copies from a decoded bitmap. |
| 113 |
| 114 // This implementation does not support scaling so check the requested size. |
| 115 ASSERT(m_fullSize.width() == info.fWidth); |
| 116 ASSERT(m_fullSize.height() == info.fHeight); |
| 117 |
| 118 // Don't use discardable memory for decoding if Skia is providing output |
| 119 // memory. By clearing the memory allocator decoding will use heap memory. |
| 120 // |
| 121 // TODO: |
| 122 // This is not pretty because this class is used in two different code |
| 123 // paths: discardable memory decoding on Android and discardable memory |
| 124 // in Skia. Once the transition to caching in Skia is complete we can get |
| 125 // rid of the logic that handles discardable memory. |
| 126 m_allocator.clear(); |
| 127 |
| 128 const ScaledImageFragment* cachedImage = decodeAndScale(SkISize::Make(info.f
Width, info.fHeight), index); |
| 129 if (!cachedImage) |
| 130 return false; |
| 131 |
| 132 ASSERT(cachedImage->bitmap().width() == info.fWidth); |
| 133 ASSERT(cachedImage->bitmap().height() == info.fHeight); |
| 134 |
| 135 bool copied = cachedImage->bitmap().copyPixelsTo(pixels, rowBytes * info.fHe
ight, rowBytes); |
| 136 ImageDecodingStore::instance()->unlockCache(this, cachedImage); |
| 137 return copied; |
| 138 } |
| 139 |
108 const ScaledImageFragment* ImageFrameGenerator::tryToLockCompleteCache(const SkI
Size& scaledSize, size_t index) | 140 const ScaledImageFragment* ImageFrameGenerator::tryToLockCompleteCache(const SkI
Size& scaledSize, size_t index) |
109 { | 141 { |
110 const ScaledImageFragment* cachedImage = 0; | 142 const ScaledImageFragment* cachedImage = 0; |
111 if (ImageDecodingStore::instance()->lockCache(this, scaledSize, index, &cach
edImage)) | 143 if (ImageDecodingStore::instance()->lockCache(this, scaledSize, index, &cach
edImage)) |
112 return cachedImage; | 144 return cachedImage; |
113 return 0; | 145 return 0; |
114 } | 146 } |
115 | 147 |
116 const ScaledImageFragment* ImageFrameGenerator::tryToScale(const ScaledImageFrag
ment* fullSizeImage, const SkISize& scaledSize, size_t index) | 148 const ScaledImageFragment* ImageFrameGenerator::tryToScale(const ScaledImageFrag
ment* fullSizeImage, const SkISize& scaledSize, size_t index) |
117 { | 149 { |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 | 290 |
259 bool ImageFrameGenerator::hasAlpha(size_t index) | 291 bool ImageFrameGenerator::hasAlpha(size_t index) |
260 { | 292 { |
261 MutexLocker lock(m_alphaMutex); | 293 MutexLocker lock(m_alphaMutex); |
262 if (index < m_hasAlpha.size()) | 294 if (index < m_hasAlpha.size()) |
263 return m_hasAlpha[index]; | 295 return m_hasAlpha[index]; |
264 return true; | 296 return true; |
265 } | 297 } |
266 | 298 |
267 } // namespace | 299 } // namespace |
OLD | NEW |