OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkBitmapCache.h" | 9 #include "SkBitmapCache.h" |
10 #include "SkImageCacherator.h" | 10 #include "SkImageCacherator.h" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 SkBitmapCache::Add(fUniqueID, *bitmap); | 155 SkBitmapCache::Add(fUniqueID, *bitmap); |
156 return check_output_bitmap(*bitmap, fUniqueID); | 156 return check_output_bitmap(*bitmap, fUniqueID); |
157 #else | 157 #else |
158 return false; | 158 return false; |
159 #endif | 159 #endif |
160 } | 160 } |
161 | 161 |
162 ////////////////////////////////////////////////////////////////////////////////
////////////////// | 162 ////////////////////////////////////////////////////////////////////////////////
////////////////// |
163 | 163 |
164 #if SK_SUPPORT_GPU | 164 #if SK_SUPPORT_GPU |
165 static void make_texture_desc(const SkImageInfo& info, GrSurfaceDesc* desc) { | |
166 desc->fFlags = kNone_GrSurfaceFlags; | |
167 desc->fWidth = info.width(); | |
168 desc->fHeight = info.height(); | |
169 desc->fConfig = SkImageInfo2GrPixelConfig(info); | |
170 desc->fSampleCnt = 0; | |
171 } | |
172 | 165 |
173 static GrTexture* load_compressed_into_texture(GrContext* ctx, SkData* data, GrS
urfaceDesc desc) { | 166 static GrTexture* load_compressed_into_texture(GrContext* ctx, SkData* data, GrS
urfaceDesc desc) { |
174 const void* rawStart; | 167 const void* rawStart; |
175 GrPixelConfig config = GrIsCompressedTextureDataSupported(ctx, data, desc.fW
idth, desc.fHeight, | 168 GrPixelConfig config = GrIsCompressedTextureDataSupported(ctx, data, desc.fW
idth, desc.fHeight, |
176 &rawStart); | 169 &rawStart); |
177 if (kUnknown_GrPixelConfig == config) { | 170 if (kUnknown_GrPixelConfig == config) { |
178 return nullptr; | 171 return nullptr; |
179 } | 172 } |
180 | 173 |
181 desc.fConfig = config; | 174 desc.fConfig = config; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 // textures (at least the texture-key) only support 16bit dimensions, so abo
rt early | 215 // textures (at least the texture-key) only support 16bit dimensions, so abo
rt early |
223 // if we're too big. | 216 // if we're too big. |
224 if (fInfo.width() > 0xFFFF || fInfo.height() > 0xFFFF) { | 217 if (fInfo.width() > 0xFFFF || fInfo.height() > 0xFFFF) { |
225 return nullptr; | 218 return nullptr; |
226 } | 219 } |
227 | 220 |
228 GrUniqueKey key; | 221 GrUniqueKey key; |
229 GrMakeKeyFromImageID(&key, fUniqueID, SkIRect::MakeWH(fInfo.width(), fInfo.h
eight()), | 222 GrMakeKeyFromImageID(&key, fUniqueID, SkIRect::MakeWH(fInfo.width(), fInfo.h
eight()), |
230 *ctx->caps(), usage); | 223 *ctx->caps(), usage); |
231 | 224 |
232 GrSurfaceDesc desc; | |
233 make_texture_desc(fInfo, &desc); | |
234 | |
235 // 1. Check the cache for a pre-existing one | 225 // 1. Check the cache for a pre-existing one |
236 if (GrTexture* tex = ctx->textureProvider()->findAndRefTextureByUniqueKey(ke
y)) { | 226 if (GrTexture* tex = ctx->textureProvider()->findAndRefTextureByUniqueKey(ke
y)) { |
237 return tex; | 227 return tex; |
238 } | 228 } |
239 | 229 |
240 // 2. Ask the genreator to natively create one | 230 // 2. Ask the genreator to natively create one |
241 { | 231 { |
242 ScopedGenerator generator(this); | 232 ScopedGenerator generator(this); |
243 SkIRect subset = SkIRect::MakeXYWH(fOrigin.x(), fOrigin.y(), fInfo.width
(), fInfo.height()); | 233 SkIRect subset = SkIRect::MakeXYWH(fOrigin.x(), fOrigin.y(), fInfo.width
(), fInfo.height()); |
244 if (GrTexture* tex = generator->generateTexture(ctx, usage, &subset)) { | 234 if (GrTexture* tex = generator->generateTexture(ctx, usage, &subset)) { |
245 return set_key_and_return(tex, key); | 235 return set_key_and_return(tex, key); |
246 } | 236 } |
247 } | 237 } |
248 | 238 |
| 239 const GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(fInfo); |
| 240 |
249 // 3. Ask the generator to return a compressed form that the GPU might suppo
rt | 241 // 3. Ask the generator to return a compressed form that the GPU might suppo
rt |
250 SkAutoTUnref<SkData> data(this->refEncoded()); | 242 SkAutoTUnref<SkData> data(this->refEncoded()); |
251 if (data) { | 243 if (data) { |
252 GrTexture* tex = load_compressed_into_texture(ctx, data, desc); | 244 GrTexture* tex = load_compressed_into_texture(ctx, data, desc); |
253 if (tex) { | 245 if (tex) { |
254 return set_key_and_return(tex, key); | 246 return set_key_and_return(tex, key); |
255 } | 247 } |
256 } | 248 } |
257 | 249 |
258 // 4. Ask the generator to return YUV planes, which the GPU can convert | 250 // 4. Ask the generator to return YUV planes, which the GPU can convert |
259 { | 251 { |
260 ScopedGenerator generator(this); | 252 ScopedGenerator generator(this); |
261 Generator_GrYUVProvider provider(generator); | 253 Generator_GrYUVProvider provider(generator); |
262 GrTexture* tex = provider.refAsTexture(ctx, desc, true); | 254 GrTexture* tex = provider.refAsTexture(ctx, desc, true); |
263 if (tex) { | 255 if (tex) { |
264 return set_key_and_return(tex, key); | 256 return set_key_and_return(tex, key); |
265 } | 257 } |
266 } | 258 } |
267 | 259 |
268 // 5. Ask the generator to return RGB(A) data, which the GPU can convert | 260 // 5. Ask the generator to return RGB(A) data, which the GPU can convert |
269 SkBitmap bitmap; | 261 SkBitmap bitmap; |
270 if (this->tryLockAsBitmap(&bitmap)) { | 262 if (this->tryLockAsBitmap(&bitmap)) { |
271 return GrRefCachedBitmapTexture(ctx, bitmap, usage); | 263 return GrRefCachedBitmapTexture(ctx, bitmap, usage); |
272 } | 264 } |
273 #endif | 265 #endif |
274 | 266 |
275 return nullptr; | 267 return nullptr; |
276 } | 268 } |
277 | 269 |
OLD | NEW |