Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Side by Side Diff: gm/textblobblockreordering.cpp

Issue 1721833005: Create new GM to target translations problems in GrAtlasTextContext (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: feedback inc Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.h"
9
10 #include "SkCanvas.h"
11 #include "SkTextBlob.h"
12
13 namespace skiagm {
14 class TextBlobBlockReordering : public GM {
15 public:
16 // This gm tests that textblobs translate properly when their draw order is different from their
17 // flush order
18 TextBlobBlockReordering() { }
19
20 protected:
21 void onOnceBeforeDraw() override {
22 SkTextBlobBuilder builder;
23
24 // make textblob
25 // Large text is used to trigger atlas eviction
26 SkPaint paint;
27 paint.setTextSize(56);
28 const char* text = "AB";
29 sk_tool_utils::set_portable_typeface(&paint);
30
31 SkRect bounds;
32 paint.measureText(text, strlen(text), &bounds);
33
34 SkScalar yOffset = bounds.height();
35 sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, yOffset - 30);
36
37 // build
38 fBlob.reset(builder.build());
39 }
40
41 SkString onShortName() override {
42 return SkString("textblobblockreordering");
43 }
44
45 SkISize onISize() override {
46 return SkISize::Make(kWidth, kHeight);
47 }
48
49 // This draws the same text blob 3 times. The second draw used a different
50 // xfer mode so it doens't get batched with the first and third.
51 // ultimately thye iwll be flushed in the order first, third, and then secon d
52 void onDraw(SkCanvas* canvas) override {
53 canvas->drawColor(sk_tool_utils::color_to_565(SK_ColorGRAY));
54
55 SkPaint paint;
56 canvas->translate(10, 40);
57
58 SkRect bounds = fBlob->bounds();
59 const int yDelta = SkScalarFloorToInt(bounds.height()) + 20;
60 const int xDelta = SkScalarFloorToInt(bounds.width());
61
62 canvas->drawTextBlob(fBlob, 0, 0, paint);
63
64 canvas->translate(SkIntToScalar(xDelta), SkIntToScalar(yDelta));
65
66 // draw a rect where the text should be, and then twiddle the xfermode
67 // so we don't batch
68 SkPaint redPaint;
69 redPaint.setColor(SK_ColorRED);
70 canvas->drawRect(bounds, redPaint);
71 SkPaint srcInPaint(paint);
72 srcInPaint.setXfermodeMode(SkXfermode::kSrcIn_Mode);
73 canvas->drawTextBlob(fBlob, 0, 0, srcInPaint);
74
75 canvas->translate(SkIntToScalar(xDelta), SkIntToScalar(yDelta));
76 canvas->drawTextBlob(fBlob, 0, 0, paint);
77 }
78
79 private:
80 SkAutoTUnref<const SkTextBlob> fBlob;
81
82 static const int kWidth = 275;
83 static const int kHeight = 200;
84
85 typedef GM INHERITED;
86 };
87
88 //////////////////////////////////////////////////////////////////////////////
89
90 DEF_GM(return new TextBlobBlockReordering;)
91 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698