OLD | NEW |
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 #include "GrBatchTest.h" | 8 #include "GrBatchTest.h" |
9 #include "GrColor.h" | 9 #include "GrColor.h" |
10 #include "GrDrawContext.h" | 10 #include "GrDrawContext.h" |
11 #include "GrDrawContextPriv.h" | 11 #include "GrDrawContextPriv.h" |
12 #include "GrDrawingManager.h" | 12 #include "GrDrawingManager.h" |
13 #include "GrOvalRenderer.h" | 13 #include "GrOvalRenderer.h" |
14 #include "GrPathRenderer.h" | 14 #include "GrPathRenderer.h" |
15 #include "GrRenderTarget.h" | 15 #include "GrRenderTarget.h" |
16 #include "GrRenderTargetPriv.h" | 16 #include "GrRenderTargetPriv.h" |
17 #include "GrResourceProvider.h" | 17 #include "GrResourceProvider.h" |
18 #include "SkSurfacePriv.h" | 18 #include "SkSurfacePriv.h" |
19 | 19 |
20 #include "batches/GrBatch.h" | 20 #include "batches/GrBatch.h" |
| 21 #include "batches/GrClearBatch.h" |
21 #include "batches/GrDrawAtlasBatch.h" | 22 #include "batches/GrDrawAtlasBatch.h" |
22 #include "batches/GrDrawVerticesBatch.h" | 23 #include "batches/GrDrawVerticesBatch.h" |
23 #include "batches/GrRectBatchFactory.h" | 24 #include "batches/GrRectBatchFactory.h" |
24 #include "batches/GrNinePatch.h" // TODO Factory | 25 #include "batches/GrNinePatch.h" // TODO Factory |
25 | 26 |
26 #include "effects/GrRRectEffect.h" | 27 #include "effects/GrRRectEffect.h" |
27 | 28 |
28 #include "instanced/InstancedRendering.h" | 29 #include "instanced/InstancedRendering.h" |
29 | 30 |
30 #include "text/GrAtlasTextContext.h" | 31 #include "text/GrAtlasTextContext.h" |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 189 |
189 void GrDrawContext::clear(const SkIRect* rect, | 190 void GrDrawContext::clear(const SkIRect* rect, |
190 const GrColor color, | 191 const GrColor color, |
191 bool canIgnoreRect) { | 192 bool canIgnoreRect) { |
192 ASSERT_SINGLE_OWNER | 193 ASSERT_SINGLE_OWNER |
193 RETURN_IF_ABANDONED | 194 RETURN_IF_ABANDONED |
194 SkDEBUGCODE(this->validate();) | 195 SkDEBUGCODE(this->validate();) |
195 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::clear"); | 196 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::clear"); |
196 | 197 |
197 AutoCheckFlush acf(fDrawingManager); | 198 AutoCheckFlush acf(fDrawingManager); |
198 this->getDrawTarget()->clear(rect, color, canIgnoreRect, this); | 199 |
| 200 const SkIRect rtRect = SkIRect::MakeWH(this->width(), this->height()); |
| 201 SkIRect clippedRect; |
| 202 if (!rect || |
| 203 (canIgnoreRect && fContext->caps()->fullClearIsFree()) || |
| 204 rect->contains(rtRect)) { |
| 205 rect = &rtRect; |
| 206 } else { |
| 207 clippedRect = *rect; |
| 208 if (!clippedRect.intersect(rtRect)) { |
| 209 return; |
| 210 } |
| 211 rect = &clippedRect; |
| 212 } |
| 213 |
| 214 if (fContext->caps()->useDrawInsteadOfClear()) { |
| 215 // This works around a driver bug with clear by drawing a rect instead. |
| 216 // The driver will ignore a clear if it is the only thing rendered to a |
| 217 // target before the target is read. |
| 218 if (rect == &rtRect) { |
| 219 this->discard(); |
| 220 } |
| 221 |
| 222 GrPaint paint; |
| 223 paint.setColor4f(GrColor4f::FromGrColor(color)); |
| 224 paint.setXPFactory(GrPorterDuffXPFactory::Make(SkXfermode::kSrc_Mode)); |
| 225 |
| 226 this->drawRect(GrNoClip(), paint, SkMatrix::I(), SkRect::Make(*rect)); |
| 227 } else { |
| 228 sk_sp<GrBatch> batch = GrClearBatch::Make(*rect, color, this->accessRend
erTarget()); |
| 229 this->getDrawTarget()->addBatch(std::move(batch)); |
| 230 } |
199 } | 231 } |
200 | 232 |
201 | 233 |
202 void GrDrawContext::drawPaint(const GrClip& clip, | 234 void GrDrawContext::drawPaint(const GrClip& clip, |
203 const GrPaint& origPaint, | 235 const GrPaint& origPaint, |
204 const SkMatrix& viewMatrix) { | 236 const SkMatrix& viewMatrix) { |
205 ASSERT_SINGLE_OWNER | 237 ASSERT_SINGLE_OWNER |
206 RETURN_IF_ABANDONED | 238 RETURN_IF_ABANDONED |
207 SkDEBUGCODE(this->validate();) | 239 SkDEBUGCODE(this->validate();) |
208 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawPaint"); | 240 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawPaint"); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 // Does the rect bound the RT? | 385 // Does the rect bound the RT? |
354 SkPoint srcSpaceRTQuad[4]; | 386 SkPoint srcSpaceRTQuad[4]; |
355 invM.mapRectToQuad(srcSpaceRTQuad, rtRect); | 387 invM.mapRectToQuad(srcSpaceRTQuad, rtRect); |
356 if (rect_contains_inclusive(rect, srcSpaceRTQuad[0]) && | 388 if (rect_contains_inclusive(rect, srcSpaceRTQuad[0]) && |
357 rect_contains_inclusive(rect, srcSpaceRTQuad[1]) && | 389 rect_contains_inclusive(rect, srcSpaceRTQuad[1]) && |
358 rect_contains_inclusive(rect, srcSpaceRTQuad[2]) && | 390 rect_contains_inclusive(rect, srcSpaceRTQuad[2]) && |
359 rect_contains_inclusive(rect, srcSpaceRTQuad[3])) { | 391 rect_contains_inclusive(rect, srcSpaceRTQuad[3])) { |
360 // Will it blend? | 392 // Will it blend? |
361 GrColor clearColor; | 393 GrColor clearColor; |
362 if (paint.isConstantBlendedColor(&clearColor)) { | 394 if (paint.isConstantBlendedColor(&clearColor)) { |
363 this->getDrawTarget()->clear(nullptr, clearColor, true,
this); | 395 this->clear(nullptr, clearColor, true); |
364 return; | 396 return; |
365 } | 397 } |
366 } | 398 } |
367 } | 399 } |
368 } | 400 } |
369 | 401 |
370 if (this->drawFilledRect(clip, paint, viewMatrix, rect, nullptr)) { | 402 if (this->drawFilledRect(clip, paint, viewMatrix, rect, nullptr)) { |
371 return; | 403 return; |
372 } | 404 } |
373 } else if (stroke.getStyle() == SkStrokeRec::kStroke_Style || | 405 } else if (stroke.getStyle() == SkStrokeRec::kStroke_Style || |
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1146 | 1178 |
1147 void GrDrawContext::drawBatch(const GrPipelineBuilder& pipelineBuilder, const Gr
Clip& clip, | 1179 void GrDrawContext::drawBatch(const GrPipelineBuilder& pipelineBuilder, const Gr
Clip& clip, |
1148 GrDrawBatch* batch) { | 1180 GrDrawBatch* batch) { |
1149 ASSERT_SINGLE_OWNER | 1181 ASSERT_SINGLE_OWNER |
1150 RETURN_IF_ABANDONED | 1182 RETURN_IF_ABANDONED |
1151 SkDEBUGCODE(this->validate();) | 1183 SkDEBUGCODE(this->validate();) |
1152 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch"); | 1184 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch"); |
1153 | 1185 |
1154 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); | 1186 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
1155 } | 1187 } |
OLD | NEW |