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 | |
140 const ScaledImageFragment* ImageFrameGenerator::tryToLockCompleteCache(const SkI
Size& scaledSize, size_t index) | 108 const ScaledImageFragment* ImageFrameGenerator::tryToLockCompleteCache(const SkI
Size& scaledSize, size_t index) |
141 { | 109 { |
142 const ScaledImageFragment* cachedImage = 0; | 110 const ScaledImageFragment* cachedImage = 0; |
143 if (ImageDecodingStore::instance()->lockCache(this, scaledSize, index, &cach
edImage)) | 111 if (ImageDecodingStore::instance()->lockCache(this, scaledSize, index, &cach
edImage)) |
144 return cachedImage; | 112 return cachedImage; |
145 return 0; | 113 return 0; |
146 } | 114 } |
147 | 115 |
148 const ScaledImageFragment* ImageFrameGenerator::tryToScale(const ScaledImageFrag
ment* fullSizeImage, const SkISize& scaledSize, size_t index) | 116 const ScaledImageFragment* ImageFrameGenerator::tryToScale(const ScaledImageFrag
ment* fullSizeImage, const SkISize& scaledSize, size_t index) |
149 { | 117 { |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 | 258 |
291 bool ImageFrameGenerator::hasAlpha(size_t index) | 259 bool ImageFrameGenerator::hasAlpha(size_t index) |
292 { | 260 { |
293 MutexLocker lock(m_alphaMutex); | 261 MutexLocker lock(m_alphaMutex); |
294 if (index < m_hasAlpha.size()) | 262 if (index < m_hasAlpha.size()) |
295 return m_hasAlpha[index]; | 263 return m_hasAlpha[index]; |
296 return true; | 264 return true; |
297 } | 265 } |
298 | 266 |
299 } // namespace | 267 } // namespace |
OLD | NEW |