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

Side by Side Diff: gm/pictureshadertile.cpp

Issue 784053002: Cleanup GM:pictureshadertile (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Created 6 years 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 | « no previous file | 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 "gm.h" 8 #include "gm.h"
9 9
10 #include "SkPaint.h" 10 #include "SkPaint.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 50
51 { 0, 0, 1, 1.5f, 0, 0 }, 51 { 0, 0, 1, 1.5f, 0, 0 },
52 { -0.5f, -0.5f, 1, 1.5f, 0, 0 }, 52 { -0.5f, -0.5f, 1, 1.5f, 0, 0 },
53 { 0.5f, 0.5f, 1, 1.5f, 0, 0 }, 53 { 0.5f, 0.5f, 1, 1.5f, 0, 0 },
54 54
55 { 0, 0, 1, 0.5f, 0, 0 }, 55 { 0, 0, 1, 0.5f, 0, 0 },
56 { 0.25f, 0.25f, 1, 0.5f, 0, 0 }, 56 { 0.25f, 0.25f, 1, 0.5f, 0, 0 },
57 { -0.25f, -0.25f, 1, 0.5f, 0, 0 }, 57 { -0.25f, -0.25f, 1, 0.5f, 0, 0 },
58 }; 58 };
59 59
60 static void draw_scene(SkCanvas* canvas, SkScalar pictureSize) {
61 canvas->clear(SK_ColorWHITE);
62
63 SkPaint paint;
64 paint.setColor(SK_ColorGREEN);
65 paint.setStyle(SkPaint::kFill_Style);
66 paint.setAntiAlias(true);
67
68 canvas->drawCircle(pictureSize / 4, pictureSize / 4, pictureSize / 4, paint) ;
69 canvas->drawRect(SkRect::MakeXYWH(pictureSize / 2, pictureSize / 2,
70 pictureSize / 2, pictureSize / 2), paint);
71
72 paint.setColor(SK_ColorRED);
73 canvas->drawLine(pictureSize / 2, pictureSize * 1 / 3,
74 pictureSize / 2, pictureSize * 2 / 3, paint);
75 canvas->drawLine(pictureSize * 1 / 3, pictureSize / 2,
76 pictureSize * 2 / 3, pictureSize / 2, paint);
77
78 paint.setColor(SK_ColorBLACK);
79 paint.setStyle(SkPaint::kStroke_Style);
80 canvas->drawRect(SkRect::MakeWH(pictureSize, pictureSize), paint);
81 }
82
60 class PictureShaderTileGM : public skiagm::GM { 83 class PictureShaderTileGM : public skiagm::GM {
61 protected: 84 protected:
62 virtual uint32_t onGetFlags() const SK_OVERRIDE { 85 uint32_t onGetFlags() const SK_OVERRIDE {
63 return kSkipTiled_Flag; 86 return kSkipTiled_Flag;
64 } 87 }
65 88
66 virtual SkString onShortName() SK_OVERRIDE { 89 SkString onShortName() SK_OVERRIDE {
67 return SkString("pictureshadertile"); 90 return SkString("pictureshadertile");
68 } 91 }
69 92
70 virtual SkISize onISize() SK_OVERRIDE { 93 SkISize onISize() SK_OVERRIDE {
71 return SkISize::Make(800, 600); 94 return SkISize::Make(800, 600);
72 } 95 }
73 96
74 virtual void onOnceBeforeDraw() SK_OVERRIDE { 97 void onOnceBeforeDraw() SK_OVERRIDE {
75 SkPictureRecorder recorder; 98 SkPictureRecorder recorder;
76 SkCanvas* pictureCanvas = recorder.beginRecording(kPictureSize, kPicture Size); 99 SkCanvas* pictureCanvas = recorder.beginRecording(kPictureSize, kPicture Size);
77 drawScene(pictureCanvas, kPictureSize); 100 draw_scene(pictureCanvas, kPictureSize);
78 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 101 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
79 102
80 SkPoint offset = SkPoint::Make(100, 100); 103 SkPoint offset = SkPoint::Make(100, 100);
81 pictureCanvas = recorder.beginRecording(SkRect::MakeXYWH(offset.x(), off set.y(), 104 pictureCanvas = recorder.beginRecording(SkRect::MakeXYWH(offset.x(), off set.y(),
82 kPictureSize, k PictureSize)); 105 kPictureSize, k PictureSize));
83 pictureCanvas->translate(offset.x(), offset.y()); 106 pictureCanvas->translate(offset.x(), offset.y());
84 drawScene(pictureCanvas, kPictureSize); 107 draw_scene(pictureCanvas, kPictureSize);
85 SkAutoTUnref<SkPicture> offsetPicture(recorder.endRecording()); 108 SkAutoTUnref<SkPicture> offsetPicture(recorder.endRecording());
86 109
87 for (unsigned i = 0; i < SK_ARRAY_COUNT(tiles); ++i) { 110 for (unsigned i = 0; i < SK_ARRAY_COUNT(tiles); ++i) {
88 SkRect tile = SkRect::MakeXYWH(tiles[i].x * kPictureSize, 111 SkRect tile = SkRect::MakeXYWH(tiles[i].x * kPictureSize,
89 tiles[i].y * kPictureSize, 112 tiles[i].y * kPictureSize,
90 tiles[i].w * kPictureSize, 113 tiles[i].w * kPictureSize,
91 tiles[i].h * kPictureSize); 114 tiles[i].h * kPictureSize);
92 SkMatrix localMatrix; 115 SkMatrix localMatrix;
93 localMatrix.setTranslate(tiles[i].offsetX * kPictureSize, 116 localMatrix.setTranslate(tiles[i].offsetX * kPictureSize,
94 tiles[i].offsetY * kPictureSize); 117 tiles[i].offsetY * kPictureSize);
95 localMatrix.postScale(kFillSize / (2 * kPictureSize), 118 localMatrix.postScale(kFillSize / (2 * kPictureSize),
96 kFillSize / (2 * kPictureSize)); 119 kFillSize / (2 * kPictureSize));
97 120
98 SkPicture* picturePtr = picture.get(); 121 SkPicture* picturePtr = picture.get();
99 SkRect* tilePtr = &tile; 122 SkRect* tilePtr = &tile;
100 123
101 if (tile == SkRect::MakeWH(kPictureSize, kPictureSize)) { 124 if (tile == SkRect::MakeWH(kPictureSize, kPictureSize)) {
102 // When the tile == picture bounds, exercise the picture + offse t path. 125 // When the tile == picture bounds, exercise the picture + offse t path.
103 picturePtr = offsetPicture.get(); 126 picturePtr = offsetPicture.get();
104 tilePtr = NULL; 127 tilePtr = NULL;
105 } 128 }
106 129
107 fShaders[i].reset(SkShader::CreatePictureShader(picturePtr, 130 fShaders[i].reset(SkShader::CreatePictureShader(picturePtr,
108 SkShader::kRepeat_TileMode, 131 SkShader::kRepeat_Ti leMode,
109 SkShader::kRepeat_TileMode, 132 SkShader::kRepeat_Ti leMode,
110 &localMatrix, 133 &localMatrix,
111 tilePtr)); 134 tilePtr));
112 } 135 }
113 } 136 }
114 137
115 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { 138 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
116 canvas->clear(SK_ColorBLACK); 139 canvas->clear(SK_ColorBLACK);
117 140
118 SkPaint paint; 141 SkPaint paint;
119 paint.setStyle(SkPaint::kFill_Style); 142 paint.setStyle(SkPaint::kFill_Style);
120 143
121 for (unsigned i = 0; i < SK_ARRAY_COUNT(fShaders); ++i) { 144 for (unsigned i = 0; i < SK_ARRAY_COUNT(fShaders); ++i) {
122 paint.setShader(fShaders[i]); 145 paint.setShader(fShaders[i]);
123 146
124 canvas->save(); 147 canvas->save();
125 canvas->translate((i % kRowSize) * kFillSize * 1.1f, 148 canvas->translate((i % kRowSize) * kFillSize * 1.1f,
126 (i / kRowSize) * kFillSize * 1.1f); 149 (i / kRowSize) * kFillSize * 1.1f);
127 canvas->drawRect(SkRect::MakeWH(kFillSize, kFillSize), paint); 150 canvas->drawRect(SkRect::MakeWH(kFillSize, kFillSize), paint);
128 canvas->restore(); 151 canvas->restore();
129 } 152 }
130 } 153 }
131 154
132 private: 155 private:
133 void drawScene(SkCanvas* canvas, SkScalar pictureSize) {
134 canvas->clear(SK_ColorWHITE);
135
136 SkPaint paint;
137 paint.setColor(SK_ColorGREEN);
138 paint.setStyle(SkPaint::kFill_Style);
139 paint.setAntiAlias(true);
140
141 canvas->drawCircle(pictureSize / 4, pictureSize / 4, pictureSize / 4, pa int);
142 canvas->drawRect(SkRect::MakeXYWH(pictureSize / 2, pictureSize / 2,
143 pictureSize / 2, pictureSize / 2), pai nt);
144
145 paint.setColor(SK_ColorRED);
146 canvas->drawLine(pictureSize / 2, pictureSize * 1 / 3,
147 pictureSize / 2, pictureSize * 2 / 3, paint);
148 canvas->drawLine(pictureSize * 1 / 3, pictureSize / 2,
149 pictureSize * 2 / 3, pictureSize / 2, paint);
150
151 paint.setColor(SK_ColorBLACK);
152 paint.setStyle(SkPaint::kStroke_Style);
153 canvas->drawRect(SkRect::MakeWH(pictureSize, pictureSize), paint);
154 }
155
156 SkAutoTUnref<SkShader> fShaders[SK_ARRAY_COUNT(tiles)]; 156 SkAutoTUnref<SkShader> fShaders[SK_ARRAY_COUNT(tiles)];
157 157
158 typedef GM INHERITED; 158 typedef GM INHERITED;
159 }; 159 };
160 160
161 DEF_GM( return SkNEW(PictureShaderTileGM); ) 161 DEF_GM( return SkNEW(PictureShaderTileGM); )
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698