OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 #include "gm.h" | 8 #include "gm.h" |
| 9 #if SK_SUPPORT_GPU |
9 #include "GrTest.h" | 10 #include "GrTest.h" |
| 11 #include "effects/GrRRectEffect.h" |
| 12 #endif |
10 #include "SkDevice.h" | 13 #include "SkDevice.h" |
11 #include "SkRRect.h" | 14 #include "SkRRect.h" |
12 #include "effects/GrRRectEffect.h" | |
13 | 15 |
14 namespace skiagm { | 16 namespace skiagm { |
15 | 17 |
16 /////////////////////////////////////////////////////////////////////////////// | 18 /////////////////////////////////////////////////////////////////////////////// |
17 | 19 |
18 class RRectGM : public GM { | 20 class RRectGM : public GM { |
19 public: | 21 public: |
20 enum Type { | 22 enum Type { |
21 kBW_Draw_Type, | 23 kBW_Draw_Type, |
22 kAA_Draw_Type, | 24 kAA_Draw_Type, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 | 58 |
57 virtual uint32_t onGetFlags() const SK_OVERRIDE { | 59 virtual uint32_t onGetFlags() const SK_OVERRIDE { |
58 if (kEffect_Type == fType) { | 60 if (kEffect_Type == fType) { |
59 return kGPUOnly_Flag; | 61 return kGPUOnly_Flag; |
60 } else { | 62 } else { |
61 return 0; | 63 return 0; |
62 } | 64 } |
63 } | 65 } |
64 | 66 |
65 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 67 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 68 int numRRects = kNumRRects; |
| 69 #if SK_SUPPORT_GPU |
66 SkBaseDevice* device = canvas->getTopDevice(); | 70 SkBaseDevice* device = canvas->getTopDevice(); |
67 GrContext* context = NULL; | 71 GrContext* context = NULL; |
68 GrRenderTarget* rt = device->accessRenderTarget(); | 72 GrRenderTarget* rt = device->accessRenderTarget(); |
69 if (NULL != rt) { | 73 if (NULL != rt) { |
70 context = rt->getContext(); | 74 context = rt->getContext(); |
71 } | 75 } |
72 if (kEffect_Type == fType && NULL == context) { | 76 if (kEffect_Type == fType && NULL == context) { |
73 return; | 77 return; |
74 } | 78 } |
| 79 if (kEffect_Type == fType) { |
| 80 numRRects *= GrRRectEffect::kEdgeTypeCnt; |
| 81 } |
| 82 #endif |
75 | 83 |
76 SkPaint paint; | 84 SkPaint paint; |
77 if (kAA_Draw_Type == fType) { | 85 if (kAA_Draw_Type == fType) { |
78 paint.setAntiAlias(true); | 86 paint.setAntiAlias(true); |
79 } | 87 } |
80 | 88 |
81 static const SkRect kMaxTileBound = SkRect::MakeWH(SkIntToScalar(kTileX)
, SkIntToScalar(kTileY)); | 89 static const SkRect kMaxTileBound = SkRect::MakeWH(SkIntToScalar(kTileX)
, SkIntToScalar(kTileY)); |
82 | 90 |
83 int curRRect = 0; | 91 int curRRect = 0; |
84 int numRRects = kNumRRects; | |
85 if (kEffect_Type == fType) { | |
86 numRRects *= GrRRectEffect::kEdgeTypeCnt; | |
87 } | |
88 for (int y = 1; y < kImageHeight; y += kTileY) { | 92 for (int y = 1; y < kImageHeight; y += kTileY) { |
89 for (int x = 1; x < kImageWidth; x += kTileX) { | 93 for (int x = 1; x < kImageWidth; x += kTileX) { |
90 if (curRRect >= numRRects) { | 94 if (curRRect >= numRRects) { |
91 break; | 95 break; |
92 } | 96 } |
93 int rrectIdx = curRRect % kNumRRects; | 97 int rrectIdx = curRRect % kNumRRects; |
94 SkASSERT(kMaxTileBound.contains(fRRects[rrectIdx].getBounds())); | 98 SkASSERT(kMaxTileBound.contains(fRRects[rrectIdx].getBounds())); |
95 | 99 |
96 canvas->save(); | 100 canvas->save(); |
97 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); | 101 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); |
98 if (kEffect_Type == fType) { | 102 if (kEffect_Type == fType) { |
| 103 #if SK_SUPPORT_GPU |
99 GrTestTarget tt; | 104 GrTestTarget tt; |
100 context->getTestTarget(&tt); | 105 context->getTestTarget(&tt); |
101 if (NULL == tt.target()) { | 106 if (NULL == tt.target()) { |
102 SkDEBUGFAIL("Couldn't get Gr test target."); | 107 SkDEBUGFAIL("Couldn't get Gr test target."); |
103 return; | 108 return; |
104 } | 109 } |
105 GrDrawState* drawState = tt.target()->drawState(); | 110 GrDrawState* drawState = tt.target()->drawState(); |
106 | 111 |
107 SkRRect rrect = fRRects[rrectIdx]; | 112 SkRRect rrect = fRRects[rrectIdx]; |
108 rrect.offset(SkIntToScalar(x), SkIntToScalar(y)); | 113 rrect.offset(SkIntToScalar(x), SkIntToScalar(y)); |
109 GrRRectEffect::EdgeType edgeType = (GrRRectEffect::EdgeT
ype) | 114 GrRRectEffect::EdgeType edgeType = (GrRRectEffect::EdgeT
ype) |
110 (curRRect / kNumRRec
ts); | 115 (curRRect / kNumRRec
ts); |
111 SkAutoTUnref<GrEffectRef> effect(GrRRectEffect::Create(e
dgeType, rrect)); | 116 SkAutoTUnref<GrEffectRef> effect(GrRRectEffect::Create(e
dgeType, rrect)); |
112 if (effect) { | 117 if (effect) { |
113 drawState->addCoverageEffect(effect); | 118 drawState->addCoverageEffect(effect); |
114 drawState->setIdentityViewMatrix(); | 119 drawState->setIdentityViewMatrix(); |
115 drawState->setRenderTarget(rt); | 120 drawState->setRenderTarget(rt); |
116 drawState->setColor(0xff000000); | 121 drawState->setColor(0xff000000); |
117 | 122 |
118 SkRect bounds = rrect.getBounds(); | 123 SkRect bounds = rrect.getBounds(); |
119 bounds.outset(2.f, 2.f); | 124 bounds.outset(2.f, 2.f); |
120 | 125 |
121 tt.target()->drawSimpleRect(bounds); | 126 tt.target()->drawSimpleRect(bounds); |
122 } | 127 } |
| 128 #endif |
123 } else if (kBW_Clip_Type == fType || kAA_Clip_Type == fType)
{ | 129 } else if (kBW_Clip_Type == fType || kAA_Clip_Type == fType)
{ |
124 bool aaClip = (kAA_Clip_Type == fType); | 130 bool aaClip = (kAA_Clip_Type == fType); |
125 canvas->clipRRect(fRRects[rrectIdx], SkRegion::kReplace_
Op, aaClip); | 131 canvas->clipRRect(fRRects[rrectIdx], SkRegion::kReplace_
Op, aaClip); |
126 canvas->drawRect(kMaxTileBound, paint); | 132 canvas->drawRect(kMaxTileBound, paint); |
127 } else { | 133 } else { |
128 canvas->drawRRect(fRRects[rrectIdx], paint); | 134 canvas->drawRRect(fRRects[rrectIdx], paint); |
129 } | 135 } |
130 ++curRRect; | 136 ++curRRect; |
131 canvas->restore(); | 137 canvas->restore(); |
132 } | 138 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 { { 0, 0 }, { 0, 0 }, { 20, 20 }, { 20, 20 } }, | 220 { { 0, 0 }, { 0, 0 }, { 20, 20 }, { 20, 20 } }, |
215 { { 20, 20 }, { 0, 0 }, { 0, 0 }, { 20, 20 } }, | 221 { { 20, 20 }, { 0, 0 }, { 0, 0 }, { 20, 20 } }, |
216 }; | 222 }; |
217 | 223 |
218 /////////////////////////////////////////////////////////////////////////////// | 224 /////////////////////////////////////////////////////////////////////////////// |
219 | 225 |
220 DEF_GM( return new RRectGM(RRectGM::kAA_Draw_Type); ) | 226 DEF_GM( return new RRectGM(RRectGM::kAA_Draw_Type); ) |
221 DEF_GM( return new RRectGM(RRectGM::kBW_Draw_Type); ) | 227 DEF_GM( return new RRectGM(RRectGM::kBW_Draw_Type); ) |
222 DEF_GM( return new RRectGM(RRectGM::kAA_Clip_Type); ) | 228 DEF_GM( return new RRectGM(RRectGM::kAA_Clip_Type); ) |
223 DEF_GM( return new RRectGM(RRectGM::kBW_Clip_Type); ) | 229 DEF_GM( return new RRectGM(RRectGM::kBW_Clip_Type); ) |
| 230 #if SK_SUPPORT_GPU |
224 DEF_GM( return new RRectGM(RRectGM::kEffect_Type); ) | 231 DEF_GM( return new RRectGM(RRectGM::kEffect_Type); ) |
| 232 #endif |
225 | 233 |
226 } | 234 } |
OLD | NEW |