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=640321e8ecfb3f9329f3bc6e1f02485f |
Hal Canary | a7181e7c | 2019-03-18 16:06:34 -0400 | [diff] [blame] | 5 | REG_FIDDLE(Surface_MakeRenderTarget_2, 256, 256, false, 0) { |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 6 | void draw(SkCanvas* canvas) { |
| 7 | auto test_draw = [](SkCanvas* surfaceCanvas) -> void { |
Robert Phillips | d1ce4cb | 2020-07-10 16:20:53 -0400 | [diff] [blame] | 8 | SkFont font(nullptr, 32); |
| 9 | |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 10 | SkPaint paint; |
| 11 | paint.setAntiAlias(true); |
Robert Phillips | d1ce4cb | 2020-07-10 16:20:53 -0400 | [diff] [blame] | 12 | // TODO: where did this setting go? |
| 13 | //paint.setLCDRenderText(true); |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 14 | paint.setColor(0xFFBBBBBB); |
Robert Phillips | d1ce4cb | 2020-07-10 16:20:53 -0400 | [diff] [blame] | 15 | |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 16 | surfaceCanvas->drawRect(SkRect::MakeWH(128, 64), paint); |
| 17 | paint.setColor(SK_ColorWHITE); |
Robert Phillips | d1ce4cb | 2020-07-10 16:20:53 -0400 | [diff] [blame] | 18 | surfaceCanvas->drawString("Text", 0, 25, font, paint); |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 19 | }; |
Robert Phillips | d1ce4cb | 2020-07-10 16:20:53 -0400 | [diff] [blame] | 20 | auto context = canvas->recordingContext(); |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 21 | SkImageInfo info = SkImageInfo::MakeN32(128, 64, kOpaque_SkAlphaType); |
| 22 | int y = 0; |
| 23 | for (auto geometry : { kRGB_H_SkPixelGeometry, kBGR_H_SkPixelGeometry, |
| 24 | kRGB_V_SkPixelGeometry, kBGR_V_SkPixelGeometry } ) { |
| 25 | SkSurfaceProps props(0, geometry); |
Robert Phillips | d1ce4cb | 2020-07-10 16:20:53 -0400 | [diff] [blame] | 26 | sk_sp<SkSurface> surface = context |
| 27 | ? SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0, &props) |
| 28 | : SkSurface::MakeRaster(info, &props); |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 29 | test_draw(surface->getCanvas()); |
| 30 | surface->draw(canvas, 0, y, nullptr); |
| 31 | sk_sp<SkImage> image(surface->makeImageSnapshot()); |
| 32 | SkAutoCanvasRestore acr(canvas, true); |
| 33 | canvas->scale(8, 8); |
| 34 | canvas->drawImage(image, 12, y / 8); |
| 35 | y += 64; |
| 36 | } |
| 37 | } |
| 38 | } // END FIDDLE |