Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 1 | // Copyright 2019 Google LLC. |
| 2 | // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 3 | #include "tools/fiddle/examples.h" |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 4 | // HASH=67b6609471a3f1ed0f4b1657004cdecb |
Hal Canary | a7181e7c | 2019-03-18 16:06:34 -0400 | [diff] [blame] | 5 | REG_FIDDLE(Surface_MakeRenderTarget, 256, 64, false, 0) { |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 6 | void draw(SkCanvas* canvas) { |
Robert Phillips | d1ce4cb | 2020-07-10 16:20:53 -0400 | [diff] [blame] | 7 | SkFont font(nullptr, 32); |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 8 | SkPaint paint; |
Robert Phillips | d1ce4cb | 2020-07-10 16:20:53 -0400 | [diff] [blame] | 9 | |
| 10 | auto context = canvas->getGrContext(); |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 11 | if (!context) { |
Robert Phillips | d1ce4cb | 2020-07-10 16:20:53 -0400 | [diff] [blame] | 12 | canvas->drawString("GPU only!", 20, 40, font, paint); |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 13 | return; |
| 14 | } |
| 15 | SkImageInfo info = SkImageInfo::MakeN32(256, 64, kOpaque_SkAlphaType); |
| 16 | for (auto surfaceOrigin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin } ) { |
| 17 | auto gpuSurface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0, |
| 18 | surfaceOrigin, nullptr)); |
| 19 | auto surfaceCanvas = gpuSurface->getCanvas(); |
| 20 | surfaceCanvas->clear(SK_ColorWHITE); |
Robert Phillips | d1ce4cb | 2020-07-10 16:20:53 -0400 | [diff] [blame] | 21 | surfaceCanvas->drawString("GPU rocks!", 20, 40, font, paint); |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 22 | sk_sp<SkImage> image(gpuSurface->makeImageSnapshot()); |
| 23 | canvas->drawImage(image, 0, 0); |
| 24 | canvas->translate(0, 128); |
| 25 | } |
| 26 | } |
| 27 | } // END FIDDLE |