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

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

Issue 1420963008: Pull texture-backed bitmap resampler out of GrTextureParamsAdjuster code into its own class. (Closed) Base URL: https://skia.googlesource.com/skia.git@nomin
Patch Set: update Created 5 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
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 8
9 #include "SkGr.h" 9 #include "SkGr.h"
10 10
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 return nullptr; 264 return nullptr;
265 } 265 }
266 266
267 return ctx->textureProvider()->createTexture(desc, true, bitmap->getPixels() , 267 return ctx->textureProvider()->createTexture(desc, true, bitmap->getPixels() ,
268 bitmap->rowBytes()); 268 bitmap->rowBytes());
269 } 269 }
270 270
271 271
272 //////////////////////////////////////////////////////////////////////////////// 272 ////////////////////////////////////////////////////////////////////////////////
273 273
274 class Bitmap_GrTextureParamsAdjuster : public GrTextureParamsAdjuster { 274 static void install_bmp_key_invalidator(const GrUniqueKey& key, SkPixelRef* pixe lRef) {
275 class Invalidator : public SkPixelRef::GenIDChangeListener {
276 public:
277 explicit Invalidator(const GrUniqueKey& key) : fMsg(key) {}
278 private:
279 GrUniqueKeyInvalidatedMessage fMsg;
280
robertphillips 2015/10/29 16:57:54 rm the stray \n ?
bsalomon 2015/10/29 17:36:22 Done.
281 void onChange() override { SkMessageBus<GrUniqueKeyInvalidatedMessage>:: Post(fMsg);
282 }
283 };
284
285 pixelRef->addGenIDChangeListener(new Invalidator(key));
286 }
287
288 class RasterBitmap_GrTextureMaker : public GrTextureMaker {
275 public: 289 public:
276 Bitmap_GrTextureParamsAdjuster(const SkBitmap& bitmap) 290 RasterBitmap_GrTextureMaker(const SkBitmap& bitmap)
277 : INHERITED(bitmap.width(), bitmap.height()) 291 : INHERITED(bitmap.width(), bitmap.height())
278 , fBitmap(bitmap) 292 , fBitmap(bitmap)
279 { 293 {
294 SkASSERT(!bitmap.getTexture());
280 if (!bitmap.isVolatile()) { 295 if (!bitmap.isVolatile()) {
281 SkIPoint origin = bitmap.pixelRefOrigin(); 296 SkIPoint origin = bitmap.pixelRefOrigin();
282 SkIRect subset = SkIRect::MakeXYWH(origin.fX, origin.fY, bitmap.widt h(), 297 SkIRect subset = SkIRect::MakeXYWH(origin.fX, origin.fY, bitmap.widt h(),
283 bitmap.height()); 298 bitmap.height());
284 GrMakeKeyFromImageID(&fOriginalKey, bitmap.pixelRef()->getGeneration ID(), subset); 299 GrMakeKeyFromImageID(&fOriginalKey, bitmap.pixelRef()->getGeneration ID(), subset);
285 } 300 }
286 } 301 }
287 302
288 protected: 303 protected:
289 GrTexture* refOriginalTexture(GrContext* ctx) override { 304 GrTexture* refOriginalTexture(GrContext* ctx) override {
290 GrTexture* tex = fBitmap.getTexture(); 305 GrTexture* tex;
291 if (tex) {
292 return SkRef(tex);
293 }
294 306
295 if (fOriginalKey.isValid()) { 307 if (fOriginalKey.isValid()) {
296 tex = ctx->textureProvider()->findAndRefTextureByUniqueKey(fOriginal Key); 308 tex = ctx->textureProvider()->findAndRefTextureByUniqueKey(fOriginal Key);
297 if (tex) { 309 if (tex) {
298 return tex; 310 return tex;
299 } 311 }
300 } 312 }
301 313
302 tex = GrUploadBitmapToTexture(ctx, fBitmap); 314 tex = GrUploadBitmapToTexture(ctx, fBitmap);
303 if (tex && fOriginalKey.isValid()) { 315 if (tex && fOriginalKey.isValid()) {
304 tex->resourcePriv().setUniqueKey(fOriginalKey); 316 tex->resourcePriv().setUniqueKey(fOriginalKey);
305 InstallInvalidator(fOriginalKey, fBitmap.pixelRef()); 317 install_bmp_key_invalidator(fOriginalKey, fBitmap.pixelRef());
306 } 318 }
307 return tex; 319 return tex;
308 } 320 }
309 321
310 void makeCopyKey(const CopyParams& copyParams, GrUniqueKey* copyKey) overrid e { 322 void makeCopyKey(const CopyParams& copyParams, GrUniqueKey* copyKey) overrid e {
311 if (fOriginalKey.isValid()) { 323 if (fOriginalKey.isValid()) {
312 MakeCopyKeyFromOrigKey(fOriginalKey, copyParams, copyKey); 324 MakeCopyKeyFromOrigKey(fOriginalKey, copyParams, copyKey);
313 } 325 }
314 } 326 }
315 327
316 void didCacheCopy(const GrUniqueKey& copyKey) override { 328 void didCacheCopy(const GrUniqueKey& copyKey) override {
317 InstallInvalidator(copyKey, fBitmap.pixelRef()); 329 install_bmp_key_invalidator(copyKey, fBitmap.pixelRef());
318 } 330 }
319 331
320 private: 332 private:
321 static void InstallInvalidator(const GrUniqueKey& key, SkPixelRef* pixelRef) {
322 class Invalidator : public SkPixelRef::GenIDChangeListener {
323 public:
324 explicit Invalidator(const GrUniqueKey& key) : fMsg(key) {}
325 private:
326 GrUniqueKeyInvalidatedMessage fMsg;
327
328 void onChange() override {
329 SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(fMsg);
330 }
331 };
332 Invalidator* listener = new Invalidator(key);
333 pixelRef->addGenIDChangeListener(listener);
334 }
335
336 const SkBitmap fBitmap; 333 const SkBitmap fBitmap;
337 GrUniqueKey fOriginalKey; 334 GrUniqueKey fOriginalKey;
338 335
339 typedef GrTextureParamsAdjuster INHERITED; 336 typedef GrTextureMaker INHERITED;
337 };
338
339 class TextureBitmap_GrTextureAdjuster : public GrTextureAdjuster {
340 public:
341 explicit TextureBitmap_GrTextureAdjuster(const SkBitmap* bmp)
342 : INHERITED(bmp->getTexture(), SkIRect::MakeWH(bmp->width(), bmp->height ()))
343 , fBmp(bmp) {}
344
345 private:
346 void makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey) override {
347 if (fBmp->isVolatile()) {
348 return;
349 }
350 // The texture subset must represent the whole bitmap. Texture-backed bi tmaps don't support
robertphillips 2015/10/29 16:57:54 teture is -> texture are ?
bsalomon 2015/10/29 17:36:22 Done.
351 // extractSubset(). Therefore, either the bitmap and the teture is the s ame size or the
352 // subset's dimensions are the bitmap's dimensions.
353 GrUniqueKey baseKey;
354 GrMakeKeyFromImageID(&baseKey, fBmp->getGenerationID(),
355 SkIRect::MakeWH(fBmp->width(), fBmp->height()));
356 MakeCopyKeyFromOrigKey(baseKey, params, copyKey);
357 }
358
359 void didCacheCopy(const GrUniqueKey& copyKey) override {
360 install_bmp_key_invalidator(copyKey, fBmp->pixelRef());
361 }
362
363 const SkBitmap* fBmp;
364
365 typedef GrTextureAdjuster INHERITED;
340 }; 366 };
341 367
342 GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, const SkBitmap& bitmap, 368 GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, const SkBitmap& bitmap,
343 const GrTextureParams& params) { 369 const GrTextureParams& params) {
344 return Bitmap_GrTextureParamsAdjuster(bitmap).refTextureForParams(ctx, param s); 370 if (GrTexture* texture = bitmap.getTexture()) {
371 return TextureBitmap_GrTextureAdjuster(&bitmap).refTextureSafeForParams( params, nullptr);
372 }
373 return RasterBitmap_GrTextureMaker(bitmap).refTextureForParams(ctx, params);
345 } 374 }
346 375
347 /////////////////////////////////////////////////////////////////////////////// 376 ///////////////////////////////////////////////////////////////////////////////
348 377
349 // alphatype is ignore for now, but if GrPixelConfig is expanded to encompass 378 // alphatype is ignore for now, but if GrPixelConfig is expanded to encompass
350 // alpha info, that will be considered. 379 // alpha info, that will be considered.
351 GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType ct, SkAlphaType, SkColorProf ileType pt) { 380 GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType ct, SkAlphaType, SkColorProf ileType pt) {
352 switch (ct) { 381 switch (ct) {
353 case kUnknown_SkColorType: 382 case kUnknown_SkColorType:
354 return kUnknown_GrPixelConfig; 383 return kUnknown_GrPixelConfig;
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 SkErrorInternals::SetError( kInvalidPaint_SkError, 684 SkErrorInternals::SetError( kInvalidPaint_SkError,
656 "Sorry, I don't understand the filtering " 685 "Sorry, I don't understand the filtering "
657 "mode you asked for. Falling back to " 686 "mode you asked for. Falling back to "
658 "MIPMaps."); 687 "MIPMaps.");
659 textureFilterMode = GrTextureParams::kMipMap_FilterMode; 688 textureFilterMode = GrTextureParams::kMipMap_FilterMode;
660 break; 689 break;
661 690
662 } 691 }
663 return textureFilterMode; 692 return textureFilterMode;
664 } 693 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698