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

Side by Side Diff: gm/lcdblendmodes.cpp

Issue 1339213004: On gpu, use max(r,g,b) for coverage alpha in LCD and update lcd blend gm. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 3 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 | src/gpu/GrTextContext.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 8
9 /* 9 /*
10 * Tests text rendering with LCD and the various blend modes. 10 * Tests text rendering with LCD and the various blend modes.
11 */ 11 */
12 12
13 #include "gm.h" 13 #include "gm.h"
14 #include "SkCanvas.h" 14 #include "SkCanvas.h"
15 #include "SkGradientShader.h" 15 #include "SkGradientShader.h"
16 #include "SkSurface.h"
16 17
17 namespace skiagm { 18 namespace skiagm {
18 19
19 static const int kColWidth = 180; 20 static const int kColWidth = 180;
20 static const int kNumCols = 4; 21 static const int kNumCols = 4;
21 static const int kWidth = kColWidth * kNumCols; 22 static const int kWidth = kColWidth * kNumCols;
22 static const int kHeight = 750; 23 static const int kHeight = 750;
23 24
24 static SkShader* make_shader(const SkRect& bounds) { 25 static SkShader* make_shader(const SkRect& bounds) {
25 const SkPoint pts[] = { 26 const SkPoint pts[] = {
(...skipping 10 matching lines...) Expand all
36 37
37 class LcdBlendGM : public skiagm::GM { 38 class LcdBlendGM : public skiagm::GM {
38 public: 39 public:
39 LcdBlendGM() { 40 LcdBlendGM() {
40 const int kPointSize = 25; 41 const int kPointSize = 25;
41 fTextHeight = SkIntToScalar(kPointSize); 42 fTextHeight = SkIntToScalar(kPointSize);
42 } 43 }
43 44
44 protected: 45 protected:
45 SkString onShortName() override { 46 SkString onShortName() override {
46 SkString name("lcdblendmodes"); 47 return SkString("lcdblendmodes");
bsalomon 2015/09/15 19:08:34 why this change?
egdaniel 2015/09/15 19:10:30 I was confused about the need for sk_tool_utils::m
47 name.append(sk_tool_utils::major_platform_os_name()); 48 }
48 return name; 49
50 void onOnceBeforeDraw() override {
51 fCheckerboard.reset(sk_tool_utils::create_checkerboard_shader(SK_ColorBL ACK,
52 SK_ColorWH ITE,
53 4));
49 } 54 }
50 55
51 SkISize onISize() override { return SkISize::Make(kWidth, kHeight); } 56 SkISize onISize() override { return SkISize::Make(kWidth, kHeight); }
52 57
53 void onDraw(SkCanvas* canvas) override { 58 void onDraw(SkCanvas* canvas) override {
54 this->drawColumn(canvas, SK_ColorBLACK, SK_ColorWHITE, false); 59 SkPaint p;
55 canvas->translate(SkIntToScalar(kColWidth), 0); 60 p.setAntiAlias(false);
56 this->drawColumn(canvas, SK_ColorWHITE, SK_ColorBLACK, false); 61 p.setStyle(SkPaint::kFill_Style);
57 canvas->translate(SkIntToScalar(kColWidth), 0); 62 p.setShader(fCheckerboard);
58 this->drawColumn(canvas, SK_ColorGREEN, SK_ColorMAGENTA, false); 63 SkRect r = SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(kHeight)) ;
59 canvas->translate(SkIntToScalar(kColWidth), 0); 64 canvas->drawRect(r, p);
60 this->drawColumn(canvas, SK_ColorCYAN, SK_ColorMAGENTA, true); 65
66 SkImageInfo info = SkImageInfo::MakeN32Premul(kWidth, kHeight);
67 SkAutoTUnref<SkSurface> surface(canvas->newSurface(info));
68 if (nullptr == surface) {
69 surface.reset(SkSurface::NewRaster(info));
70 }
71
72 SkCanvas* surfCanvas = surface->getCanvas();
73 this->drawColumn(surfCanvas, SK_ColorBLACK, SK_ColorWHITE, false);
74 surfCanvas->translate(SkIntToScalar(kColWidth), 0);
75 this->drawColumn(surfCanvas, SK_ColorWHITE, SK_ColorBLACK, false);
76 surfCanvas->translate(SkIntToScalar(kColWidth), 0);
77 this->drawColumn(surfCanvas, SK_ColorGREEN, SK_ColorMAGENTA, false);
78 surfCanvas->translate(SkIntToScalar(kColWidth), 0);
79 this->drawColumn(surfCanvas, SK_ColorCYAN, SK_ColorMAGENTA, true);
80
81 SkPaint surfPaint;
82 SkAutoTUnref<SkXfermode> xfermode(SkXfermode::Create(SkXfermode::kSrcOve r_Mode));
83 surfPaint.setXfermode(xfermode);
84 surface->draw(canvas, 0, 0, &surfPaint);
61 } 85 }
62 86
63 void drawColumn(SkCanvas* canvas, SkColor backgroundColor, SkColor textColor , bool useGrad) { 87 void drawColumn(SkCanvas* canvas, SkColor backgroundColor, SkColor textColor , bool useGrad) {
64 const struct { 88 const struct {
65 SkXfermode::Mode fMode; 89 SkXfermode::Mode fMode;
66 const char* fLabel; 90 const char* fLabel;
67 } gModes[] = { 91 } gModes[] = {
68 { SkXfermode::kClear_Mode, "Clear" }, 92 { SkXfermode::kClear_Mode, "Clear" },
69 { SkXfermode::kSrc_Mode, "Src" }, 93 { SkXfermode::kSrc_Mode, "Src" },
70 { SkXfermode::kDst_Mode, "Dst" }, 94 { SkXfermode::kDst_Mode, "Dst" },
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 paint.setShader(make_shader(r))->unref(); 141 paint.setShader(make_shader(r))->unref();
118 } 142 }
119 SkString string(gModes[m].fLabel); 143 SkString string(gModes[m].fLabel);
120 canvas->drawText(gModes[m].fLabel, string.size(), 0, y, paint); 144 canvas->drawText(gModes[m].fLabel, string.size(), 0, y, paint);
121 y+=fTextHeight; 145 y+=fTextHeight;
122 } 146 }
123 } 147 }
124 148
125 private: 149 private:
126 SkScalar fTextHeight; 150 SkScalar fTextHeight;
151 SkAutoTUnref<SkShader> fCheckerboard;
127 typedef skiagm::GM INHERITED; 152 typedef skiagm::GM INHERITED;
128 }; 153 };
129 154
130 ////////////////////////////////////////////////////////////////////////////// 155 //////////////////////////////////////////////////////////////////////////////
131 156
132 DEF_GM( return new LcdBlendGM; ) 157 DEF_GM( return new LcdBlendGM; )
133 } 158 }
OLDNEW
« no previous file with comments | « no previous file | src/gpu/GrTextContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698