Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
textblobblockreordering.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2016 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"
12#include "include/core/SkFont.h"
15#include "include/core/SkRect.h"
18#include "include/core/SkSize.h"
22#include "tools/ToolUtils.h"
24
25#include <string.h>
26
27namespace skiagm {
29public:
30 // This gm tests that textblobs translate properly when their draw order is different from their
31 // flush order
33
34protected:
35 void onOnceBeforeDraw() override {
36 SkTextBlobBuilder builder;
37
38 // make textblob
39 // Large text is used to trigger atlas eviction
41 font.setEdging(SkFont::Edging::kAlias);
42 const char* text = "AB";
43
44 SkRect bounds;
45 font.measureText(text, strlen(text), SkTextEncoding::kUTF8, &bounds);
46
47 SkScalar yOffset = bounds.height();
48 ToolUtils::add_to_text_blob(&builder, text, font, 0, yOffset - 30);
49
50 // build
51 fBlob = builder.make();
52 }
53
54 SkString getName() const override { return SkString("textblobblockreordering"); }
55
56 SkISize getISize() override { return SkISize::Make(kWidth, kHeight); }
57
58 // This draws the same text blob 3 times. The second draw used a different xfer mode so its
59 // GrDrawOp doesn't get combined with the first and third. Ultimately, they will be flushed in
60 // the order first, third, and then second.
61 void onDraw(SkCanvas* canvas) override {
62 canvas->drawColor(SK_ColorGRAY);
63
65 canvas->translate(10, 40);
66
67 SkRect bounds = fBlob->bounds();
68 const int yDelta = SkScalarFloorToInt(bounds.height()) + 20;
69 const int xDelta = SkScalarFloorToInt(bounds.width());
70
71 canvas->drawTextBlob(fBlob, 0, 0, paint);
72
73 canvas->translate(SkIntToScalar(xDelta), SkIntToScalar(yDelta));
74
75 // Draw a rect where the text should be, and then twiddle the xfermode so we don't combine.
76 SkPaint redPaint;
77 redPaint.setColor(SK_ColorRED);
78 canvas->drawRect(bounds, redPaint);
79 SkPaint srcInPaint(paint);
81 canvas->drawTextBlob(fBlob, 0, 0, srcInPaint);
82
83 canvas->translate(SkIntToScalar(xDelta), SkIntToScalar(yDelta));
84 canvas->drawTextBlob(fBlob, 0, 0, paint);
85 }
86
87private:
89
90 inline static constexpr int kWidth = 275;
91 inline static constexpr int kHeight = 200;
92
93 using INHERITED = GM;
94};
95
96//////////////////////////////////////////////////////////////////////////////
97
98DEF_GM(return new TextBlobBlockReordering;)
99} // namespace skiagm
@ kSrcIn
r = s * da
constexpr SkColor SK_ColorGRAY
Definition SkColor.h:113
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
@ kUTF8
uses bytes to represent UTF-8 or ASCII
#define SkIntToScalar(x)
Definition SkScalar.h:57
#define SkScalarFloorToInt(x)
Definition SkScalar.h:35
void drawRect(const SkRect &rect, const SkPaint &paint)
void translate(SkScalar dx, SkScalar dy)
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
Definition SkCanvas.h:1182
void drawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint)
@ kAlias
no transparent pixels on glyph edges
void setColor(SkColor color)
Definition SkPaint.cpp:119
void setBlendMode(SkBlendMode mode)
Definition SkPaint.cpp:151
const SkRect & bounds() const
Definition SkTextBlob.h:53
void onDraw(SkCanvas *canvas) override
const Paint & paint
float SkScalar
Definition extension.cpp:12
#define DEF_GM(CODE)
Definition gm.h:40
std::u16string text
sk_sp< SkTypeface > DefaultPortableTypeface()
void add_to_text_blob(SkTextBlobBuilder *builder, const char *text, const SkFont &font, SkScalar x, SkScalar y)
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20