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

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

Issue 1142053004: Empty picture shaders should draw nothing. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: sort Created 5 years, 7 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') | tests/PictureShaderTest.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 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 , fPicture(SkRef(picture)) 107 , fPicture(SkRef(picture))
108 , fTile(tile ? *tile : picture->cullRect()) 108 , fTile(tile ? *tile : picture->cullRect())
109 , fTmx(tmx) 109 , fTmx(tmx)
110 , fTmy(tmy) { 110 , fTmy(tmy) {
111 } 111 }
112 112
113 SkPictureShader::~SkPictureShader() { 113 SkPictureShader::~SkPictureShader() {
114 fPicture->unref(); 114 fPicture->unref();
115 } 115 }
116 116
117 SkPictureShader* SkPictureShader::Create(const SkPicture* picture, TileMode tmx, TileMode tmy, 117 SkShader* SkPictureShader::Create(const SkPicture* picture, TileMode tmx, TileMo de tmy,
118 const SkMatrix* localMatrix, const SkRe ct* tile) { 118 const SkMatrix* localMatrix, const SkRe ct* tile) {
119 if (!picture || picture->cullRect().isEmpty() || (tile && tile->isEmpty())) { 119 if (!picture || picture->cullRect().isEmpty() || (tile && tile->isEmpty())) {
120 return NULL; 120 return SkShader::CreateEmptyShader();
121 } 121 }
122 return SkNEW_ARGS(SkPictureShader, (picture, tmx, tmy, localMatrix, tile)); 122 return SkNEW_ARGS(SkPictureShader, (picture, tmx, tmy, localMatrix, tile));
123 } 123 }
124 124
125 SkFlattenable* SkPictureShader::CreateProc(SkReadBuffer& buffer) { 125 SkFlattenable* SkPictureShader::CreateProc(SkReadBuffer& buffer) {
126 SkMatrix lm; 126 SkMatrix lm;
127 buffer.readMatrix(&lm); 127 buffer.readMatrix(&lm);
128 TileMode mx = (TileMode)buffer.read32(); 128 TileMode mx = (TileMode)buffer.read32();
129 TileMode my = (TileMode)buffer.read32(); 129 TileMode my = (TileMode)buffer.read32();
130 SkRect tile; 130 SkRect tile;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 if (scaledSize.width() > maxTextureSize || scaledSize.height() > maxText ureSize) { 178 if (scaledSize.width() > maxTextureSize || scaledSize.height() > maxText ureSize) {
179 SkScalar downScale = maxTextureSize / SkMax32(scaledSize.width(), sc aledSize.height()); 179 SkScalar downScale = maxTextureSize / SkMax32(scaledSize.width(), sc aledSize.height());
180 scaledSize.set(SkScalarFloorToScalar(SkScalarMul(scaledSize.width(), downScale)), 180 scaledSize.set(SkScalarFloorToScalar(SkScalarMul(scaledSize.width(), downScale)),
181 SkScalarFloorToScalar(SkScalarMul(scaledSize.height() , downScale))); 181 SkScalarFloorToScalar(SkScalarMul(scaledSize.height() , downScale)));
182 } 182 }
183 } 183 }
184 #endif 184 #endif
185 185
186 SkISize tileSize = scaledSize.toRound(); 186 SkISize tileSize = scaledSize.toRound();
187 if (tileSize.isEmpty()) { 187 if (tileSize.isEmpty()) {
188 return NULL; 188 return SkShader::CreateEmptyShader();
189 } 189 }
190 190
191 // The actual scale, compensating for rounding & clamping. 191 // The actual scale, compensating for rounding & clamping.
192 SkSize tileScale = SkSize::Make(SkIntToScalar(tileSize.width()) / fTile.widt h(), 192 SkSize tileScale = SkSize::Make(SkIntToScalar(tileSize.width()) / fTile.widt h(),
193 SkIntToScalar(tileSize.height()) / fTile.hei ght()); 193 SkIntToScalar(tileSize.height()) / fTile.hei ght());
194 194
195 SkAutoTUnref<SkShader> tileShader; 195 SkAutoTUnref<SkShader> tileShader;
196 BitmapShaderKey key(fPicture->uniqueID(), 196 BitmapShaderKey key(fPicture->uniqueID(),
197 fTile, 197 fTile,
198 fTmx, 198 fTmx,
199 fTmy, 199 fTmy,
200 tileScale, 200 tileScale,
201 this->getLocalMatrix()); 201 this->getLocalMatrix());
202 202
203 if (!SkResourceCache::Find(key, BitmapShaderRec::Visitor, &tileShader)) { 203 if (!SkResourceCache::Find(key, BitmapShaderRec::Visitor, &tileShader)) {
204 SkBitmap bm; 204 SkBitmap bm;
205 bm.setInfo(SkImageInfo::MakeN32Premul(tileSize)); 205 bm.setInfo(SkImageInfo::MakeN32Premul(tileSize));
206 if (!cache_try_alloc_pixels(&bm)) { 206 if (!cache_try_alloc_pixels(&bm)) {
207 return NULL; 207 return SkShader::CreateEmptyShader();
208 } 208 }
209 bm.eraseColor(SK_ColorTRANSPARENT); 209 bm.eraseColor(SK_ColorTRANSPARENT);
210 210
211 // Always disable LCD text, since we can't assume our image will be opaq ue. 211 // Always disable LCD text, since we can't assume our image will be opaq ue.
212 SkCanvas canvas(bm, SkSurfaceProps(0, kUnknown_SkPixelGeometry)); 212 SkCanvas canvas(bm, SkSurfaceProps(0, kUnknown_SkPixelGeometry));
213 213
214 canvas.scale(tileScale.width(), tileScale.height()); 214 canvas.scale(tileScale.width(), tileScale.height());
215 canvas.translate(-fTile.x(), -fTile.y()); 215 canvas.translate(-fTile.x(), -fTile.y());
216 canvas.drawPicture(fPicture); 216 canvas.drawPicture(fPicture);
217 217
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 return bitmapShader->asFragmentProcessor(context, paint, viewM, NULL, paintC olor, fp); 321 return bitmapShader->asFragmentProcessor(context, paint, viewM, NULL, paintC olor, fp);
322 } 322 }
323 #else 323 #else
324 bool SkPictureShader::asFragmentProcessor(GrContext*, const SkPaint&, const SkMa trix&, 324 bool SkPictureShader::asFragmentProcessor(GrContext*, const SkPaint&, const SkMa trix&,
325 const SkMatrix*, GrColor*, 325 const SkMatrix*, GrColor*,
326 GrFragmentProcessor**) const { 326 GrFragmentProcessor**) const {
327 SkDEBUGFAIL("Should not call in GPU-less build"); 327 SkDEBUGFAIL("Should not call in GPU-less build");
328 return false; 328 return false;
329 } 329 }
330 #endif 330 #endif
OLDNEW
« no previous file with comments | « src/core/SkPictureShader.h ('k') | tests/PictureShaderTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698