Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: src/gpu/SkGr.cpp

Issue 682223002: rename GrTextureDesc->GrSurfaceDesc, GrTextureFlags->GrSurfaceFlags (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: const Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/SkGpuDevice.cpp ('k') | src/gpu/SkGrPixelRef.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkColorFilter.h" 9 #include "SkColorFilter.h"
10 #include "SkConfig8888.h" 10 #include "SkConfig8888.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 memcpy(key.fData8 + 8, &origin.fY, 4); 98 memcpy(key.fData8 + 8, &origin.fY, 4);
99 memcpy(key.fData8 + 12, &width, 2); 99 memcpy(key.fData8 + 12, &width, 2);
100 memcpy(key.fData8 + 14, &height, 2); 100 memcpy(key.fData8 + 14, &height, 2);
101 static const size_t kKeyDataSize = 16; 101 static const size_t kKeyDataSize = 16;
102 memset(key.fData8 + kKeyDataSize, 0, sizeof(key) - kKeyDataSize); 102 memset(key.fData8 + kKeyDataSize, 0, sizeof(key) - kKeyDataSize);
103 GR_STATIC_ASSERT(sizeof(key) >= kKeyDataSize); 103 GR_STATIC_ASSERT(sizeof(key) >= kKeyDataSize);
104 static const GrCacheID::Domain gBitmapTextureDomain = GrCacheID::GenerateDom ain(); 104 static const GrCacheID::Domain gBitmapTextureDomain = GrCacheID::GenerateDom ain();
105 id->reset(gBitmapTextureDomain, key); 105 id->reset(gBitmapTextureDomain, key);
106 } 106 }
107 107
108 static void generate_bitmap_texture_desc(const SkBitmap& bitmap, GrTextureDesc* desc) { 108 static void generate_bitmap_texture_desc(const SkBitmap& bitmap, GrSurfaceDesc* desc) {
109 desc->fFlags = kNone_GrTextureFlags; 109 desc->fFlags = kNone_GrSurfaceFlags;
110 desc->fWidth = bitmap.width(); 110 desc->fWidth = bitmap.width();
111 desc->fHeight = bitmap.height(); 111 desc->fHeight = bitmap.height();
112 desc->fConfig = SkImageInfo2GrPixelConfig(bitmap.info()); 112 desc->fConfig = SkImageInfo2GrPixelConfig(bitmap.info());
113 desc->fSampleCnt = 0; 113 desc->fSampleCnt = 0;
114 } 114 }
115 115
116 namespace { 116 namespace {
117 117
118 // When the SkPixelRef genID changes, invalidate a corresponding GrResource desc ribed by key. 118 // When the SkPixelRef genID changes, invalidate a corresponding GrResource desc ribed by key.
119 class GrResourceInvalidator : public SkPixelRef::GenIDChangeListener { 119 class GrResourceInvalidator : public SkPixelRef::GenIDChangeListener {
(...skipping 12 matching lines...) Expand all
132 132
133 static void add_genID_listener(GrResourceKey key, SkPixelRef* pixelRef) { 133 static void add_genID_listener(GrResourceKey key, SkPixelRef* pixelRef) {
134 SkASSERT(pixelRef); 134 SkASSERT(pixelRef);
135 pixelRef->addGenIDChangeListener(SkNEW_ARGS(GrResourceInvalidator, (key))); 135 pixelRef->addGenIDChangeListener(SkNEW_ARGS(GrResourceInvalidator, (key)));
136 } 136 }
137 137
138 static GrTexture* sk_gr_allocate_texture(GrContext* ctx, 138 static GrTexture* sk_gr_allocate_texture(GrContext* ctx,
139 bool cache, 139 bool cache,
140 const GrTextureParams* params, 140 const GrTextureParams* params,
141 const SkBitmap& bm, 141 const SkBitmap& bm,
142 GrTextureDesc desc, 142 GrSurfaceDesc desc,
143 const void* pixels, 143 const void* pixels,
144 size_t rowBytes) { 144 size_t rowBytes) {
145 GrTexture* result; 145 GrTexture* result;
146 if (cache) { 146 if (cache) {
147 // This texture is likely to be used again so leave it in the cache 147 // This texture is likely to be used again so leave it in the cache
148 GrCacheID cacheID; 148 GrCacheID cacheID;
149 generate_bitmap_cache_id(bm, &cacheID); 149 generate_bitmap_cache_id(bm, &cacheID);
150 150
151 GrResourceKey key; 151 GrResourceKey key;
152 result = ctx->createTexture(params, desc, cacheID, pixels, rowBytes, &ke y); 152 result = ctx->createTexture(params, desc, cacheID, pixels, rowBytes, &ke y);
(...skipping 10 matching lines...) Expand all
163 if (pixels) { 163 if (pixels) {
164 result->writePixels(0, 0, bm.width(), bm.height(), desc.fConfig, pix els, rowBytes); 164 result->writePixels(0, 0, bm.width(), bm.height(), desc.fConfig, pix els, rowBytes);
165 } 165 }
166 } 166 }
167 return result; 167 return result;
168 } 168 }
169 169
170 #ifndef SK_IGNORE_ETC1_SUPPORT 170 #ifndef SK_IGNORE_ETC1_SUPPORT
171 static GrTexture *load_etc1_texture(GrContext* ctx, bool cache, 171 static GrTexture *load_etc1_texture(GrContext* ctx, bool cache,
172 const GrTextureParams* params, 172 const GrTextureParams* params,
173 const SkBitmap &bm, GrTextureDesc desc) { 173 const SkBitmap &bm, GrSurfaceDesc desc) {
174 SkAutoTUnref<SkData> data(bm.pixelRef()->refEncodedData()); 174 SkAutoTUnref<SkData> data(bm.pixelRef()->refEncodedData());
175 175
176 // Is this even encoded data? 176 // Is this even encoded data?
177 if (NULL == data) { 177 if (NULL == data) {
178 return NULL; 178 return NULL;
179 } 179 }
180 180
181 // Is this a valid PKM encoded data? 181 // Is this a valid PKM encoded data?
182 const uint8_t *bytes = data->bytes(); 182 const uint8_t *bytes = data->bytes();
183 if (etc1_pkm_is_valid(bytes)) { 183 if (etc1_pkm_is_valid(bytes)) {
(...skipping 28 matching lines...) Expand all
212 desc.fConfig = kETC1_GrPixelConfig; 212 desc.fConfig = kETC1_GrPixelConfig;
213 } else { 213 } else {
214 return NULL; 214 return NULL;
215 } 215 }
216 216
217 return sk_gr_allocate_texture(ctx, cache, params, bm, desc, bytes, 0); 217 return sk_gr_allocate_texture(ctx, cache, params, bm, desc, bytes, 0);
218 } 218 }
219 #endif // SK_IGNORE_ETC1_SUPPORT 219 #endif // SK_IGNORE_ETC1_SUPPORT
220 220
221 static GrTexture *load_yuv_texture(GrContext* ctx, bool cache, const GrTexturePa rams* params, 221 static GrTexture *load_yuv_texture(GrContext* ctx, bool cache, const GrTexturePa rams* params,
222 const SkBitmap& bm, const GrTextureDesc& desc ) { 222 const SkBitmap& bm, const GrSurfaceDesc& desc ) {
223 // Subsets are not supported, the whole pixelRef is loaded when using YUV de coding 223 // Subsets are not supported, the whole pixelRef is loaded when using YUV de coding
224 if ((bm.pixelRef()->info().width() != bm.info().width()) || 224 if ((bm.pixelRef()->info().width() != bm.info().width()) ||
225 (bm.pixelRef()->info().height() != bm.info().height())) { 225 (bm.pixelRef()->info().height() != bm.info().height())) {
226 return NULL; 226 return NULL;
227 } 227 }
228 228
229 SkPixelRef* pixelRef = bm.pixelRef(); 229 SkPixelRef* pixelRef = bm.pixelRef();
230 SkISize yuvSizes[3]; 230 SkISize yuvSizes[3];
231 if ((NULL == pixelRef) || !pixelRef->getYUV8Planes(yuvSizes, NULL, NULL, NUL L)) { 231 if ((NULL == pixelRef) || !pixelRef->getYUV8Planes(yuvSizes, NULL, NULL, NUL L)) {
232 return NULL; 232 return NULL;
(...skipping 12 matching lines...) Expand all
245 planes[1] = (uint8_t*)planes[0] + sizes[0]; 245 planes[1] = (uint8_t*)planes[0] + sizes[0];
246 planes[2] = (uint8_t*)planes[1] + sizes[1]; 246 planes[2] = (uint8_t*)planes[1] + sizes[1];
247 247
248 SkYUVColorSpace colorSpace; 248 SkYUVColorSpace colorSpace;
249 249
250 // Get the YUV planes 250 // Get the YUV planes
251 if (!pixelRef->getYUV8Planes(yuvSizes, planes, rowBytes, &colorSpace)) { 251 if (!pixelRef->getYUV8Planes(yuvSizes, planes, rowBytes, &colorSpace)) {
252 return NULL; 252 return NULL;
253 } 253 }
254 254
255 GrTextureDesc yuvDesc; 255 GrSurfaceDesc yuvDesc;
256 yuvDesc.fConfig = kAlpha_8_GrPixelConfig; 256 yuvDesc.fConfig = kAlpha_8_GrPixelConfig;
257 SkAutoTUnref<GrTexture> yuvTextures[3]; 257 SkAutoTUnref<GrTexture> yuvTextures[3];
258 for (int i = 0; i < 3; ++i) { 258 for (int i = 0; i < 3; ++i) {
259 yuvDesc.fWidth = yuvSizes[i].fWidth; 259 yuvDesc.fWidth = yuvSizes[i].fWidth;
260 yuvDesc.fHeight = yuvSizes[i].fHeight; 260 yuvDesc.fHeight = yuvSizes[i].fHeight;
261 yuvTextures[i].reset( 261 yuvTextures[i].reset(
262 ctx->refScratchTexture(yuvDesc, GrContext::kApprox_ScratchTexMatch)) ; 262 ctx->refScratchTexture(yuvDesc, GrContext::kApprox_ScratchTexMatch)) ;
263 if (!yuvTextures[i] || 263 if (!yuvTextures[i] ||
264 !yuvTextures[i]->writePixels(0, 0, yuvDesc.fWidth, yuvDesc.fHeight, 264 !yuvTextures[i]->writePixels(0, 0, yuvDesc.fWidth, yuvDesc.fHeight,
265 yuvDesc.fConfig, planes[i], rowBytes[i] )) { 265 yuvDesc.fConfig, planes[i], rowBytes[i] )) {
266 return NULL; 266 return NULL;
267 } 267 }
268 } 268 }
269 269
270 GrTextureDesc rtDesc = desc; 270 GrSurfaceDesc rtDesc = desc;
271 rtDesc.fFlags = rtDesc.fFlags | 271 rtDesc.fFlags = rtDesc.fFlags |
272 kRenderTarget_GrTextureFlagBit | 272 kRenderTarget_GrSurfaceFlag |
273 kNoStencil_GrTextureFlagBit; 273 kNoStencil_GrSurfaceFlag;
274 274
275 GrTexture* result = sk_gr_allocate_texture(ctx, cache, params, bm, rtDesc, N ULL, 0); 275 GrTexture* result = sk_gr_allocate_texture(ctx, cache, params, bm, rtDesc, N ULL, 0);
276 276
277 GrRenderTarget* renderTarget = result ? result->asRenderTarget() : NULL; 277 GrRenderTarget* renderTarget = result ? result->asRenderTarget() : NULL;
278 if (renderTarget) { 278 if (renderTarget) {
279 SkAutoTUnref<GrFragmentProcessor> yuvToRgbProcessor( 279 SkAutoTUnref<GrFragmentProcessor> yuvToRgbProcessor(
280 GrYUVtoRGBEffect::Create(yuvTextures[0], yuvTextures[1], yuvTextures [2], colorSpace)); 280 GrYUVtoRGBEffect::Create(yuvTextures[0], yuvTextures[1], yuvTextures [2], colorSpace));
281 GrPaint paint; 281 GrPaint paint;
282 paint.addColorProcessor(yuvToRgbProcessor); 282 paint.addColorProcessor(yuvToRgbProcessor);
283 SkRect r = SkRect::MakeWH(SkIntToScalar(yuvSizes[0].fWidth), 283 SkRect r = SkRect::MakeWH(SkIntToScalar(yuvSizes[0].fWidth),
(...skipping 11 matching lines...) Expand all
295 } 295 }
296 296
297 static GrTexture* sk_gr_create_bitmap_texture(GrContext* ctx, 297 static GrTexture* sk_gr_create_bitmap_texture(GrContext* ctx,
298 bool cache, 298 bool cache,
299 const GrTextureParams* params, 299 const GrTextureParams* params,
300 const SkBitmap& origBitmap) { 300 const SkBitmap& origBitmap) {
301 SkBitmap tmpBitmap; 301 SkBitmap tmpBitmap;
302 302
303 const SkBitmap* bitmap = &origBitmap; 303 const SkBitmap* bitmap = &origBitmap;
304 304
305 GrTextureDesc desc; 305 GrSurfaceDesc desc;
306 generate_bitmap_texture_desc(*bitmap, &desc); 306 generate_bitmap_texture_desc(*bitmap, &desc);
307 307
308 if (kIndex_8_SkColorType == bitmap->colorType()) { 308 if (kIndex_8_SkColorType == bitmap->colorType()) {
309 // build_compressed_data doesn't do npot->pot expansion 309 // build_compressed_data doesn't do npot->pot expansion
310 // and paletted textures can't be sub-updated 310 // and paletted textures can't be sub-updated
311 if (cache && ctx->supportsIndex8PixelConfig(params, bitmap->width(), bit map->height())) { 311 if (cache && ctx->supportsIndex8PixelConfig(params, bitmap->width(), bit map->height())) {
312 size_t imageSize = GrCompressedFormatDataSize(kIndex_8_GrPixelConfig , 312 size_t imageSize = GrCompressedFormatDataSize(kIndex_8_GrPixelConfig ,
313 bitmap->width(), bitma p->height()); 313 bitmap->width(), bitma p->height());
314 SkAutoMalloc storage(imageSize); 314 SkAutoMalloc storage(imageSize);
315 build_index8_data(storage.get(), origBitmap); 315 build_index8_data(storage.get(), origBitmap);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 return sk_gr_allocate_texture(ctx, cache, params, origBitmap, desc, 361 return sk_gr_allocate_texture(ctx, cache, params, origBitmap, desc,
362 bitmap->getPixels(), bitmap->rowBytes()); 362 bitmap->getPixels(), bitmap->rowBytes());
363 } 363 }
364 364
365 bool GrIsBitmapInCache(const GrContext* ctx, 365 bool GrIsBitmapInCache(const GrContext* ctx,
366 const SkBitmap& bitmap, 366 const SkBitmap& bitmap,
367 const GrTextureParams* params) { 367 const GrTextureParams* params) {
368 GrCacheID cacheID; 368 GrCacheID cacheID;
369 generate_bitmap_cache_id(bitmap, &cacheID); 369 generate_bitmap_cache_id(bitmap, &cacheID);
370 370
371 GrTextureDesc desc; 371 GrSurfaceDesc desc;
372 generate_bitmap_texture_desc(bitmap, &desc); 372 generate_bitmap_texture_desc(bitmap, &desc);
373 return ctx->isTextureInCache(desc, cacheID, params); 373 return ctx->isTextureInCache(desc, cacheID, params);
374 } 374 }
375 375
376 GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, 376 GrTexture* GrRefCachedBitmapTexture(GrContext* ctx,
377 const SkBitmap& bitmap, 377 const SkBitmap& bitmap,
378 const GrTextureParams* params) { 378 const GrTextureParams* params) {
379 GrTexture* result = NULL; 379 GrTexture* result = NULL;
380 380
381 bool cache = !bitmap.isVolatile(); 381 bool cache = !bitmap.isVolatile();
382 382
383 if (cache) { 383 if (cache) {
384 // If the bitmap isn't changing try to find a cached copy first. 384 // If the bitmap isn't changing try to find a cached copy first.
385 385
386 GrCacheID cacheID; 386 GrCacheID cacheID;
387 generate_bitmap_cache_id(bitmap, &cacheID); 387 generate_bitmap_cache_id(bitmap, &cacheID);
388 388
389 GrTextureDesc desc; 389 GrSurfaceDesc desc;
390 generate_bitmap_texture_desc(bitmap, &desc); 390 generate_bitmap_texture_desc(bitmap, &desc);
391 391
392 result = ctx->findAndRefTexture(desc, cacheID, params); 392 result = ctx->findAndRefTexture(desc, cacheID, params);
393 } 393 }
394 if (NULL == result) { 394 if (NULL == result) {
395 result = sk_gr_create_bitmap_texture(ctx, cache, params, bitmap); 395 result = sk_gr_create_bitmap_texture(ctx, cache, params, bitmap);
396 } 396 }
397 if (NULL == result) { 397 if (NULL == result) {
398 GrPrintf("---- failed to create texture for cache [%d %d]\n", 398 GrPrintf("---- failed to create texture for cache [%d %d]\n",
399 bitmap.width(), bitmap.height()); 399 bitmap.width(), bitmap.height());
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 if (shader->asFragmentProcessor(context, skPaint, NULL, &paintColor, &fp ) && fp) { 574 if (shader->asFragmentProcessor(context, skPaint, NULL, &paintColor, &fp ) && fp) {
575 grPaint->addColorProcessor(fp)->unref(); 575 grPaint->addColorProcessor(fp)->unref();
576 constantColor = false; 576 constantColor = false;
577 } 577 }
578 } 578 }
579 579
580 // The grcolor is automatically set when calling asFragmentProcessor. 580 // The grcolor is automatically set when calling asFragmentProcessor.
581 // If the shader can be seen as an effect it returns true and adds its effec t to the grpaint. 581 // If the shader can be seen as an effect it returns true and adds its effec t to the grpaint.
582 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint ); 582 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint );
583 } 583 }
OLDNEW
« no previous file with comments | « src/gpu/SkGpuDevice.cpp ('k') | src/gpu/SkGrPixelRef.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698