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

Side by Side Diff: gm/bitmapshader.cpp

Issue 245963010: Move SkShader::fLocalMatrix into SkShader constructor. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: nit Created 6 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 | « gm/bigmatrix.cpp ('k') | gm/clippedbitmapshaders.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 /* 2 /*
3 * Copyright 2013 Google Inc. 3 * Copyright 2013 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "gm.h" 8 #include "gm.h"
9 9
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 17 matching lines...) Expand all
28 SkPaint circlePaint; 28 SkPaint circlePaint;
29 circlePaint.setColor(SK_ColorBLACK); 29 circlePaint.setColor(SK_ColorBLACK);
30 30
31 bm->allocPixels(SkImageInfo::MakeA8(20, 20)); 31 bm->allocPixels(SkImageInfo::MakeA8(20, 20));
32 bm->eraseColor(SK_ColorTRANSPARENT); 32 bm->eraseColor(SK_ColorTRANSPARENT);
33 33
34 SkCanvas canvas(*bm); 34 SkCanvas canvas(*bm);
35 canvas.drawCircle(10, 10, 10, circlePaint); 35 canvas.drawCircle(10, 10, 10, circlePaint);
36 } 36 }
37 37
38 static void adopt_shader(SkPaint* paint, SkShader* shader, SkMatrix s) { 38 static void adopt_shader(SkPaint* paint, SkShader* shader) {
39 shader->setLocalMatrix(s);
40 paint->setShader(shader); 39 paint->setShader(shader);
41 SkSafeUnref(shader); 40 SkSafeUnref(shader);
42 } 41 }
43 42
44 class BitmapShaderGM : public GM { 43 class BitmapShaderGM : public GM {
45 public: 44 public:
46 45
47 BitmapShaderGM() { 46 BitmapShaderGM() {
48 this->setBGColor(SK_ColorGRAY); 47 this->setBGColor(SK_ColorGRAY);
49 draw_bm(&fBitmap); 48 draw_bm(&fBitmap);
(...skipping 15 matching lines...) Expand all
65 for (int i = 0; i < 2; i++) { 64 for (int i = 0; i < 2; i++) {
66 SkMatrix s; 65 SkMatrix s;
67 s.reset(); 66 s.reset();
68 if (1 == i) { 67 if (1 == i) {
69 s.setScale(1.5f, 1.5f); 68 s.setScale(1.5f, 1.5f);
70 s.postTranslate(2, 2); 69 s.postTranslate(2, 2);
71 } 70 }
72 71
73 canvas->save(); 72 canvas->save();
74 adopt_shader(&paint, SkShader::CreateBitmapShader(fBitmap, SkShader: :kClamp_TileMode, 73 adopt_shader(&paint, SkShader::CreateBitmapShader(fBitmap, SkShader: :kClamp_TileMode,
75 SkShader::kClamp_T ileMode), s); 74 SkShader::kClamp_T ileMode, &s));
76 75
77 // draw the shader with a bitmap mask 76 // draw the shader with a bitmap mask
78 canvas->drawBitmap(fMask, 0, 0, &paint); 77 canvas->drawBitmap(fMask, 0, 0, &paint);
79 canvas->drawBitmap(fMask, 30, 0, &paint); 78 canvas->drawBitmap(fMask, 30, 0, &paint);
80 79
81 canvas->translate(0, 25); 80 canvas->translate(0, 25);
82 81
83 canvas->drawCircle(10, 10, 10, paint); 82 canvas->drawCircle(10, 10, 10, paint);
84 canvas->drawCircle(40, 10, 10, paint); // no blue circle expected 83 canvas->drawCircle(40, 10, 10, paint); // no blue circle expected
85 84
86 canvas->translate(0, 25); 85 canvas->translate(0, 25);
87 86
88 // clear the shader, colorized by a solid color with a bitmap mask 87 // clear the shader, colorized by a solid color with a bitmap mask
89 paint.setShader(NULL); 88 paint.setShader(NULL);
90 paint.setColor(SK_ColorGREEN); 89 paint.setColor(SK_ColorGREEN);
91 canvas->drawBitmap(fMask, 0, 0, &paint); 90 canvas->drawBitmap(fMask, 0, 0, &paint);
92 canvas->drawBitmap(fMask, 30, 0, &paint); 91 canvas->drawBitmap(fMask, 30, 0, &paint);
93 92
94 canvas->translate(0, 25); 93 canvas->translate(0, 25);
95 94
96 adopt_shader(&paint, SkShader::CreateBitmapShader(fMask, SkShader::k Repeat_TileMode, 95 adopt_shader(&paint, SkShader::CreateBitmapShader(fMask, SkShader::k Repeat_TileMode,
97 SkShader::kRepeat_ TileMode), s); 96 SkShader::kRepeat_ TileMode, &s));
98 paint.setColor(SK_ColorRED); 97 paint.setColor(SK_ColorRED);
99 98
100 // draw the mask using the shader and a color 99 // draw the mask using the shader and a color
101 canvas->drawRect(SkRect::MakeXYWH(0, 0, 20, 20), paint); 100 canvas->drawRect(SkRect::MakeXYWH(0, 0, 20, 20), paint);
102 canvas->drawRect(SkRect::MakeXYWH(30, 0, 20, 20), paint); 101 canvas->drawRect(SkRect::MakeXYWH(30, 0, 20, 20), paint);
103 canvas->restore(); 102 canvas->restore();
104 canvas->translate(60, 0); 103 canvas->translate(60, 0);
105 } 104 }
106 } 105 }
107 106
108 private: 107 private:
109 SkBitmap fBitmap; 108 SkBitmap fBitmap;
110 SkBitmap fMask; 109 SkBitmap fMask;
111 110
112 typedef GM INHERITED; 111 typedef GM INHERITED;
113 }; 112 };
114 113
115 ////////////////////////////////////////////////////////////////////////////// 114 //////////////////////////////////////////////////////////////////////////////
116 115
117 static GM* MyFactory(void*) { return new BitmapShaderGM; } 116 static GM* MyFactory(void*) { return new BitmapShaderGM; }
118 static GMRegistry reg(MyFactory); 117 static GMRegistry reg(MyFactory);
119 118
120 } 119 }
OLDNEW
« no previous file with comments | « gm/bigmatrix.cpp ('k') | gm/clippedbitmapshaders.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698