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

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

Issue 513983002: Try out scalar picture sizes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update to ToT again Created 6 years, 3 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/SkPictureRecorder.cpp ('k') | src/core/SkRecordDraw.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"
11 #include "SkBitmapProcShader.h" 11 #include "SkBitmapProcShader.h"
12 #include "SkCanvas.h" 12 #include "SkCanvas.h"
13 #include "SkMatrixUtils.h" 13 #include "SkMatrixUtils.h"
14 #include "SkPicture.h" 14 #include "SkPicture.h"
15 #include "SkReadBuffer.h" 15 #include "SkReadBuffer.h"
16 16
17 #if SK_SUPPORT_GPU 17 #if SK_SUPPORT_GPU
18 #include "GrContext.h" 18 #include "GrContext.h"
19 #endif 19 #endif
20 20
21 SkPictureShader::SkPictureShader(const SkPicture* picture, TileMode tmx, TileMod e tmy, 21 SkPictureShader::SkPictureShader(const SkPicture* picture, TileMode tmx, TileMod e tmy,
22 const SkMatrix* localMatrix, const SkRect* tile ) 22 const SkMatrix* localMatrix, const SkRect* tile )
23 : INHERITED(localMatrix) 23 : INHERITED(localMatrix)
24 , fPicture(SkRef(picture)) 24 , fPicture(SkRef(picture))
25 , fTile(NULL != tile ? *tile : picture->cullRect())
25 , fTmx(tmx) 26 , fTmx(tmx)
26 , fTmy(tmy) { 27 , fTmy(tmy) {
27 fTile = tile ? *tile : SkRect::MakeWH(SkIntToScalar(picture->width()),
28 SkIntToScalar(picture->height()));
29 } 28 }
30 29
31 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING 30 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
32 SkPictureShader::SkPictureShader(SkReadBuffer& buffer) : INHERITED(buffer) { 31 SkPictureShader::SkPictureShader(SkReadBuffer& buffer) : INHERITED(buffer) {
33 fTmx = static_cast<SkShader::TileMode>(buffer.read32()); 32 fTmx = static_cast<SkShader::TileMode>(buffer.read32());
34 fTmy = static_cast<SkShader::TileMode>(buffer.read32()); 33 fTmy = static_cast<SkShader::TileMode>(buffer.read32());
35 buffer.readRect(&fTile); 34 buffer.readRect(&fTile);
36 fPicture = SkPicture::CreateFromBuffer(buffer); 35 fPicture = SkPicture::CreateFromBuffer(buffer);
37 } 36 }
38 #endif 37 #endif
39 38
40 SkPictureShader::~SkPictureShader() { 39 SkPictureShader::~SkPictureShader() {
41 fPicture->unref(); 40 fPicture->unref();
42 } 41 }
43 42
44 SkPictureShader* SkPictureShader::Create(const SkPicture* picture, TileMode tmx, TileMode tmy, 43 SkPictureShader* SkPictureShader::Create(const SkPicture* picture, TileMode tmx, TileMode tmy,
45 const SkMatrix* localMatrix, const SkRe ct* tile) { 44 const SkMatrix* localMatrix, const SkRe ct* tile) {
46 if (!picture || 0 == picture->width() || 0 == picture->height() 45 if (!picture || picture->cullRect().isEmpty() || (NULL != tile && tile->isEm pty())) {
47 || (NULL != tile && tile->isEmpty())) {
48 return NULL; 46 return NULL;
49 } 47 }
50 return SkNEW_ARGS(SkPictureShader, (picture, tmx, tmy, localMatrix, tile)); 48 return SkNEW_ARGS(SkPictureShader, (picture, tmx, tmy, localMatrix, tile));
51 } 49 }
52 50
53 SkFlattenable* SkPictureShader::CreateProc(SkReadBuffer& buffer) { 51 SkFlattenable* SkPictureShader::CreateProc(SkReadBuffer& buffer) {
54 SkMatrix lm; 52 SkMatrix lm;
55 buffer.readMatrix(&lm); 53 buffer.readMatrix(&lm);
56 TileMode mx = (TileMode)buffer.read32(); 54 TileMode mx = (TileMode)buffer.read32();
57 TileMode my = (TileMode)buffer.read32(); 55 TileMode my = (TileMode)buffer.read32();
58 SkRect tile; 56 SkRect tile;
59 buffer.readRect(&tile); 57 buffer.readRect(&tile);
60 SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromBuffer(buffer)); 58 SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromBuffer(buffer));
61 return SkPictureShader::Create(picture, mx, my, &lm, &tile); 59 return SkPictureShader::Create(picture, mx, my, &lm, &tile);
62 } 60 }
63 61
64 void SkPictureShader::flatten(SkWriteBuffer& buffer) const { 62 void SkPictureShader::flatten(SkWriteBuffer& buffer) const {
65 buffer.writeMatrix(this->getLocalMatrix()); 63 buffer.writeMatrix(this->getLocalMatrix());
66 buffer.write32(fTmx); 64 buffer.write32(fTmx);
67 buffer.write32(fTmy); 65 buffer.write32(fTmy);
68 buffer.writeRect(fTile); 66 buffer.writeRect(fTile);
69 fPicture->flatten(buffer); 67 fPicture->flatten(buffer);
70 } 68 }
71 69
72 SkShader* SkPictureShader::refBitmapShader(const SkMatrix& matrix, const SkMatri x* localM) const { 70 SkShader* SkPictureShader::refBitmapShader(const SkMatrix& matrix, const SkMatri x* localM) const {
73 SkASSERT(fPicture && fPicture->width() > 0 && fPicture->height() > 0); 71 SkASSERT(fPicture && !fPicture->cullRect().isEmpty());
74 72
75 SkMatrix m; 73 SkMatrix m;
76 m.setConcat(matrix, this->getLocalMatrix()); 74 m.setConcat(matrix, this->getLocalMatrix());
77 if (localM) { 75 if (localM) {
78 m.preConcat(*localM); 76 m.preConcat(*localM);
79 } 77 }
80 78
81 // Use a rotation-invariant scale 79 // Use a rotation-invariant scale
82 SkPoint scale; 80 SkPoint scale;
83 if (!SkDecomposeUpper2x2(m, NULL, &scale, NULL)) { 81 if (!SkDecomposeUpper2x2(m, NULL, &scale, NULL)) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 SkASSERT(fBitmapShaderContext); 192 SkASSERT(fBitmapShaderContext);
195 fBitmapShaderContext->shadeSpan16(x, y, dstC, count); 193 fBitmapShaderContext->shadeSpan16(x, y, dstC, count);
196 } 194 }
197 195
198 #ifndef SK_IGNORE_TO_STRING 196 #ifndef SK_IGNORE_TO_STRING
199 void SkPictureShader::toString(SkString* str) const { 197 void SkPictureShader::toString(SkString* str) const {
200 static const char* gTileModeName[SkShader::kTileModeCount] = { 198 static const char* gTileModeName[SkShader::kTileModeCount] = {
201 "clamp", "repeat", "mirror" 199 "clamp", "repeat", "mirror"
202 }; 200 };
203 201
204 str->appendf("PictureShader: [%d:%d] ", 202 str->appendf("PictureShader: [%f:%f:%f:%f] ",
205 fPicture ? fPicture->width() : 0, 203 fPicture ? fPicture->cullRect().fLeft : 0,
206 fPicture ? fPicture->height() : 0); 204 fPicture ? fPicture->cullRect().fTop : 0,
205 fPicture ? fPicture->cullRect().fRight : 0,
206 fPicture ? fPicture->cullRect().fBottom : 0);
207 207
208 str->appendf("(%s, %s)", gTileModeName[fTmx], gTileModeName[fTmy]); 208 str->appendf("(%s, %s)", gTileModeName[fTmx], gTileModeName[fTmy]);
209 209
210 this->INHERITED::toString(str); 210 this->INHERITED::toString(str);
211 } 211 }
212 #endif 212 #endif
213 213
214 #if SK_SUPPORT_GPU 214 #if SK_SUPPORT_GPU
215 bool SkPictureShader::asNewEffect(GrContext* context, const SkPaint& paint, 215 bool SkPictureShader::asNewEffect(GrContext* context, const SkPaint& paint,
216 const SkMatrix* localMatrix, GrColor* paintCol or, 216 const SkMatrix* localMatrix, GrColor* paintCol or,
217 GrEffect** effect) const { 217 GrEffect** effect) const {
218 SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(context->getMatrix (), localMatrix)); 218 SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(context->getMatrix (), localMatrix));
219 if (!bitmapShader) { 219 if (!bitmapShader) {
220 return false; 220 return false;
221 } 221 }
222 return bitmapShader->asNewEffect(context, paint, NULL, paintColor, effect); 222 return bitmapShader->asNewEffect(context, paint, NULL, paintColor, effect);
223 } 223 }
224 #else 224 #else
225 bool SkPictureShader::asNewEffect(GrContext* context, const SkPaint& paint, 225 bool SkPictureShader::asNewEffect(GrContext* context, const SkPaint& paint,
226 const SkMatrix* localMatrix, GrColor* paintCol or, 226 const SkMatrix* localMatrix, GrColor* paintCol or,
227 GrEffect** effect) const { 227 GrEffect** effect) const {
228 SkDEBUGFAIL("Should not call in GPU-less build"); 228 SkDEBUGFAIL("Should not call in GPU-less build");
229 return false; 229 return false;
230 } 230 }
231 #endif 231 #endif
OLDNEW
« no previous file with comments | « src/core/SkPictureRecorder.cpp ('k') | src/core/SkRecordDraw.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698