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

Side by Side Diff: gm/bigrrectaaeffect.cpp

Issue 1256353004: Fix elliptical rrect clip shaders for large radii on devices with mediump (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rename file Created 5 years, 4 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/effects/GrOvalEffect.cpp » ('j') | 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 2015 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 #if SK_SUPPORT_GPU
10 #include "GrTest.h"
11 #include "effects/GrRRectEffect.h"
12 #include "SkDevice.h"
13 #include "SkRRect.h"
14
15 namespace skiagm {
16
17 ///////////////////////////////////////////////////////////////////////////////
18
19 class BigRRectAAEffectGM : public GM {
20 public:
21 BigRRectAAEffectGM() {
22 this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD));
23 this->setUpRRects();
24 }
25
26 protected:
27 SkString onShortName() override {
28 return SkString("big_rrect_aa_effect");
29 }
30
31 SkISize onISize() override { return SkISize::Make(kImageWidth, kImageHeight) ; }
32
33 void onDraw(SkCanvas* canvas) override {
34 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget ();
35 GrContext* context = rt ? rt->getContext() : NULL;
36 if (!context) {
37 this->drawGpuOnlyMessage(canvas);
38 return;
39 }
40
41 SkPaint paint;
42
43 #ifdef SK_DEBUG
44 static const SkRect kMaxRRectBound = SkRect::MakeWH(SkIntToScalar(kMaxSi ze),
45 SkIntToScalar(kMaxSi ze));
46 static const SkRect kMaxImageBound = SkRect::MakeWH(SkIntToScalar(kImage Width),
47 SkIntToScalar(kImage Height));
48 #endif
49
50 int y = kPad;
51 int x = kPad;
52 static const GrPrimitiveEdgeType kEdgeTypes[] = {
53 kFillAA_GrProcessorEdgeType,
54 kInverseFillAA_GrProcessorEdgeType,
55 };
56 for (size_t et = 0; et < SK_ARRAY_COUNT(kEdgeTypes); ++et) {
57 GrPrimitiveEdgeType edgeType = kEdgeTypes[et];
58 for (int curRRect = 0; curRRect < fRRects.count(); ++curRRect) {
59 #ifdef SK_DEBUG
60 SkASSERT(kMaxRRectBound.contains(fRRects[curRRect].getBounds())) ;
61 SkRect imageSpaceBounds = fRRects[curRRect].getBounds();
62 imageSpaceBounds.offset(SkIntToScalar(x), SkIntToScalar(y));
63 SkASSERT(kMaxImageBound.contains(imageSpaceBounds));
64 #endif
65 canvas->save();
66 canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
67 GrTestTarget tt;
68 context->getTestTarget(&tt);
69 if (NULL == tt.target()) {
70 SkDEBUGFAIL("Couldn't get Gr test target.");
71 return;
72 }
73 GrPipelineBuilder pipelineBuilder;
74
75 SkRRect rrect = fRRects[curRRect];
76 rrect.offset(SkIntToScalar(x), SkIntToScalar(y));
77 SkAutoTUnref<GrFragmentProcessor> fp(GrRRectEffect::Create(e dgeType, rrect));
78 SkASSERT(fp);
79 if (fp) {
80 pipelineBuilder.addCoverageProcessor(fp);
81 pipelineBuilder.setRenderTarget(rt);
82
83 SkRect bounds = SkRect::MakeWH(SkIntToScalar(kMaxSize),
84 SkIntToScalar(kMaxSize));
85 bounds.outset(2.f, 2.f);
86 bounds.offset(SkIntToScalar(x), SkIntToScalar(y));
87
88 tt.target()->drawSimpleRect(pipelineBuilder,
89 0xff000000,
90 SkMatrix::I(),
91 bounds);
92 }
93 canvas->restore();
94 x = x + kDrawOffset;
95 if (x + kMaxSize> kImageWidth) {
96 x = kPad;
97 y += kDrawOffset;
98 }
99 }
100 }
101 }
102
103 void setUpRRects() {
104 SkScalar maxSize = SkIntToScalar(kMaxSize);
105 fRRects.push()->setRect(SkRect::MakeWH(maxSize, maxSize));
106 fRRects.push()->setOval(SkRect::MakeWH(maxSize, maxSize));
107 fRRects.push()->setOval(SkRect::MakeWH(maxSize - 1.f, maxSize - 10.f));
108 fRRects.push()->setRectXY(SkRect::MakeWH(maxSize - 1.f, maxSize - 10.f),
109 maxSize/2.f - 10.f, maxSize/2.f - 10.f);
110 fRRects.push()->setRectXY(SkRect::MakeWH(maxSize - 1.f, maxSize - 10),
111 maxSize/2.f - 10.f, maxSize/2.f - 20.f);
112 }
113
114 private:
115 static const int kPad = 5;
116 static const int kMaxSize = 300;
117 static const int kDrawOffset = kMaxSize + kPad;
118
119 static const int kImageWidth = 4 * kDrawOffset + kPad;
120 static const int kImageHeight = 3 * kDrawOffset + kPad;
121
122
123 SkTDArray<SkRRect> fRRects;
124 typedef GM INHERITED;
125 };
126
127 ///////////////////////////////////////////////////////////////////////////////
128
129 DEF_GM( return new BigRRectAAEffectGM (); )
130
131 }
132 #endif
OLDNEW
« no previous file with comments | « no previous file | src/gpu/effects/GrOvalEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698