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

Side by Side Diff: gm/pictureshadertile.cpp

Issue 1789633002: more shader-->sp conversions (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 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/pictureshader.cpp ('k') | gm/rectangletexture.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 "gm.h" 8 #include "gm.h"
9 9
10 #include "SkPaint.h" 10 #include "SkPaint.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 88 }
89 89
90 SkISize onISize() override { 90 SkISize onISize() override {
91 return SkISize::Make(800, 600); 91 return SkISize::Make(800, 600);
92 } 92 }
93 93
94 void onOnceBeforeDraw() override { 94 void onOnceBeforeDraw() override {
95 SkPictureRecorder recorder; 95 SkPictureRecorder recorder;
96 SkCanvas* pictureCanvas = recorder.beginRecording(kPictureSize, kPicture Size); 96 SkCanvas* pictureCanvas = recorder.beginRecording(kPictureSize, kPicture Size);
97 draw_scene(pictureCanvas, kPictureSize); 97 draw_scene(pictureCanvas, kPictureSize);
98 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 98 sk_sp<SkPicture> picture(recorder.endRecording());
99 99
100 SkPoint offset = SkPoint::Make(100, 100); 100 SkPoint offset = SkPoint::Make(100, 100);
101 pictureCanvas = recorder.beginRecording(SkRect::MakeXYWH(offset.x(), off set.y(), 101 pictureCanvas = recorder.beginRecording(SkRect::MakeXYWH(offset.x(), off set.y(),
102 kPictureSize, k PictureSize)); 102 kPictureSize, k PictureSize));
103 pictureCanvas->translate(offset.x(), offset.y()); 103 pictureCanvas->translate(offset.x(), offset.y());
104 draw_scene(pictureCanvas, kPictureSize); 104 draw_scene(pictureCanvas, kPictureSize);
105 SkAutoTUnref<SkPicture> offsetPicture(recorder.endRecording()); 105 sk_sp<SkPicture> offsetPicture(recorder.endRecording());
106 106
107 for (unsigned i = 0; i < SK_ARRAY_COUNT(tiles); ++i) { 107 for (unsigned i = 0; i < SK_ARRAY_COUNT(tiles); ++i) {
108 SkRect tile = SkRect::MakeXYWH(tiles[i].x * kPictureSize, 108 SkRect tile = SkRect::MakeXYWH(tiles[i].x * kPictureSize,
109 tiles[i].y * kPictureSize, 109 tiles[i].y * kPictureSize,
110 tiles[i].w * kPictureSize, 110 tiles[i].w * kPictureSize,
111 tiles[i].h * kPictureSize); 111 tiles[i].h * kPictureSize);
112 SkMatrix localMatrix; 112 SkMatrix localMatrix;
113 localMatrix.setTranslate(tiles[i].offsetX * kPictureSize, 113 localMatrix.setTranslate(tiles[i].offsetX * kPictureSize,
114 tiles[i].offsetY * kPictureSize); 114 tiles[i].offsetY * kPictureSize);
115 localMatrix.postScale(kFillSize / (2 * kPictureSize), 115 localMatrix.postScale(kFillSize / (2 * kPictureSize),
116 kFillSize / (2 * kPictureSize)); 116 kFillSize / (2 * kPictureSize));
117 117
118 SkPicture* picturePtr = picture.get(); 118 sk_sp<SkPicture>& pictureRef = picture;
119 SkRect* tilePtr = &tile; 119 SkRect* tilePtr = &tile;
120 120
121 if (tile == SkRect::MakeWH(kPictureSize, kPictureSize)) { 121 if (tile == SkRect::MakeWH(kPictureSize, kPictureSize)) {
122 // When the tile == picture bounds, exercise the picture + offse t path. 122 // When the tile == picture bounds, exercise the picture + offse t path.
123 picturePtr = offsetPicture.get(); 123 pictureRef = offsetPicture;
f(malita) 2016/03/13 20:25:50 Heh, yeah, this is assigning offsetPicture -> pict
124 tilePtr = nullptr; 124 tilePtr = nullptr;
125 } 125 }
126 126
127 fShaders[i].reset(SkShader::CreatePictureShader(picturePtr, 127 fShaders[i] = SkShader::MakePictureShader(pictureRef, SkShader::kRep eat_TileMode,
128 SkShader::kRepeat_Ti leMode, 128 SkShader::kRepeat_TileMode , &localMatrix,
129 SkShader::kRepeat_Ti leMode, 129 tilePtr);
130 &localMatrix,
131 tilePtr));
132 } 130 }
133 } 131 }
134 132
135 void onDraw(SkCanvas* canvas) override { 133 void onDraw(SkCanvas* canvas) override {
136 canvas->clear(SK_ColorBLACK); 134 canvas->clear(SK_ColorBLACK);
137 135
138 SkPaint paint; 136 SkPaint paint;
139 paint.setStyle(SkPaint::kFill_Style); 137 paint.setStyle(SkPaint::kFill_Style);
140 138
141 for (unsigned i = 0; i < SK_ARRAY_COUNT(fShaders); ++i) { 139 for (unsigned i = 0; i < SK_ARRAY_COUNT(fShaders); ++i) {
142 paint.setShader(fShaders[i]); 140 paint.setShader(fShaders[i]);
143 141
144 canvas->save(); 142 canvas->save();
145 canvas->translate((i % kRowSize) * kFillSize * 1.1f, 143 canvas->translate((i % kRowSize) * kFillSize * 1.1f,
146 (i / kRowSize) * kFillSize * 1.1f); 144 (i / kRowSize) * kFillSize * 1.1f);
147 canvas->drawRect(SkRect::MakeWH(kFillSize, kFillSize), paint); 145 canvas->drawRect(SkRect::MakeWH(kFillSize, kFillSize), paint);
148 canvas->restore(); 146 canvas->restore();
149 } 147 }
150 } 148 }
151 149
152 private: 150 private:
153 SkAutoTUnref<SkShader> fShaders[SK_ARRAY_COUNT(tiles)]; 151 sk_sp<SkShader> fShaders[SK_ARRAY_COUNT(tiles)];
154 152
155 typedef GM INHERITED; 153 typedef GM INHERITED;
156 }; 154 };
157 155
158 DEF_GM(return new PictureShaderTileGM;) 156 DEF_GM(return new PictureShaderTileGM;)
OLDNEW
« no previous file with comments | « gm/pictureshader.cpp ('k') | gm/rectangletexture.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698