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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 } | 307 } |
308 | 308 |
309 static void draw_as_bitmap(SkCanvas* canvas, SkImageCacherator* cache, SkSca
lar x, SkScalar y) { | 309 static void draw_as_bitmap(SkCanvas* canvas, SkImageCacherator* cache, SkSca
lar x, SkScalar y) { |
310 SkBitmap bitmap; | 310 SkBitmap bitmap; |
311 cache->lockAsBitmap(&bitmap, nullptr); | 311 cache->lockAsBitmap(&bitmap, nullptr); |
312 canvas->drawBitmap(bitmap, x, y); | 312 canvas->drawBitmap(bitmap, x, y); |
313 } | 313 } |
314 | 314 |
315 static void draw_as_tex(SkCanvas* canvas, SkImageCacherator* cache, SkScalar
x, SkScalar y) { | 315 static void draw_as_tex(SkCanvas* canvas, SkImageCacherator* cache, SkScalar
x, SkScalar y) { |
316 #if SK_SUPPORT_GPU | 316 #if SK_SUPPORT_GPU |
317 SkAutoTUnref<GrTexture> texture(cache->lockAsTexture(canvas->getGrContex
t(), | 317 sk_sp<GrTexture> texture(cache->lockAsTexture(canvas->getGrContext(), |
318 GrTextureParams::Cl
ampBilerp(), | 318 GrTextureParams::ClampBile
rp(), |
319 SkSourceGammaTreatm
ent::kRespect, | 319 SkSourceGammaTreatment::kR
espect, |
320 nullptr)); | 320 nullptr)); |
321 if (!texture) { | 321 if (!texture) { |
322 // show placeholder if we have no texture | 322 // show placeholder if we have no texture |
323 SkPaint paint; | 323 SkPaint paint; |
324 paint.setStyle(SkPaint::kStroke_Style); | 324 paint.setStyle(SkPaint::kStroke_Style); |
325 SkRect r = SkRect::MakeXYWH(x, y, SkIntToScalar(cache->info().width(
)), | 325 SkRect r = SkRect::MakeXYWH(x, y, SkIntToScalar(cache->info().width(
)), |
326 SkIntToScalar(cache->info().width())); | 326 SkIntToScalar(cache->info().width())); |
327 canvas->drawRect(r, paint); | 327 canvas->drawRect(r, paint); |
328 canvas->drawLine(r.left(), r.top(), r.right(), r.bottom(), paint); | 328 canvas->drawLine(r.left(), r.top(), r.right(), r.bottom(), paint); |
329 canvas->drawLine(r.left(), r.bottom(), r.right(), r.top(), paint); | 329 canvas->drawLine(r.left(), r.bottom(), r.right(), r.top(), paint); |
330 return; | 330 return; |
331 } | 331 } |
332 // No API to draw a GrTexture directly, so we cheat and create a private
image subclass | 332 // No API to draw a GrTexture directly, so we cheat and create a private
image subclass |
333 SkAutoTUnref<SkImage> image(new SkImage_Gpu(cache->info().width(), cache
->info().height(), | 333 sk_sp<SkImage> image(new SkImage_Gpu(cache->info().width(), cache->info(
).height(), |
334 cache->uniqueID(), kPremul_S
kAlphaType, texture, | 334 cache->uniqueID(), kPremul_SkAlphaT
ype, |
335 sk_ref_sp(cache->info().colo
rSpace()), | 335 std::move(texture), |
336 SkBudgeted::kNo)); | 336 sk_ref_sp(cache->info().colorSpace(
)), |
337 canvas->drawImage(image, x, y); | 337 SkBudgeted::kNo)); |
| 338 canvas->drawImage(image.get(), x, y); |
338 #endif | 339 #endif |
339 } | 340 } |
340 | 341 |
341 void drawSet(SkCanvas* canvas) const { | 342 void drawSet(SkCanvas* canvas) const { |
342 SkMatrix matrix = SkMatrix::MakeTrans(-100, -100); | 343 SkMatrix matrix = SkMatrix::MakeTrans(-100, -100); |
343 canvas->drawPicture(fPicture, &matrix, nullptr); | 344 canvas->drawPicture(fPicture, &matrix, nullptr); |
344 | 345 |
345 // Draw the tex first, so it doesn't hit a lucky cache from the raster v
ersion. This | 346 // Draw the tex first, so it doesn't hit a lucky cache from the raster v
ersion. This |
346 // way we also can force the generateTexture call. | 347 // way we also can force the generateTexture call. |
347 | 348 |
(...skipping 26 matching lines...) Expand all Loading... |
374 | 375 |
375 private: | 376 private: |
376 typedef skiagm::GM INHERITED; | 377 typedef skiagm::GM INHERITED; |
377 }; | 378 }; |
378 DEF_GM( return new ImageCacheratorGM("picture", make_pic_generator); ) | 379 DEF_GM( return new ImageCacheratorGM("picture", make_pic_generator); ) |
379 DEF_GM( return new ImageCacheratorGM("raster", make_ras_generator); ) | 380 DEF_GM( return new ImageCacheratorGM("raster", make_ras_generator); ) |
380 DEF_GM( return new ImageCacheratorGM("ctable", make_ctable_generator); ) | 381 DEF_GM( return new ImageCacheratorGM("ctable", make_ctable_generator); ) |
381 #if SK_SUPPORT_GPU | 382 #if SK_SUPPORT_GPU |
382 DEF_GM( return new ImageCacheratorGM("texture", make_tex_generator); ) | 383 DEF_GM( return new ImageCacheratorGM("texture", make_tex_generator); ) |
383 #endif | 384 #endif |
OLD | NEW |