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" |
| 15 | |
| 16 | DEF_SIMPLE_GM_BG(skbug_12212, canvas, 400, 400, SK_ColorCYAN) { |
| 17 | // Create an Alpha_8 surface to draw into (strangely, with RGB pixel geometry). |
| 18 | auto imageInfo = SkImageInfo::Make(/*width=*/400, /*height=*/400, kAlpha_8_SkColorType, |
| 19 | kPremul_SkAlphaType); |
| 20 | SkSurfaceProps props(/*flags=*/0, kRGB_H_SkPixelGeometry); |
| 21 | sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget( |
| 22 | canvas->recordingContext(), SkBudgeted::kNo, imageInfo, /*sampleCount=*/0, &props); |
| 23 | if (!surface) { |
| 24 | surface = SkSurface::MakeRaster(imageInfo, &props); |
| 25 | } |
| 26 | |
| 27 | // Draw text into the surface using LCD antialiasing. |
| 28 | SkPaint p; |
| 29 | p.setAntiAlias(true); |
| 30 | p.setBlendMode(SkBlendMode::kSrc); |
| 31 | p.setAlpha(0x80); |
| 32 | SkFont font{}; |
| 33 | font = font.makeWithSize(170); |
| 34 | font.setEdging(SkFont::Edging::kSubpixelAntiAlias); |
| 35 | auto textBlob = SkTextBlob::MakeFromText("text", /*byteLength=*/4, font); |
| 36 | surface->getCanvas()->drawTextBlob(textBlob, /*x=*/50, /*y=*/350, p); |
| 37 | |
| 38 | // Draw the surface on our main canvas. |
| 39 | surface->draw(canvas, /*x=*/0, /*y=*/0); |
| 40 | } |