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

Side by Side Diff: gm/rectangletexture.cpp

Issue 1810813003: update callsites for Make image factories (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: start to take advantage of sk_sp drawImage 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/perspshaders.cpp ('k') | gm/repeated_bitmap.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 2016 Google Inc. 3 * Copyright 2016 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 8
9 // This test only works with the GPU backend. 9 // This test only works with the GPU backend.
10 10
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 canvas.drawPaint(paint); 47 canvas.drawPaint(paint);
48 48
49 SkColor colors1[] = { 0xFFA07010 , 0xFFA02080 }; 49 SkColor colors1[] = { 0xFFA07010 , 0xFFA02080 };
50 paint.setAntiAlias(true); 50 paint.setAntiAlias(true);
51 paint.setShader(SkGradientShader::MakeLinear(pts, colors1, nullptr, 2, 51 paint.setShader(SkGradientShader::MakeLinear(pts, colors1, nullptr, 2,
52 SkShader::kClamp_TileMode)) ; 52 SkShader::kClamp_TileMode)) ;
53 canvas.drawCircle(SkIntToScalar(width) / 2, SkIntToScalar(height) / 2, 53 canvas.drawCircle(SkIntToScalar(width) / 2, SkIntToScalar(height) / 2,
54 SkIntToScalar(width + height) / 5, paint); 54 SkIntToScalar(width + height) / 5, paint);
55 } 55 }
56 56
57 SkImage* createRectangleTextureImg(GrContext* context, int width, int height , void* pixels) { 57 sk_sp<SkImage> createRectangleTextureImg(GrContext* context, int width, int height,
58 void* pixels) {
58 if (!context) { 59 if (!context) {
59 return nullptr; 60 return nullptr;
60 } 61 }
61 GrGpu* gpu = context->getGpu(); 62 GrGpu* gpu = context->getGpu();
62 if (!gpu) { 63 if (!gpu) {
63 return nullptr; 64 return nullptr;
64 } 65 }
65 const GrGLContext* glCtx = gpu->glContextForTesting(); 66 const GrGLContext* glCtx = gpu->glContextForTesting();
66 if (!glCtx) { 67 if (!glCtx) {
67 return nullptr; 68 return nullptr;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 context->resetContext(); 105 context->resetContext();
105 GrGLTextureInfo info; 106 GrGLTextureInfo info;
106 info.fID = id; 107 info.fID = id;
107 info.fTarget = TARGET; 108 info.fTarget = TARGET;
108 GrBackendTextureDesc desc; 109 GrBackendTextureDesc desc;
109 desc.fConfig = kRGBA_8888_GrPixelConfig; 110 desc.fConfig = kRGBA_8888_GrPixelConfig;
110 desc.fWidth = width; 111 desc.fWidth = width;
111 desc.fHeight = height; 112 desc.fHeight = height;
112 desc.fOrigin = kTopLeft_GrSurfaceOrigin; 113 desc.fOrigin = kTopLeft_GrSurfaceOrigin;
113 desc.fTextureHandle = reinterpret_cast<GrBackendObject>(&info); 114 desc.fTextureHandle = reinterpret_cast<GrBackendObject>(&info);
114 if (SkImage* image = SkImage::NewFromAdoptedTexture(context, desc)) { 115 if (sk_sp<SkImage> image = SkImage::MakeFromAdoptedTexture(context, desc )) {
115 return image; 116 return image;
116 } 117 }
117 GR_GL_CALL(gl, DeleteTextures(1, &id)); 118 GR_GL_CALL(gl, DeleteTextures(1, &id));
118 return nullptr; 119 return nullptr;
119 } 120 }
120 121
121 void onDraw(SkCanvas* canvas) override { 122 void onDraw(SkCanvas* canvas) override {
122 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget (); 123 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget ();
123 GrContext* context; 124 GrContext* context;
124 if (!rt || !(context = rt->getContext())) { 125 if (!rt || !(context = rt->getContext())) {
125 skiagm::GM::DrawGpuOnlyMessage(canvas); 126 skiagm::GM::DrawGpuOnlyMessage(canvas);
126 return; 127 return;
127 } 128 }
128 129
129 static const int kWidth = 50; 130 static const int kWidth = 50;
130 static const int kHeight = 50; 131 static const int kHeight = 50;
131 static const SkScalar kPad = 5.f; 132 static const SkScalar kPad = 5.f;
132 133
133 SkPMColor pixels[kWidth * kHeight]; 134 SkPMColor pixels[kWidth * kHeight];
134 this->fillPixels(kWidth, kHeight, pixels); 135 this->fillPixels(kWidth, kHeight, pixels);
135 SkAutoTUnref<SkImage> rectImg(this->createRectangleTextureImg(context, k Width, kHeight, 136 sk_sp<SkImage> rectImg(this->createRectangleTextureImg(context, kWidth, kHeight, pixels));
136 pixels));
137 137
138 if (!rectImg) { 138 if (!rectImg) {
139 SkPaint paint; 139 SkPaint paint;
140 paint.setAntiAlias(true); 140 paint.setAntiAlias(true);
141 static const char* kMsg = "Could not create rectangle texture image. "; 141 static const char* kMsg = "Could not create rectangle texture image. ";
142 canvas->drawText(kMsg, strlen(kMsg), 10, 100, paint); 142 canvas->drawText(kMsg, strlen(kMsg), 10, 100, paint);
143 return; 143 return;
144 } 144 }
145 145
146 static const SkFilterQuality kQualities[] = { 146 static const SkFilterQuality kQualities[] = {
147 kNone_SkFilterQuality, 147 kNone_SkFilterQuality,
148 kLow_SkFilterQuality, 148 kLow_SkFilterQuality,
149 kMedium_SkFilterQuality, 149 kMedium_SkFilterQuality,
150 kHigh_SkFilterQuality, 150 kHigh_SkFilterQuality,
151 }; 151 };
152 152
153 static const SkScalar kScales[] = { 1.0f, 1.2f, 0.75f }; 153 static const SkScalar kScales[] = { 1.0f, 1.2f, 0.75f };
154 154
155 canvas->translate(kPad, kPad); 155 canvas->translate(kPad, kPad);
156 for (auto s : kScales) { 156 for (auto s : kScales) {
157 canvas->save(); 157 canvas->save();
158 canvas->scale(s, s); 158 canvas->scale(s, s);
159 for (auto q : kQualities) { 159 for (auto q : kQualities) {
160 SkPaint plainPaint; 160 SkPaint plainPaint;
161 plainPaint.setFilterQuality(q); 161 plainPaint.setFilterQuality(q);
162 canvas->drawImage(rectImg, 0, 0, &plainPaint); 162 canvas->drawImage(rectImg.get(), 0, 0, &plainPaint);
163 canvas->translate(kWidth + kPad, 0); 163 canvas->translate(kWidth + kPad, 0);
164 164
165 SkPaint clampPaint; 165 SkPaint clampPaint;
166 clampPaint.setFilterQuality(q); 166 clampPaint.setFilterQuality(q);
167 clampPaint.setShader(rectImg->makeShader(SkShader::kClamp_Ti leMode, 167 clampPaint.setShader(rectImg->makeShader(SkShader::kClamp_TileMo de,
168 SkShader::kClamp_Ti leMode)); 168 SkShader::kClamp_TileMo de));
169 canvas->drawRect(SkRect::MakeWH(1.5f * kWidth, 1.5f * kHeigh t), clampPaint); 169 canvas->drawRect(SkRect::MakeWH(1.5f * kWidth, 1.5f * kHeight), clampPaint);
170 canvas->translate(kWidth * 1.5f + kPad, 0); 170 canvas->translate(kWidth * 1.5f + kPad, 0);
171 171
172 SkPaint repeatPaint; 172 SkPaint repeatPaint;
173 repeatPaint.setFilterQuality(q); 173 repeatPaint.setFilterQuality(q);
174 repeatPaint.setShader(rectImg->makeShader(SkShader::kRepeat_ TileMode, 174 repeatPaint.setShader(rectImg->makeShader(SkShader::kRepeat_Tile Mode,
175 SkShader::kMirror_ TileMode)); 175 SkShader::kMirror_Tile Mode));
176 canvas->drawRect(SkRect::MakeWH(1.5f * kWidth, 1.5f * kHeigh t), repeatPaint); 176 canvas->drawRect(SkRect::MakeWH(1.5f * kWidth, 1.5f * kHeight), repeatPaint);
177 canvas->translate(1.5f * kWidth + kPad, 0); 177 canvas->translate(1.5f * kWidth + kPad, 0);
178 } 178 }
179 canvas->restore(); 179 canvas->restore();
180 canvas->translate(0, kPad + 1.5f * kHeight * s); 180 canvas->translate(0, kPad + 1.5f * kHeight * s);
181 } 181 }
182 } 182 }
183 183
184 private: 184 private:
185 typedef GM INHERITED; 185 typedef GM INHERITED;
186 }; 186 };
187 187
188 DEF_GM(return new RectangleTexture;) 188 DEF_GM(return new RectangleTexture;)
189 } 189 }
190 190
191 #endif 191 #endif
OLDNEW
« no previous file with comments | « gm/perspshaders.cpp ('k') | gm/repeated_bitmap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698