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

Side by Side Diff: src/core/SkPictureShader.cpp

Issue 387043002: No need to cache local matrix in picture shader. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 5 months 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/core/SkPictureShader.h ('k') | no next file » | 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 2014 Google Inc. 2 * Copyright 2014 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 "SkPictureShader.h" 8 #include "SkPictureShader.h"
9 9
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 if (tileSize.isEmpty()) { 74 if (tileSize.isEmpty()) {
75 return NULL; 75 return NULL;
76 } 76 }
77 77
78 // The actual scale, compensating for rounding. 78 // The actual scale, compensating for rounding.
79 SkSize tileScale = SkSize::Make(SkIntToScalar(tileSize.width()) / fPicture-> width(), 79 SkSize tileScale = SkSize::Make(SkIntToScalar(tileSize.width()) / fPicture-> width(),
80 SkIntToScalar(tileSize.height()) / fPicture- >height()); 80 SkIntToScalar(tileSize.height()) / fPicture- >height());
81 81
82 SkAutoMutexAcquire ama(fCachedBitmapShaderMutex); 82 SkAutoMutexAcquire ama(fCachedBitmapShaderMutex);
83 83
84 // TODO(fmalita): remove fCachedLocalMatrix from this key after getLocalMatr ix is removed. 84 if (!fCachedBitmapShader || tileScale != fCachedTileScale) {
85 if (!fCachedBitmapShader || tileScale != fCachedTileScale ||
86 this->getLocalMatrix() != fCachedLocalMatrix) {
87 SkBitmap bm; 85 SkBitmap bm;
88 if (!bm.allocN32Pixels(tileSize.width(), tileSize.height())) { 86 if (!bm.allocN32Pixels(tileSize.width(), tileSize.height())) {
89 return NULL; 87 return NULL;
90 } 88 }
91 bm.eraseColor(SK_ColorTRANSPARENT); 89 bm.eraseColor(SK_ColorTRANSPARENT);
92 90
93 SkCanvas canvas(bm); 91 SkCanvas canvas(bm);
94 canvas.scale(tileScale.width(), tileScale.height()); 92 canvas.scale(tileScale.width(), tileScale.height());
95 canvas.drawPicture(fPicture); 93 canvas.drawPicture(fPicture);
96 94
97 fCachedTileScale = tileScale; 95 fCachedTileScale = tileScale;
98 fCachedLocalMatrix = this->getLocalMatrix();
99 96
100 SkMatrix shaderMatrix = this->getLocalMatrix(); 97 SkMatrix shaderMatrix = this->getLocalMatrix();
101 shaderMatrix.preScale(1 / tileScale.width(), 1 / tileScale.height()); 98 shaderMatrix.preScale(1 / tileScale.width(), 1 / tileScale.height());
102 fCachedBitmapShader.reset(CreateBitmapShader(bm, fTmx, fTmy, &shaderMatr ix)); 99 fCachedBitmapShader.reset(CreateBitmapShader(bm, fTmx, fTmy, &shaderMatr ix));
103 } 100 }
104 101
105 // Increment the ref counter inside the mutex to ensure the returned pointer is still valid. 102 // Increment the ref counter inside the mutex to ensure the returned pointer is still valid.
106 // Otherwise, the pointer may have been overwritten on a different thread be fore the object's 103 // Otherwise, the pointer may have been overwritten on a different thread be fore the object's
107 // ref count was incremented. 104 // ref count was incremented.
108 fCachedBitmapShader.get()->ref(); 105 fCachedBitmapShader.get()->ref();
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 return bitmapShader->asNewEffect(context, paint, NULL, paintColor, effect); 195 return bitmapShader->asNewEffect(context, paint, NULL, paintColor, effect);
199 } 196 }
200 #else 197 #else
201 bool SkPictureShader::asNewEffect(GrContext* context, const SkPaint& paint, 198 bool SkPictureShader::asNewEffect(GrContext* context, const SkPaint& paint,
202 const SkMatrix* localMatrix, GrColor* paintCol or, 199 const SkMatrix* localMatrix, GrColor* paintCol or,
203 GrEffect** effect) const { 200 GrEffect** effect) const {
204 SkDEBUGFAIL("Should not call in GPU-less build"); 201 SkDEBUGFAIL("Should not call in GPU-less build");
205 return false; 202 return false;
206 } 203 }
207 #endif 204 #endif
OLDNEW
« no previous file with comments | « src/core/SkPictureShader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698