OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkImage.h" | 10 #include "SkImage.h" |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 { | 192 { |
193 fName.printf("image-cacherator-from-%s", suffix); | 193 fName.printf("image-cacherator-from-%s", suffix); |
194 } | 194 } |
195 | 195 |
196 protected: | 196 protected: |
197 SkString onShortName() override { | 197 SkString onShortName() override { |
198 return fName; | 198 return fName; |
199 } | 199 } |
200 | 200 |
201 SkISize onISize() override { | 201 SkISize onISize() override { |
202 return SkISize::Make(850, 450); | 202 return SkISize::Make(960, 450); |
203 } | 203 } |
204 | 204 |
205 void onOnceBeforeDraw() override { | 205 void onOnceBeforeDraw() override { |
206 const SkRect bounds = SkRect::MakeXYWH(100, 100, 100, 100); | 206 const SkRect bounds = SkRect::MakeXYWH(100, 100, 100, 100); |
207 SkPictureRecorder recorder; | 207 SkPictureRecorder recorder; |
208 draw_something(recorder.beginRecording(bounds), bounds); | 208 draw_something(recorder.beginRecording(bounds), bounds); |
209 fPicture.reset(recorder.endRecording()); | 209 fPicture.reset(recorder.endRecording()); |
210 } | 210 } |
211 | 211 |
212 void makeCaches(GrContext* ctx) { | 212 void makeCaches(GrContext* ctx) { |
(...skipping 20 matching lines...) Expand all Loading... |
233 SkBitmap bitmap; | 233 SkBitmap bitmap; |
234 cache->lockAsBitmap(&bitmap); | 234 cache->lockAsBitmap(&bitmap); |
235 canvas->drawBitmap(bitmap, x, y); | 235 canvas->drawBitmap(bitmap, x, y); |
236 } | 236 } |
237 | 237 |
238 static void draw_as_tex(SkCanvas* canvas, SkImageCacherator* cache, SkScalar
x, SkScalar y) { | 238 static void draw_as_tex(SkCanvas* canvas, SkImageCacherator* cache, SkScalar
x, SkScalar y) { |
239 #if SK_SUPPORT_GPU | 239 #if SK_SUPPORT_GPU |
240 SkAutoTUnref<GrTexture> texture(cache->lockAsTexture(canvas->getGrContex
t(), | 240 SkAutoTUnref<GrTexture> texture(cache->lockAsTexture(canvas->getGrContex
t(), |
241 kUntiled_SkImageUsa
geType)); | 241 kUntiled_SkImageUsa
geType)); |
242 if (!texture) { | 242 if (!texture) { |
| 243 // show placeholder if we have no texture |
| 244 SkPaint paint; |
| 245 paint.setStyle(SkPaint::kStroke_Style); |
| 246 SkRect r = SkRect::MakeXYWH(x, y, SkIntToScalar(cache->info().width(
)), |
| 247 SkIntToScalar(cache->info().width())); |
| 248 canvas->drawRect(r, paint); |
| 249 canvas->drawLine(r.left(), r.top(), r.right(), r.bottom(), paint); |
| 250 canvas->drawLine(r.left(), r.bottom(), r.right(), r.top(), paint); |
243 return; | 251 return; |
244 } | 252 } |
245 // No API to draw a GrTexture directly, so we cheat and create a private
image subclass | 253 // No API to draw a GrTexture directly, so we cheat and create a private
image subclass |
246 SkAutoTUnref<SkImage> image(new SkImage_Gpu(cache->info().width(), cache
->info().height(), | 254 SkAutoTUnref<SkImage> image(new SkImage_Gpu(cache->info().width(), cache
->info().height(), |
247 cache->uniqueID(), kPremul_S
kAlphaType, texture, | 255 cache->uniqueID(), kPremul_S
kAlphaType, texture, |
248 0, SkSurface::kNo_Budgeted))
; | 256 0, SkSurface::kNo_Budgeted))
; |
249 canvas->drawImage(image, x, y); | 257 canvas->drawImage(image, x, y); |
250 #endif | 258 #endif |
251 } | 259 } |
252 | 260 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 typedef skiagm::GM INHERITED; | 296 typedef skiagm::GM INHERITED; |
289 }; | 297 }; |
290 DEF_GM( return new ImageCacheratorGM("picture", make_pic_generator); ) | 298 DEF_GM( return new ImageCacheratorGM("picture", make_pic_generator); ) |
291 DEF_GM( return new ImageCacheratorGM("raster", make_ras_generator); ) | 299 DEF_GM( return new ImageCacheratorGM("raster", make_ras_generator); ) |
292 #if SK_SUPPORT_GPU | 300 #if SK_SUPPORT_GPU |
293 DEF_GM( return new ImageCacheratorGM("texture", make_tex_generator); ) | 301 DEF_GM( return new ImageCacheratorGM("texture", make_tex_generator); ) |
294 #endif | 302 #endif |
295 | 303 |
296 | 304 |
297 | 305 |
OLD | NEW |