OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkGr.h" | 8 #include "SkGr.h" |
9 #include "SkConfig8888.h" | 9 #include "SkConfig8888.h" |
10 #include "SkMessageBus.h" | 10 #include "SkMessageBus.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 // our compressed data will be trimmed, so pass width() for its | 134 // our compressed data will be trimmed, so pass width() for its |
135 // "rowBytes", since they are the same now. | 135 // "rowBytes", since they are the same now. |
136 | 136 |
137 if (cache) { | 137 if (cache) { |
138 GrCacheID cacheID; | 138 GrCacheID cacheID; |
139 generate_bitmap_cache_id(origBitmap, &cacheID); | 139 generate_bitmap_cache_id(origBitmap, &cacheID); |
140 | 140 |
141 GrResourceKey key; | 141 GrResourceKey key; |
142 GrTexture* result = ctx->createTexture(params, desc, cacheID, | 142 GrTexture* result = ctx->createTexture(params, desc, cacheID, |
143 storage.get(), bitmap->wi
dth(), &key); | 143 storage.get(), bitmap->wi
dth(), &key); |
144 add_genID_listener(key, origBitmap.pixelRef()); | 144 if (NULL != result) { |
| 145 add_genID_listener(key, origBitmap.pixelRef()); |
| 146 } |
145 return result; | 147 return result; |
146 } else { | 148 } else { |
147 GrTexture* result = ctx->lockAndRefScratchTexture(desc, | 149 GrTexture* result = ctx->lockAndRefScratchTexture(desc, |
148 GrContext::kExact_Sc
ratchTexMatch); | 150 GrContext::kExact_Sc
ratchTexMatch); |
149 result->writePixels(0, 0, bitmap->width(), | 151 result->writePixels(0, 0, bitmap->width(), |
150 bitmap->height(), desc.fConfig, | 152 bitmap->height(), desc.fConfig, |
151 storage.get()); | 153 storage.get()); |
152 return result; | 154 return result; |
153 } | 155 } |
154 } else { | 156 } else { |
155 origBitmap.copyTo(&tmpBitmap, SkBitmap::kARGB_8888_Config); | 157 origBitmap.copyTo(&tmpBitmap, SkBitmap::kARGB_8888_Config); |
156 // now bitmap points to our temp, which has been promoted to 32bits | 158 // now bitmap points to our temp, which has been promoted to 32bits |
157 bitmap = &tmpBitmap; | 159 bitmap = &tmpBitmap; |
158 desc.fConfig = SkBitmapConfig2GrPixelConfig(bitmap->config()); | 160 desc.fConfig = SkBitmapConfig2GrPixelConfig(bitmap->config()); |
159 } | 161 } |
160 } | 162 } |
161 | 163 |
162 SkAutoLockPixels alp(*bitmap); | 164 SkAutoLockPixels alp(*bitmap); |
163 if (!bitmap->readyToDraw()) { | 165 if (!bitmap->readyToDraw()) { |
164 return NULL; | 166 return NULL; |
165 } | 167 } |
166 if (cache) { | 168 if (cache) { |
167 // This texture is likely to be used again so leave it in the cache | 169 // This texture is likely to be used again so leave it in the cache |
168 GrCacheID cacheID; | 170 GrCacheID cacheID; |
169 generate_bitmap_cache_id(origBitmap, &cacheID); | 171 generate_bitmap_cache_id(origBitmap, &cacheID); |
170 | 172 |
171 GrResourceKey key; | 173 GrResourceKey key; |
172 GrTexture* result = ctx->createTexture(params, desc, cacheID, | 174 GrTexture* result = ctx->createTexture(params, desc, cacheID, |
173 bitmap->getPixels(), bitmap->rowB
ytes(), &key); | 175 bitmap->getPixels(), bitmap->rowB
ytes(), &key); |
174 add_genID_listener(key, origBitmap.pixelRef()); | 176 if (NULL != result) { |
| 177 add_genID_listener(key, origBitmap.pixelRef()); |
| 178 } |
175 return result; | 179 return result; |
176 } else { | 180 } else { |
177 // This texture is unlikely to be used again (in its present form) so | 181 // This texture is unlikely to be used again (in its present form) so |
178 // just use a scratch texture. This will remove the texture from the | 182 // just use a scratch texture. This will remove the texture from the |
179 // cache so no one else can find it. Additionally, once unlocked, the | 183 // cache so no one else can find it. Additionally, once unlocked, the |
180 // scratch texture will go to the end of the list for purging so will | 184 // scratch texture will go to the end of the list for purging so will |
181 // likely be available for this volatile bitmap the next time around. | 185 // likely be available for this volatile bitmap the next time around. |
182 GrTexture* result = ctx->lockAndRefScratchTexture(desc, GrContext::kExac
t_ScratchTexMatch); | 186 GrTexture* result = ctx->lockAndRefScratchTexture(desc, GrContext::kExac
t_ScratchTexMatch); |
183 result->writePixels(0, 0, | 187 result->writePixels(0, 0, |
184 bitmap->width(), bitmap->height(), | 188 bitmap->width(), bitmap->height(), |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 return kRGB_565_GrPixelConfig; | 251 return kRGB_565_GrPixelConfig; |
248 case SkBitmap::kARGB_4444_Config: | 252 case SkBitmap::kARGB_4444_Config: |
249 return kRGBA_4444_GrPixelConfig; | 253 return kRGBA_4444_GrPixelConfig; |
250 case SkBitmap::kARGB_8888_Config: | 254 case SkBitmap::kARGB_8888_Config: |
251 return kSkia8888_GrPixelConfig; | 255 return kSkia8888_GrPixelConfig; |
252 default: | 256 default: |
253 // kNo_Config, kA1_Config missing | 257 // kNo_Config, kA1_Config missing |
254 return kUnknown_GrPixelConfig; | 258 return kUnknown_GrPixelConfig; |
255 } | 259 } |
256 } | 260 } |
OLD | NEW |