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

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

Issue 1424313010: Separate out natively-texture image/bmp draws from cached-as-texture image/bmp draws (Closed) Base URL: https://skia.googlesource.com/skia.git@const
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
« no previous file with comments | « src/gpu/SkGpuDevice_drawTexture.cpp ('k') | src/gpu/SkGrPriv.h » ('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 8
9 #include "SkGr.h" 9 #include "SkGr.h"
10 10
11 #include "GrCaps.h" 11 #include "GrCaps.h"
12 #include "GrContext.h" 12 #include "GrContext.h"
13 #include "GrTextureParamsAdjuster.h" 13 #include "GrTextureParamsAdjuster.h"
14 #include "GrGpuResourcePriv.h" 14 #include "GrGpuResourcePriv.h"
15 #include "GrImageIDTextureAdjuster.h"
15 #include "GrXferProcessor.h" 16 #include "GrXferProcessor.h"
16 #include "GrYUVProvider.h" 17 #include "GrYUVProvider.h"
17 18
18 #include "SkColorFilter.h" 19 #include "SkColorFilter.h"
19 #include "SkConfig8888.h" 20 #include "SkConfig8888.h"
20 #include "SkCanvas.h" 21 #include "SkCanvas.h"
21 #include "SkData.h" 22 #include "SkData.h"
22 #include "SkErrorInternals.h" 23 #include "SkErrorInternals.h"
23 #include "SkGrPixelRef.h" 24 #include "SkGrPixelRef.h"
24 #include "SkMessageBus.h" 25 #include "SkMessageBus.h"
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 return nullptr; 265 return nullptr;
265 } 266 }
266 267
267 return ctx->textureProvider()->createTexture(desc, true, bitmap->getPixels() , 268 return ctx->textureProvider()->createTexture(desc, true, bitmap->getPixels() ,
268 bitmap->rowBytes()); 269 bitmap->rowBytes());
269 } 270 }
270 271
271 272
272 //////////////////////////////////////////////////////////////////////////////// 273 ////////////////////////////////////////////////////////////////////////////////
273 274
274 static void install_bmp_key_invalidator(const GrUniqueKey& key, SkPixelRef* pixe lRef) { 275 void GrInstallBitmapUniqueKeyInvalidator(const GrUniqueKey& key, SkPixelRef* pix elRef) {
275 class Invalidator : public SkPixelRef::GenIDChangeListener { 276 class Invalidator : public SkPixelRef::GenIDChangeListener {
276 public: 277 public:
277 explicit Invalidator(const GrUniqueKey& key) : fMsg(key) {} 278 explicit Invalidator(const GrUniqueKey& key) : fMsg(key) {}
278 private: 279 private:
279 GrUniqueKeyInvalidatedMessage fMsg; 280 GrUniqueKeyInvalidatedMessage fMsg;
280 281
281 void onChange() override { SkMessageBus<GrUniqueKeyInvalidatedMessage>:: Post(fMsg); } 282 void onChange() override { SkMessageBus<GrUniqueKeyInvalidatedMessage>:: Post(fMsg); }
282 }; 283 };
283 284
284 pixelRef->addGenIDChangeListener(new Invalidator(key)); 285 pixelRef->addGenIDChangeListener(new Invalidator(key));
(...skipping 21 matching lines...) Expand all
306 if (fOriginalKey.isValid()) { 307 if (fOriginalKey.isValid()) {
307 tex = ctx->textureProvider()->findAndRefTextureByUniqueKey(fOriginal Key); 308 tex = ctx->textureProvider()->findAndRefTextureByUniqueKey(fOriginal Key);
308 if (tex) { 309 if (tex) {
309 return tex; 310 return tex;
310 } 311 }
311 } 312 }
312 313
313 tex = GrUploadBitmapToTexture(ctx, fBitmap); 314 tex = GrUploadBitmapToTexture(ctx, fBitmap);
314 if (tex && fOriginalKey.isValid()) { 315 if (tex && fOriginalKey.isValid()) {
315 tex->resourcePriv().setUniqueKey(fOriginalKey); 316 tex->resourcePriv().setUniqueKey(fOriginalKey);
316 install_bmp_key_invalidator(fOriginalKey, fBitmap.pixelRef()); 317 GrInstallBitmapUniqueKeyInvalidator(fOriginalKey, fBitmap.pixelRef() );
317 } 318 }
318 return tex; 319 return tex;
319 } 320 }
320 321
321 void makeCopyKey(const CopyParams& copyParams, GrUniqueKey* copyKey) overrid e { 322 void makeCopyKey(const CopyParams& copyParams, GrUniqueKey* copyKey) overrid e {
322 if (fOriginalKey.isValid()) { 323 if (fOriginalKey.isValid()) {
323 MakeCopyKeyFromOrigKey(fOriginalKey, copyParams, copyKey); 324 MakeCopyKeyFromOrigKey(fOriginalKey, copyParams, copyKey);
324 } 325 }
325 } 326 }
326 327
327 void didCacheCopy(const GrUniqueKey& copyKey) override { 328 void didCacheCopy(const GrUniqueKey& copyKey) override {
328 install_bmp_key_invalidator(copyKey, fBitmap.pixelRef()); 329 GrInstallBitmapUniqueKeyInvalidator(copyKey, fBitmap.pixelRef());
329 } 330 }
330 331
331 private: 332 private:
332 const SkBitmap fBitmap; 333 const SkBitmap fBitmap;
333 GrUniqueKey fOriginalKey; 334 GrUniqueKey fOriginalKey;
334 335
335 typedef GrTextureMaker INHERITED; 336 typedef GrTextureMaker INHERITED;
336 }; 337 };
337 338
338 class TextureBitmap_GrTextureAdjuster : public GrTextureAdjuster {
339 public:
340 explicit TextureBitmap_GrTextureAdjuster(const SkBitmap* bmp)
341 : INHERITED(bmp->getTexture(), SkIRect::MakeWH(bmp->width(), bmp->height ()))
342 , fBmp(bmp) {}
343
344 private:
345 void makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey) override {
346 if (fBmp->isVolatile()) {
347 return;
348 }
349 // The content area must represent the whole bitmap. Texture-backed bitm aps don't support
350 // extractSubset(). Therefore, either the bitmap and the texture are the same size or the
351 // content's dimensions are the bitmap's dimensions which is pinned to t he upper left
352 // of the texture.
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;
366 };
367
368 GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, const SkBitmap& bitmap, 339 GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, const SkBitmap& bitmap,
369 const GrTextureParams& params) { 340 const GrTextureParams& params) {
370 if (bitmap.getTexture()) { 341 if (bitmap.getTexture()) {
371 return TextureBitmap_GrTextureAdjuster(&bitmap).refTextureSafeForParams( params, nullptr); 342 return GrBitmapTextureAdjuster(&bitmap).refTextureSafeForParams(params, nullptr);
372 } 343 }
373 return RasterBitmap_GrTextureMaker(bitmap).refTextureForParams(ctx, params); 344 return RasterBitmap_GrTextureMaker(bitmap).refTextureForParams(ctx, params);
374 } 345 }
375 346
376 /////////////////////////////////////////////////////////////////////////////// 347 ///////////////////////////////////////////////////////////////////////////////
377 348
378 // alphatype is ignore for now, but if GrPixelConfig is expanded to encompass 349 // alphatype is ignore for now, but if GrPixelConfig is expanded to encompass
379 // alpha info, that will be considered. 350 // alpha info, that will be considered.
380 GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType ct, SkAlphaType, SkColorProf ileType pt) { 351 GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType ct, SkAlphaType, SkColorProf ileType pt) {
381 switch (ct) { 352 switch (ct) {
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 SkErrorInternals::SetError( kInvalidPaint_SkError, 655 SkErrorInternals::SetError( kInvalidPaint_SkError,
685 "Sorry, I don't understand the filtering " 656 "Sorry, I don't understand the filtering "
686 "mode you asked for. Falling back to " 657 "mode you asked for. Falling back to "
687 "MIPMaps."); 658 "MIPMaps.");
688 textureFilterMode = GrTextureParams::kMipMap_FilterMode; 659 textureFilterMode = GrTextureParams::kMipMap_FilterMode;
689 break; 660 break;
690 661
691 } 662 }
692 return textureFilterMode; 663 return textureFilterMode;
693 } 664 }
OLDNEW
« no previous file with comments | « src/gpu/SkGpuDevice_drawTexture.cpp ('k') | src/gpu/SkGrPriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698