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 #if SK_SUPPORT_GPU |
10 #include "GrTest.h" | 10 #include "GrTest.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 | 58 |
59 virtual uint32_t onGetFlags() const SK_OVERRIDE { | 59 virtual uint32_t onGetFlags() const SK_OVERRIDE { |
60 if (kEffect_Type == fType) { | 60 if (kEffect_Type == fType) { |
61 return kGPUOnly_Flag; | 61 return kGPUOnly_Flag; |
62 } else { | 62 } else { |
63 return 0; | 63 return 0; |
64 } | 64 } |
65 } | 65 } |
66 | 66 |
67 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 67 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
68 int numRRects = kNumRRects; | |
69 #if SK_SUPPORT_GPU | 68 #if SK_SUPPORT_GPU |
70 SkBaseDevice* device = canvas->getTopDevice(); | 69 SkBaseDevice* device = canvas->getTopDevice(); |
71 GrContext* context = NULL; | 70 GrContext* context = NULL; |
72 GrRenderTarget* rt = device->accessRenderTarget(); | 71 GrRenderTarget* rt = device->accessRenderTarget(); |
73 if (NULL != rt) { | 72 if (NULL != rt) { |
74 context = rt->getContext(); | 73 context = rt->getContext(); |
75 } | 74 } |
76 if (kEffect_Type == fType && NULL == context) { | 75 if (kEffect_Type == fType && NULL == context) { |
77 return; | 76 return; |
78 } | 77 } |
79 if (kEffect_Type == fType) { | |
80 numRRects *= kGrEffectEdgeTypeCnt; | |
81 } | |
82 #endif | 78 #endif |
83 | 79 |
84 SkPaint paint; | 80 SkPaint paint; |
85 if (kAA_Draw_Type == fType) { | 81 if (kAA_Draw_Type == fType) { |
86 paint.setAntiAlias(true); | 82 paint.setAntiAlias(true); |
87 } | 83 } |
88 | 84 |
89 static const SkRect kMaxTileBound = SkRect::MakeWH(SkIntToScalar(kTileX)
, SkIntToScalar(kTileY)); | 85 static const SkRect kMaxTileBound = SkRect::MakeWH(SkIntToScalar(kTileX)
, |
| 86 SkIntToScalar(kTileY)
); |
| 87 #ifdef SK_DEBUG |
| 88 static const SkRect kMaxImageBound = SkRect::MakeWH(SkIntToScalar(kImage
Width), |
| 89 SkIntToScalar(kImage
Height)); |
| 90 #endif |
90 | 91 |
91 int curRRect = 0; | 92 int lastEdgeType = (kEffect_Type == fType) ? kLast_GrEffectEdgeType: 0; |
92 for (int y = 1; y < kImageHeight; y += kTileY) { | |
93 for (int x = 1; x < kImageWidth; x += kTileX) { | |
94 if (curRRect >= numRRects) { | |
95 break; | |
96 } | |
97 int rrectIdx = curRRect % kNumRRects; | |
98 SkASSERT(kMaxTileBound.contains(fRRects[rrectIdx].getBounds())); | |
99 | 93 |
| 94 int y = 1; |
| 95 for (int et = (GrEffectEdgeType) 0; et <= lastEdgeType; ++et) { |
| 96 int x = 1; |
| 97 for (int curRRect = 0; curRRect < kNumRRects; ++curRRect) { |
| 98 bool drew = true; |
| 99 #ifdef SK_DEBUG |
| 100 SkASSERT(kMaxTileBound.contains(fRRects[curRRect].getBounds())); |
| 101 SkRect imageSpaceBounds = fRRects[curRRect].getBounds(); |
| 102 imageSpaceBounds.offset(SkIntToScalar(x), SkIntToScalar(y)); |
| 103 SkASSERT(kMaxImageBound.contains(imageSpaceBounds)); |
| 104 #endif |
100 canvas->save(); | 105 canvas->save(); |
101 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); | 106 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); |
102 if (kEffect_Type == fType) { | 107 if (kEffect_Type == fType) { |
103 #if SK_SUPPORT_GPU | 108 #if SK_SUPPORT_GPU |
104 GrTestTarget tt; | 109 GrTestTarget tt; |
105 context->getTestTarget(&tt); | 110 context->getTestTarget(&tt); |
106 if (NULL == tt.target()) { | 111 if (NULL == tt.target()) { |
107 SkDEBUGFAIL("Couldn't get Gr test target."); | 112 SkDEBUGFAIL("Couldn't get Gr test target."); |
108 return; | 113 return; |
109 } | 114 } |
110 GrDrawState* drawState = tt.target()->drawState(); | 115 GrDrawState* drawState = tt.target()->drawState(); |
111 | 116 |
112 SkRRect rrect = fRRects[rrectIdx]; | 117 SkRRect rrect = fRRects[curRRect]; |
113 rrect.offset(SkIntToScalar(x), SkIntToScalar(y)); | 118 rrect.offset(SkIntToScalar(x), SkIntToScalar(y)); |
114 GrEffectEdgeType edgeType = (GrEffectEdgeType) (curRRect
/ kNumRRects); | 119 GrEffectEdgeType edgeType = (GrEffectEdgeType) et; |
115 SkAutoTUnref<GrEffectRef> effect(GrRRectEffect::Create(e
dgeType, rrect)); | 120 SkAutoTUnref<GrEffectRef> effect(GrRRectEffect::Create(e
dgeType, rrect)); |
116 if (effect) { | 121 if (effect) { |
117 drawState->addCoverageEffect(effect); | 122 drawState->addCoverageEffect(effect); |
118 drawState->setIdentityViewMatrix(); | 123 drawState->setIdentityViewMatrix(); |
119 drawState->setRenderTarget(rt); | 124 drawState->setRenderTarget(rt); |
120 drawState->setColor(0xff000000); | 125 drawState->setColor(0xff000000); |
121 | 126 |
122 SkRect bounds = rrect.getBounds(); | 127 SkRect bounds = rrect.getBounds(); |
123 bounds.outset(2.f, 2.f); | 128 bounds.outset(2.f, 2.f); |
124 | 129 |
125 tt.target()->drawSimpleRect(bounds); | 130 tt.target()->drawSimpleRect(bounds); |
| 131 } else { |
| 132 drew = false; |
126 } | 133 } |
127 #endif | 134 #endif |
128 } else if (kBW_Clip_Type == fType || kAA_Clip_Type == fType)
{ | 135 } else if (kBW_Clip_Type == fType || kAA_Clip_Type == fType)
{ |
129 bool aaClip = (kAA_Clip_Type == fType); | 136 bool aaClip = (kAA_Clip_Type == fType); |
130 canvas->clipRRect(fRRects[rrectIdx], SkRegion::kReplace_
Op, aaClip); | 137 canvas->clipRRect(fRRects[curRRect], SkRegion::kReplace_
Op, aaClip); |
131 canvas->drawRect(kMaxTileBound, paint); | 138 canvas->drawRect(kMaxTileBound, paint); |
132 } else { | 139 } else { |
133 canvas->drawRRect(fRRects[rrectIdx], paint); | 140 canvas->drawRRect(fRRects[curRRect], paint); |
134 } | 141 } |
135 ++curRRect; | |
136 canvas->restore(); | 142 canvas->restore(); |
| 143 if (drew) { |
| 144 x = x + kTileX; |
| 145 if (x > kImageWidth) { |
| 146 x = 1; |
| 147 y += kTileY; |
| 148 } |
| 149 } |
| 150 } |
| 151 if (x != 1) { |
| 152 y += kTileY; |
137 } | 153 } |
138 } | 154 } |
139 } | 155 } |
140 | 156 |
141 void setUpRRects() { | 157 void setUpRRects() { |
142 // each RRect must fit in a 0x0 -> (kTileX-2)x(kTileY-2) block. These wi
ll be tiled across | 158 // each RRect must fit in a 0x0 -> (kTileX-2)x(kTileY-2) block. These wi
ll be tiled across |
143 // the screen in kTileX x kTileY tiles. The extra empty pixels on each s
ide are for AA. | 159 // the screen in kTileX x kTileY tiles. The extra empty pixels on each s
ide are for AA. |
144 | 160 |
145 // simple cases | 161 // simple cases |
146 fRRects[0].setRect(SkRect::MakeWH(kTileX-2, kTileY-2)); | 162 fRRects[0].setRect(SkRect::MakeWH(kTileX-2, kTileY-2)); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 | 240 |
225 DEF_GM( return new RRectGM(RRectGM::kAA_Draw_Type); ) | 241 DEF_GM( return new RRectGM(RRectGM::kAA_Draw_Type); ) |
226 DEF_GM( return new RRectGM(RRectGM::kBW_Draw_Type); ) | 242 DEF_GM( return new RRectGM(RRectGM::kBW_Draw_Type); ) |
227 DEF_GM( return new RRectGM(RRectGM::kAA_Clip_Type); ) | 243 DEF_GM( return new RRectGM(RRectGM::kAA_Clip_Type); ) |
228 DEF_GM( return new RRectGM(RRectGM::kBW_Clip_Type); ) | 244 DEF_GM( return new RRectGM(RRectGM::kBW_Clip_Type); ) |
229 #if SK_SUPPORT_GPU | 245 #if SK_SUPPORT_GPU |
230 DEF_GM( return new RRectGM(RRectGM::kEffect_Type); ) | 246 DEF_GM( return new RRectGM(RRectGM::kEffect_Type); ) |
231 #endif | 247 #endif |
232 | 248 |
233 } | 249 } |
OLD | NEW |