John Stiles | 68c9325 | 2021-07-16 15:41:56 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "gm/gm.h" |
| 9 | #include "include/core/SkCanvas.h" |
| 10 | #include "include/core/SkFont.h" |
| 11 | #include "include/core/SkPaint.h" |
| 12 | #include "include/core/SkRect.h" |
| 13 | #include "include/core/SkSurface.h" |
| 14 | #include "include/core/SkTextBlob.h" |
Kevin Lubick | 77472bf | 2023-03-24 07:11:17 -0400 | [diff] [blame] | 15 | #include "include/gpu/GpuTypes.h" |
Kevin Lubick | 5c93acf | 2023-05-09 12:11:43 -0400 | [diff] [blame] | 16 | #include "include/gpu/ganesh/SkSurfaceGanesh.h" |
Kevin Lubick | bca43ec | 2023-10-30 10:11:22 -0400 | [diff] [blame] | 17 | #include "tools/fonts/FontToolUtils.h" |
John Stiles | 68c9325 | 2021-07-16 15:41:56 -0400 | [diff] [blame] | 18 | |
| 19 | DEF_SIMPLE_GM_BG(skbug_12212, canvas, 400, 400, SK_ColorCYAN) { |
| 20 | // Create an Alpha_8 surface to draw into (strangely, with RGB pixel geometry). |
| 21 | auto imageInfo = SkImageInfo::Make(/*width=*/400, /*height=*/400, kAlpha_8_SkColorType, |
| 22 | kPremul_SkAlphaType); |
| 23 | SkSurfaceProps props(/*flags=*/0, kRGB_H_SkPixelGeometry); |
Kevin Lubick | 5c93acf | 2023-05-09 12:11:43 -0400 | [diff] [blame] | 24 | sk_sp<SkSurface> surface = SkSurfaces::RenderTarget( |
Kevin Lubick | ecd3a2f | 2023-01-05 08:17:45 -0500 | [diff] [blame] | 25 | canvas->recordingContext(), skgpu::Budgeted::kNo, imageInfo, /*sampleCount=*/0, &props); |
John Stiles | 68c9325 | 2021-07-16 15:41:56 -0400 | [diff] [blame] | 26 | if (!surface) { |
Kevin Lubick | 5c93acf | 2023-05-09 12:11:43 -0400 | [diff] [blame] | 27 | surface = SkSurfaces::Raster(imageInfo, &props); |
John Stiles | 68c9325 | 2021-07-16 15:41:56 -0400 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | // Draw text into the surface using LCD antialiasing. |
| 31 | SkPaint p; |
| 32 | p.setAntiAlias(true); |
| 33 | p.setBlendMode(SkBlendMode::kSrc); |
| 34 | p.setAlpha(0x80); |
Kevin Lubick | bca43ec | 2023-10-30 10:11:22 -0400 | [diff] [blame] | 35 | SkFont font = ToolUtils::DefaultPortableFont(); |
| 36 | font.setSize(170); |
John Stiles | 68c9325 | 2021-07-16 15:41:56 -0400 | [diff] [blame] | 37 | font.setEdging(SkFont::Edging::kSubpixelAntiAlias); |
| 38 | auto textBlob = SkTextBlob::MakeFromText("text", /*byteLength=*/4, font); |
| 39 | surface->getCanvas()->drawTextBlob(textBlob, /*x=*/50, /*y=*/350, p); |
| 40 | |
| 41 | // Draw the surface on our main canvas. |
| 42 | surface->draw(canvas, /*x=*/0, /*y=*/0); |
| 43 | } |