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=d3aec071998f871809f515e58abb1b0e |
Hal Canary | a7181e7c | 2019-03-18 16:06:34 -0400 | [diff] [blame] | 5 | REG_FIDDLE(Surface_MakeFromBackendTexture, 256, 256, false, 3) { |
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 | GrRecordingContext* context = canvas->recordingContext(); |
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 | } |
Robert Phillips | d1ce4cb | 2020-07-10 16:20:53 -0400 | [diff] [blame] | 15 | GrDirectContext* direct = context->asDirectContext(); |
| 16 | if (!direct) { |
| 17 | canvas->drawString("Direct Context only!", 20, 40, font, paint); |
| 18 | return; |
| 19 | } |
| 20 | |
| 21 | sk_sp<SkSurface> gpuSurface = SkSurface::MakeFromBackendTexture(direct, |
| 22 | backEndTexture, |
| 23 | kTopLeft_GrSurfaceOrigin, |
| 24 | 0, |
| 25 | kRGBA_8888_SkColorType, |
| 26 | nullptr, |
| 27 | nullptr, |
| 28 | nullptr); |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 29 | auto surfaceCanvas = gpuSurface->getCanvas(); |
Robert Phillips | d1ce4cb | 2020-07-10 16:20:53 -0400 | [diff] [blame] | 30 | surfaceCanvas->drawString("GPU rocks!", 20, 40, font, paint); |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 31 | sk_sp<SkImage> image(gpuSurface->makeImageSnapshot()); |
| 32 | canvas->drawImage(image, 0, 0); |
| 33 | } |
| 34 | } // END FIDDLE |