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

Side by Side Diff: src/gpu/GrDrawContext.cpp

Issue 1406173003: Loosen requirement that there be only one GrDrawTarget (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix comment Created 5 years, 2 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 | « src/gpu/GrContext.cpp ('k') | src/gpu/GrDrawTarget.h » ('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 /* 2 /*
3 * Copyright 2015 Google Inc. 3 * Copyright 2015 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "GrAtlasTextContext.h" 9 #include "GrAtlasTextContext.h"
10 #include "GrBatchTest.h" 10 #include "GrBatchTest.h"
(...skipping 19 matching lines...) Expand all
30 30
31 class AutoCheckFlush { 31 class AutoCheckFlush {
32 public: 32 public:
33 AutoCheckFlush(GrContext* context) : fContext(context) { SkASSERT(context); } 33 AutoCheckFlush(GrContext* context) : fContext(context) { SkASSERT(context); }
34 ~AutoCheckFlush() { fContext->flushIfNecessary(); } 34 ~AutoCheckFlush() { fContext->flushIfNecessary(); }
35 35
36 private: 36 private:
37 GrContext* fContext; 37 GrContext* fContext;
38 }; 38 };
39 39
40 // In MDB mode the reffing of the 'getLastDrawTarget' call's result allows in-pr ogress
41 // drawTargets to be picked up and added to by drawContexts lower in the call
42 // stack. When this occurs with a closed drawTarget, a new one will be allocated
43 // when the drawContext attempts to use it (via getDrawTarget).
40 GrDrawContext::GrDrawContext(GrContext* context, 44 GrDrawContext::GrDrawContext(GrContext* context,
41 GrRenderTarget* rt, 45 GrRenderTarget* rt,
42 GrDrawTarget* drawTarget,
43 const SkSurfaceProps* surfaceProps) 46 const SkSurfaceProps* surfaceProps)
44 : fContext(context) 47 : fContext(context)
45 , fRenderTarget(rt) 48 , fRenderTarget(rt)
46 , fDrawTarget(SkRef(drawTarget)) 49 , fDrawTarget(SkSafeRef(rt->getLastDrawTarget()))
47 , fTextContext(nullptr) 50 , fTextContext(nullptr)
48 , fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps)) { 51 , fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps)) {
49 SkDEBUGCODE(this->validate();) 52 SkDEBUGCODE(this->validate();)
50 } 53 }
51 54
52 GrDrawContext::~GrDrawContext() {
53 SkSafeUnref(fDrawTarget);
54 }
55
56 #ifdef SK_DEBUG 55 #ifdef SK_DEBUG
57 void GrDrawContext::validate() const { 56 void GrDrawContext::validate() const {
58 SkASSERT(fRenderTarget); 57 SkASSERT(fRenderTarget);
59 ASSERT_OWNED_RESOURCE(fRenderTarget); 58 ASSERT_OWNED_RESOURCE(fRenderTarget);
59
60 if (fDrawTarget && !fDrawTarget->isClosed()) {
61 SkASSERT(fRenderTarget->getLastDrawTarget() == fDrawTarget);
62 }
60 } 63 }
61 #endif 64 #endif
62 65
66 GrDrawContext::~GrDrawContext() {
67 SkSafeUnref(fDrawTarget);
68 }
69
70 GrDrawTarget* GrDrawContext::getDrawTarget() {
71 SkDEBUGCODE(this->validate();)
72
73 if (!fDrawTarget || fDrawTarget->isClosed()) {
74 fDrawTarget = fContext->newDrawTarget(fRenderTarget);
75 fRenderTarget->setLastDrawTarget(fDrawTarget);
76 }
77
78 return fDrawTarget;
79 }
80
63 void GrDrawContext::copySurface(GrSurface* src, const SkIRect& srcRect, const Sk IPoint& dstPoint) { 81 void GrDrawContext::copySurface(GrSurface* src, const SkIRect& srcRect, const Sk IPoint& dstPoint) {
64 RETURN_IF_ABANDONED 82 RETURN_IF_ABANDONED
65 SkDEBUGCODE(this->validate();) 83 SkDEBUGCODE(this->validate();)
66 84
67 fDrawTarget->copySurface(fRenderTarget, src, srcRect, dstPoint); 85 this->getDrawTarget()->copySurface(fRenderTarget, src, srcRect, dstPoint);
68 } 86 }
69 87
70 88
71 void GrDrawContext::drawText(const GrClip& clip, const GrPaint& grPaint, 89 void GrDrawContext::drawText(const GrClip& clip, const GrPaint& grPaint,
72 const SkPaint& skPaint, 90 const SkPaint& skPaint,
73 const SkMatrix& viewMatrix, 91 const SkMatrix& viewMatrix,
74 const char text[], size_t byteLength, 92 const char text[], size_t byteLength,
75 SkScalar x, SkScalar y, const SkIRect& clipBounds) { 93 SkScalar x, SkScalar y, const SkIRect& clipBounds) {
76 RETURN_IF_ABANDONED 94 RETURN_IF_ABANDONED
77 SkDEBUGCODE(this->validate();) 95 SkDEBUGCODE(this->validate();)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 void GrDrawContext::drawPathsFromRange(const GrPipelineBuilder* pipelineBuilder, 137 void GrDrawContext::drawPathsFromRange(const GrPipelineBuilder* pipelineBuilder,
120 const SkMatrix& viewMatrix, 138 const SkMatrix& viewMatrix,
121 const SkMatrix& localMatrix, 139 const SkMatrix& localMatrix,
122 GrColor color, 140 GrColor color,
123 GrPathRange* range, 141 GrPathRange* range,
124 GrPathRangeDraw* draw, 142 GrPathRangeDraw* draw,
125 int /*GrPathRendering::FillType*/ fill) { 143 int /*GrPathRendering::FillType*/ fill) {
126 RETURN_IF_ABANDONED 144 RETURN_IF_ABANDONED
127 SkDEBUGCODE(this->validate();) 145 SkDEBUGCODE(this->validate();)
128 146
129 fDrawTarget->drawPathsFromRange(*pipelineBuilder, viewMatrix, localMatrix, c olor, range, draw, 147 this->getDrawTarget()->drawPathsFromRange(*pipelineBuilder, viewMatrix, loca lMatrix, color,
130 (GrPathRendering::FillType) fill); 148 range, draw, (GrPathRendering::Fil lType) fill);
131 } 149 }
132 150
133 void GrDrawContext::discard() { 151 void GrDrawContext::discard() {
134 RETURN_IF_ABANDONED 152 RETURN_IF_ABANDONED
135 SkDEBUGCODE(this->validate();) 153 SkDEBUGCODE(this->validate();)
136 154
137 AutoCheckFlush acf(fContext); 155 AutoCheckFlush acf(fContext);
138 fDrawTarget->discard(fRenderTarget); 156 this->getDrawTarget()->discard(fRenderTarget);
139 } 157 }
140 158
141 void GrDrawContext::clear(const SkIRect* rect, 159 void GrDrawContext::clear(const SkIRect* rect,
142 const GrColor color, 160 const GrColor color,
143 bool canIgnoreRect) { 161 bool canIgnoreRect) {
144 RETURN_IF_ABANDONED 162 RETURN_IF_ABANDONED
145 SkDEBUGCODE(this->validate();) 163 SkDEBUGCODE(this->validate();)
146 164
147 AutoCheckFlush acf(fContext); 165 AutoCheckFlush acf(fContext);
148 fDrawTarget->clear(rect, color, canIgnoreRect, fRenderTarget); 166 this->getDrawTarget()->clear(rect, color, canIgnoreRect, fRenderTarget);
149 } 167 }
150 168
151 169
152 void GrDrawContext::drawPaint(const GrClip& clip, 170 void GrDrawContext::drawPaint(const GrClip& clip,
153 const GrPaint& origPaint, 171 const GrPaint& origPaint,
154 const SkMatrix& viewMatrix) { 172 const SkMatrix& viewMatrix) {
155 RETURN_IF_ABANDONED 173 RETURN_IF_ABANDONED
156 SkDEBUGCODE(this->validate();) 174 SkDEBUGCODE(this->validate();)
157 175
158 // set rect to be big enough to fill the space, but not super-huge, so we 176 // set rect to be big enough to fill the space, but not super-huge, so we
(...skipping 25 matching lines...) Expand all
184 } else { 202 } else {
185 SkMatrix localMatrix; 203 SkMatrix localMatrix;
186 if (!viewMatrix.invert(&localMatrix)) { 204 if (!viewMatrix.invert(&localMatrix)) {
187 SkDebugf("Could not invert matrix\n"); 205 SkDebugf("Could not invert matrix\n");
188 return; 206 return;
189 } 207 }
190 208
191 AutoCheckFlush acf(fContext); 209 AutoCheckFlush acf(fContext);
192 210
193 GrPipelineBuilder pipelineBuilder(*paint, fRenderTarget, clip); 211 GrPipelineBuilder pipelineBuilder(*paint, fRenderTarget, clip);
194 fDrawTarget->drawNonAARect(pipelineBuilder, 212 this->getDrawTarget()->drawNonAARect(pipelineBuilder,
195 paint->getColor(), 213 paint->getColor(),
196 SkMatrix::I(), 214 SkMatrix::I(),
197 r, 215 r,
198 localMatrix); 216 localMatrix);
199 } 217 }
200 } 218 }
201 219
202 static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& po int) { 220 static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& po int) {
203 return point.fX >= rect.fLeft && point.fX <= rect.fRight && 221 return point.fX >= rect.fLeft && point.fX <= rect.fRight &&
204 point.fY >= rect.fTop && point.fY <= rect.fBottom; 222 point.fY >= rect.fTop && point.fY <= rect.fBottom;
205 } 223 }
206 224
207 void GrDrawContext::drawRect(const GrClip& clip, 225 void GrDrawContext::drawRect(const GrClip& clip,
208 const GrPaint& paint, 226 const GrPaint& paint,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 // Does the rect bound the RT? 264 // Does the rect bound the RT?
247 SkPoint srcSpaceRTQuad[4]; 265 SkPoint srcSpaceRTQuad[4];
248 invM.mapRectToQuad(srcSpaceRTQuad, rtRect); 266 invM.mapRectToQuad(srcSpaceRTQuad, rtRect);
249 if (rect_contains_inclusive(rect, srcSpaceRTQuad[0]) && 267 if (rect_contains_inclusive(rect, srcSpaceRTQuad[0]) &&
250 rect_contains_inclusive(rect, srcSpaceRTQuad[1]) && 268 rect_contains_inclusive(rect, srcSpaceRTQuad[1]) &&
251 rect_contains_inclusive(rect, srcSpaceRTQuad[2]) && 269 rect_contains_inclusive(rect, srcSpaceRTQuad[2]) &&
252 rect_contains_inclusive(rect, srcSpaceRTQuad[3])) { 270 rect_contains_inclusive(rect, srcSpaceRTQuad[3])) {
253 // Will it blend? 271 // Will it blend?
254 GrColor clearColor; 272 GrColor clearColor;
255 if (paint.isConstantBlendedColor(&clearColor)) { 273 if (paint.isConstantBlendedColor(&clearColor)) {
256 fDrawTarget->clear(nullptr, clearColor, true, fRenderTarget) ; 274 this->getDrawTarget()->clear(nullptr, clearColor, true, fRen derTarget);
257 return; 275 return;
258 } 276 }
259 } 277 }
260 } 278 }
261 } 279 }
262 280
263 GrColor color = paint.getColor(); 281 GrColor color = paint.getColor();
264 bool needAA = paint.isAntiAlias() && 282 bool needAA = paint.isAntiAlias() &&
265 !pipelineBuilder.getRenderTarget()->isUnifiedMultisampled(); 283 !pipelineBuilder.getRenderTarget()->isUnifiedMultisampled();
266 284
267 // The fill path can handle rotation but not skew 285 // The fill path can handle rotation but not skew
268 // The stroke path needs the rect to remain axis aligned (no rotation or ske w) 286 // The stroke path needs the rect to remain axis aligned (no rotation or ske w)
269 // None of our AA draw rect calls can handle perspective yet 287 // None of our AA draw rect calls can handle perspective yet
270 bool canApplyAA = width >=0 ? viewMatrix.rectStaysRect() : viewMatrix.preser vesRightAngles(); 288 bool canApplyAA = width >=0 ? viewMatrix.rectStaysRect() : viewMatrix.preser vesRightAngles();
271 289
272 if (needAA && canApplyAA) { 290 if (needAA && canApplyAA) {
273 SkASSERT(!viewMatrix.hasPerspective()); 291 SkASSERT(!viewMatrix.hasPerspective());
274 SkAutoTUnref<GrDrawBatch> batch; 292 SkAutoTUnref<GrDrawBatch> batch;
275 if (width >= 0) { 293 if (width >= 0) {
276 batch.reset(GrRectBatchFactory::CreateAAStroke(color, viewMatrix, re ct, *strokeInfo)); 294 batch.reset(GrRectBatchFactory::CreateAAStroke(color, viewMatrix, re ct, *strokeInfo));
277 } else { 295 } else {
278 SkRect devBoundRect; 296 SkRect devBoundRect;
279 viewMatrix.mapRect(&devBoundRect, rect); 297 viewMatrix.mapRect(&devBoundRect, rect);
280 batch.reset(GrRectBatchFactory::CreateAAFill(color, viewMatrix, rect , devBoundRect)); 298 batch.reset(GrRectBatchFactory::CreateAAFill(color, viewMatrix, rect , devBoundRect));
281 } 299 }
282 fDrawTarget->drawBatch(pipelineBuilder, batch); 300 this->getDrawTarget()->drawBatch(pipelineBuilder, batch);
283 return; 301 return;
284 } 302 }
285 303
286 if (width >= 0) { 304 if (width >= 0) {
287 // Non-AA hairlines are snapped to pixel centers to make which pixels ar e hit deterministic 305 // Non-AA hairlines are snapped to pixel centers to make which pixels ar e hit deterministic
288 bool snapToPixelCenters = (0 == width && !fRenderTarget->isUnifiedMultis ampled()); 306 bool snapToPixelCenters = (0 == width && !fRenderTarget->isUnifiedMultis ampled());
289 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateNonAAStroke( 307 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateNonAAStroke(
290 color, viewMatrix, rect, width, snapToPi xelCenters)); 308 color, viewMatrix, rect, width, snapToPi xelCenters));
291 309
292 // Depending on sub-pixel coordinates and the particular GPU, we may los e a corner of 310 // Depending on sub-pixel coordinates and the particular GPU, we may los e a corner of
293 // hairline rects. We jam all the vertices to pixel centers to avoid thi s, but not when MSAA 311 // hairline rects. We jam all the vertices to pixel centers to avoid thi s, but not when MSAA
294 // is enabled because it can cause ugly artifacts. 312 // is enabled because it can cause ugly artifacts.
295 pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCenters_ Flag, 313 pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCenters_ Flag,
296 snapToPixelCenters); 314 snapToPixelCenters);
297 fDrawTarget->drawBatch(pipelineBuilder, batch); 315 this->getDrawTarget()->drawBatch(pipelineBuilder, batch);
298 } else { 316 } else {
299 // filled BW rect 317 // filled BW rect
300 fDrawTarget->drawNonAARect(pipelineBuilder, color, viewMatrix, rect); 318 this->getDrawTarget()->drawNonAARect(pipelineBuilder, color, viewMatrix, rect);
301 } 319 }
302 } 320 }
303 321
304 void GrDrawContext::drawNonAARectToRect(const GrClip& clip, 322 void GrDrawContext::drawNonAARectToRect(const GrClip& clip,
305 const GrPaint& paint, 323 const GrPaint& paint,
306 const SkMatrix& viewMatrix, 324 const SkMatrix& viewMatrix,
307 const SkRect& rectToDraw, 325 const SkRect& rectToDraw,
308 const SkRect& localRect) { 326 const SkRect& localRect) {
309 RETURN_IF_ABANDONED 327 RETURN_IF_ABANDONED
310 SkDEBUGCODE(this->validate();) 328 SkDEBUGCODE(this->validate();)
311 329
312 AutoCheckFlush acf(fContext); 330 AutoCheckFlush acf(fContext);
313 331
314 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); 332 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip);
315 fDrawTarget->drawNonAARect(pipelineBuilder, 333 this->getDrawTarget()->drawNonAARect(pipelineBuilder,
316 paint.getColor(), 334 paint.getColor(),
317 viewMatrix, 335 viewMatrix,
318 rectToDraw, 336 rectToDraw,
319 localRect); 337 localRect);
320 } 338 }
321 339
322 void GrDrawContext::drawNonAARectWithLocalMatrix(const GrClip& clip, 340 void GrDrawContext::drawNonAARectWithLocalMatrix(const GrClip& clip,
323 const GrPaint& paint, 341 const GrPaint& paint,
324 const SkMatrix& viewMatrix, 342 const SkMatrix& viewMatrix,
325 const SkRect& rectToDraw, 343 const SkRect& rectToDraw,
326 const SkMatrix& localMatrix) { 344 const SkMatrix& localMatrix) {
327 RETURN_IF_ABANDONED 345 RETURN_IF_ABANDONED
328 SkDEBUGCODE(this->validate();) 346 SkDEBUGCODE(this->validate();)
329 347
330 AutoCheckFlush acf(fContext); 348 AutoCheckFlush acf(fContext);
331 349
332 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); 350 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip);
333 fDrawTarget->drawNonAARect(pipelineBuilder, 351 this->getDrawTarget()->drawNonAARect(pipelineBuilder,
334 paint.getColor(), 352 paint.getColor(),
335 viewMatrix, 353 viewMatrix,
336 rectToDraw, 354 rectToDraw,
337 localMatrix); 355 localMatrix);
338 } 356 }
339 357
340 void GrDrawContext::drawVertices(const GrClip& clip, 358 void GrDrawContext::drawVertices(const GrClip& clip,
341 const GrPaint& paint, 359 const GrPaint& paint,
342 const SkMatrix& viewMatrix, 360 const SkMatrix& viewMatrix,
343 GrPrimitiveType primitiveType, 361 GrPrimitiveType primitiveType,
344 int vertexCount, 362 int vertexCount,
345 const SkPoint positions[], 363 const SkPoint positions[],
346 const SkPoint texCoords[], 364 const SkPoint texCoords[],
347 const GrColor colors[], 365 const GrColor colors[],
(...skipping 21 matching lines...) Expand all
369 bounds.outset(0.5f, 0.5f); 387 bounds.outset(0.5f, 0.5f);
370 } 388 }
371 389
372 GrDrawVerticesBatch::Geometry geometry; 390 GrDrawVerticesBatch::Geometry geometry;
373 geometry.fColor = paint.getColor(); 391 geometry.fColor = paint.getColor();
374 SkAutoTUnref<GrDrawBatch> batch(GrDrawVerticesBatch::Create(geometry, primit iveType, viewMatrix, 392 SkAutoTUnref<GrDrawBatch> batch(GrDrawVerticesBatch::Create(geometry, primit iveType, viewMatrix,
375 positions, verte xCount, indices, 393 positions, verte xCount, indices,
376 indexCount, colo rs, texCoords, 394 indexCount, colo rs, texCoords,
377 bounds)); 395 bounds));
378 396
379 fDrawTarget->drawBatch(pipelineBuilder, batch); 397 this->getDrawTarget()->drawBatch(pipelineBuilder, batch);
380 } 398 }
381 399
382 /////////////////////////////////////////////////////////////////////////////// 400 ///////////////////////////////////////////////////////////////////////////////
383 401
384 void GrDrawContext::drawAtlas(const GrClip& clip, 402 void GrDrawContext::drawAtlas(const GrClip& clip,
385 const GrPaint& paint, 403 const GrPaint& paint,
386 const SkMatrix& viewMatrix, 404 const SkMatrix& viewMatrix,
387 int spriteCount, 405 int spriteCount,
388 const SkRSXform xform[], 406 const SkRSXform xform[],
389 const SkRect texRect[], 407 const SkRect texRect[],
390 const SkColor colors[]) { 408 const SkColor colors[]) {
391 RETURN_IF_ABANDONED 409 RETURN_IF_ABANDONED
392 SkDEBUGCODE(this->validate();) 410 SkDEBUGCODE(this->validate();)
393 411
394 AutoCheckFlush acf(fContext); 412 AutoCheckFlush acf(fContext);
395 413
396 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); 414 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip);
397 415
398 GrDrawAtlasBatch::Geometry geometry; 416 GrDrawAtlasBatch::Geometry geometry;
399 geometry.fColor = paint.getColor(); 417 geometry.fColor = paint.getColor();
400 SkAutoTUnref<GrDrawBatch> batch(GrDrawAtlasBatch::Create(geometry, viewMatri x, spriteCount, 418 SkAutoTUnref<GrDrawBatch> batch(GrDrawAtlasBatch::Create(geometry, viewMatri x, spriteCount,
401 xform, texRect, col ors)); 419 xform, texRect, col ors));
402 420
403 fDrawTarget->drawBatch(pipelineBuilder, batch); 421 this->getDrawTarget()->drawBatch(pipelineBuilder, batch);
404 } 422 }
405 423
406 /////////////////////////////////////////////////////////////////////////////// 424 ///////////////////////////////////////////////////////////////////////////////
407 425
408 void GrDrawContext::drawRRect(const GrClip& clip, 426 void GrDrawContext::drawRRect(const GrClip& clip,
409 const GrPaint& paint, 427 const GrPaint& paint,
410 const SkMatrix& viewMatrix, 428 const SkMatrix& viewMatrix,
411 const SkRRect& rrect, 429 const SkRRect& rrect,
412 const GrStrokeInfo& strokeInfo) { 430 const GrStrokeInfo& strokeInfo) {
413 RETURN_IF_ABANDONED 431 RETURN_IF_ABANDONED
414 SkDEBUGCODE(this->validate();) 432 SkDEBUGCODE(this->validate();)
415 433
416 if (rrect.isEmpty()) { 434 if (rrect.isEmpty()) {
417 return; 435 return;
418 } 436 }
419 437
420 if (strokeInfo.isDashed()) { 438 if (strokeInfo.isDashed()) {
421 SkPath path; 439 SkPath path;
422 path.setIsVolatile(true); 440 path.setIsVolatile(true);
423 path.addRRect(rrect); 441 path.addRRect(rrect);
424 this->drawPath(clip, paint, viewMatrix, path, strokeInfo); 442 this->drawPath(clip, paint, viewMatrix, path, strokeInfo);
425 return; 443 return;
426 } 444 }
427 445
428 AutoCheckFlush acf(fContext); 446 AutoCheckFlush acf(fContext);
429 447
430 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); 448 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip);
431 GrColor color = paint.getColor(); 449 GrColor color = paint.getColor();
432 450
433 if (!GrOvalRenderer::DrawRRect(fDrawTarget, 451 if (!GrOvalRenderer::DrawRRect(this->getDrawTarget(),
434 pipelineBuilder, 452 pipelineBuilder,
435 color, 453 color,
436 viewMatrix, 454 viewMatrix,
437 paint.isAntiAlias(), 455 paint.isAntiAlias(),
438 rrect, 456 rrect,
439 strokeInfo)) { 457 strokeInfo)) {
440 SkPath path; 458 SkPath path;
441 path.setIsVolatile(true); 459 path.setIsVolatile(true);
442 path.addRRect(rrect); 460 path.addRRect(rrect);
443 this->internalDrawPath(fDrawTarget, &pipelineBuilder, viewMatrix, color, 461 this->internalDrawPath(this->getDrawTarget(), &pipelineBuilder, viewMatr ix, color,
444 paint.isAntiAlias(), path, strokeInfo); 462 paint.isAntiAlias(), path, strokeInfo);
445 } 463 }
446 } 464 }
447 465
448 /////////////////////////////////////////////////////////////////////////////// 466 ///////////////////////////////////////////////////////////////////////////////
449 467
450 void GrDrawContext::drawDRRect(const GrClip& clip, 468 void GrDrawContext::drawDRRect(const GrClip& clip,
451 const GrPaint& paint, 469 const GrPaint& paint,
452 const SkMatrix& viewMatrix, 470 const SkMatrix& viewMatrix,
453 const SkRRect& outer, 471 const SkRRect& outer,
454 const SkRRect& inner) { 472 const SkRRect& inner) {
455 RETURN_IF_ABANDONED 473 RETURN_IF_ABANDONED
456 SkDEBUGCODE(this->validate();) 474 SkDEBUGCODE(this->validate();)
457 475
458 if (outer.isEmpty()) { 476 if (outer.isEmpty()) {
459 return; 477 return;
460 } 478 }
461 479
462 AutoCheckFlush acf(fContext); 480 AutoCheckFlush acf(fContext);
463 481
464 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); 482 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip);
465 GrColor color = paint.getColor(); 483 GrColor color = paint.getColor();
466 if (!GrOvalRenderer::DrawDRRect(fDrawTarget, 484 if (!GrOvalRenderer::DrawDRRect(this->getDrawTarget(),
467 pipelineBuilder, 485 pipelineBuilder,
468 color, 486 color,
469 viewMatrix, 487 viewMatrix,
470 paint.isAntiAlias(), 488 paint.isAntiAlias(),
471 outer, 489 outer,
472 inner)) { 490 inner)) {
473 SkPath path; 491 SkPath path;
474 path.setIsVolatile(true); 492 path.setIsVolatile(true);
475 path.addRRect(inner); 493 path.addRRect(inner);
476 path.addRRect(outer); 494 path.addRRect(outer);
477 path.setFillType(SkPath::kEvenOdd_FillType); 495 path.setFillType(SkPath::kEvenOdd_FillType);
478 496
479 GrStrokeInfo fillRec(SkStrokeRec::kFill_InitStyle); 497 GrStrokeInfo fillRec(SkStrokeRec::kFill_InitStyle);
480 this->internalDrawPath(fDrawTarget, &pipelineBuilder, viewMatrix, color, 498 this->internalDrawPath(this->getDrawTarget(), &pipelineBuilder, viewMatr ix, color,
481 paint.isAntiAlias(), path, fillRec); 499 paint.isAntiAlias(), path, fillRec);
482 } 500 }
483 } 501 }
484 502
485 /////////////////////////////////////////////////////////////////////////////// 503 ///////////////////////////////////////////////////////////////////////////////
486 504
487 void GrDrawContext::drawOval(const GrClip& clip, 505 void GrDrawContext::drawOval(const GrClip& clip,
488 const GrPaint& paint, 506 const GrPaint& paint,
489 const SkMatrix& viewMatrix, 507 const SkMatrix& viewMatrix,
490 const SkRect& oval, 508 const SkRect& oval,
(...skipping 11 matching lines...) Expand all
502 path.addOval(oval); 520 path.addOval(oval);
503 this->drawPath(clip, paint, viewMatrix, path, strokeInfo); 521 this->drawPath(clip, paint, viewMatrix, path, strokeInfo);
504 return; 522 return;
505 } 523 }
506 524
507 AutoCheckFlush acf(fContext); 525 AutoCheckFlush acf(fContext);
508 526
509 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); 527 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip);
510 GrColor color = paint.getColor(); 528 GrColor color = paint.getColor();
511 529
512 if (!GrOvalRenderer::DrawOval(fDrawTarget, 530 if (!GrOvalRenderer::DrawOval(this->getDrawTarget(),
513 pipelineBuilder, 531 pipelineBuilder,
514 color, 532 color,
515 viewMatrix, 533 viewMatrix,
516 paint.isAntiAlias(), 534 paint.isAntiAlias(),
517 oval, 535 oval,
518 strokeInfo)) { 536 strokeInfo)) {
519 SkPath path; 537 SkPath path;
520 path.setIsVolatile(true); 538 path.setIsVolatile(true);
521 path.addOval(oval); 539 path.addOval(oval);
522 this->internalDrawPath(fDrawTarget, &pipelineBuilder, viewMatrix, color, 540 this->internalDrawPath(this->getDrawTarget(), &pipelineBuilder, viewMatr ix, color,
523 paint.isAntiAlias(), path, strokeInfo); 541 paint.isAntiAlias(), path, strokeInfo);
524 } 542 }
525 } 543 }
526 544
527 // Can 'path' be drawn as a pair of filled nested rectangles? 545 // Can 'path' be drawn as a pair of filled nested rectangles?
528 static bool is_nested_rects(const SkMatrix& viewMatrix, 546 static bool is_nested_rects(const SkMatrix& viewMatrix,
529 const SkPath& path, 547 const SkPath& path,
530 const SkStrokeRec& stroke, 548 const SkStrokeRec& stroke,
531 SkRect rects[2]) { 549 SkRect rects[2]) {
532 SkASSERT(stroke.isFillStyle()); 550 SkASSERT(stroke.isFillStyle());
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 } 593 }
576 594
577 void GrDrawContext::drawBatch(const GrClip& clip, 595 void GrDrawContext::drawBatch(const GrClip& clip,
578 const GrPaint& paint, GrDrawBatch* batch) { 596 const GrPaint& paint, GrDrawBatch* batch) {
579 RETURN_IF_ABANDONED 597 RETURN_IF_ABANDONED
580 SkDEBUGCODE(this->validate();) 598 SkDEBUGCODE(this->validate();)
581 599
582 AutoCheckFlush acf(fContext); 600 AutoCheckFlush acf(fContext);
583 601
584 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); 602 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip);
585 fDrawTarget->drawBatch(pipelineBuilder, batch); 603 this->getDrawTarget()->drawBatch(pipelineBuilder, batch);
586 } 604 }
587 605
588 void GrDrawContext::drawPath(const GrClip& clip, 606 void GrDrawContext::drawPath(const GrClip& clip,
589 const GrPaint& paint, 607 const GrPaint& paint,
590 const SkMatrix& viewMatrix, 608 const SkMatrix& viewMatrix,
591 const SkPath& path, 609 const SkPath& path,
592 const GrStrokeInfo& strokeInfo) { 610 const GrStrokeInfo& strokeInfo) {
593 RETURN_IF_ABANDONED 611 RETURN_IF_ABANDONED
594 SkDEBUGCODE(this->validate();) 612 SkDEBUGCODE(this->validate();)
595 613
(...skipping 18 matching lines...) Expand all
614 bool useCoverageAA = paint.isAntiAlias() && 632 bool useCoverageAA = paint.isAntiAlias() &&
615 !pipelineBuilder.getRenderTarget()->isUnifiedMultisampled(); 633 !pipelineBuilder.getRenderTarget()->isUnifiedMultisampled();
616 634
617 if (useCoverageAA && strokeInfo.getWidth() < 0 && !path.isConvex()) { 635 if (useCoverageAA && strokeInfo.getWidth() < 0 && !path.isConvex()) {
618 // Concave AA paths are expensive - try to avoid them for special ca ses 636 // Concave AA paths are expensive - try to avoid them for special ca ses
619 SkRect rects[2]; 637 SkRect rects[2];
620 638
621 if (is_nested_rects(viewMatrix, path, strokeInfo, rects)) { 639 if (is_nested_rects(viewMatrix, path, strokeInfo, rects)) {
622 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateAAFill NestedRects( 640 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateAAFill NestedRects(
623 color, viewMatrix, rects)); 641 color, viewMatrix, rects));
624 fDrawTarget->drawBatch(pipelineBuilder, batch); 642 this->getDrawTarget()->drawBatch(pipelineBuilder, batch);
625 return; 643 return;
626 } 644 }
627 } 645 }
628 SkRect ovalRect; 646 SkRect ovalRect;
629 bool isOval = path.isOval(&ovalRect); 647 bool isOval = path.isOval(&ovalRect);
630 648
631 if (isOval && !path.isInverseFillType()) { 649 if (isOval && !path.isInverseFillType()) {
632 if (GrOvalRenderer::DrawOval(fDrawTarget, 650 if (GrOvalRenderer::DrawOval(this->getDrawTarget(),
633 pipelineBuilder, 651 pipelineBuilder,
634 color, 652 color,
635 viewMatrix, 653 viewMatrix,
636 paint.isAntiAlias(), 654 paint.isAntiAlias(),
637 ovalRect, 655 ovalRect,
638 strokeInfo)) { 656 strokeInfo)) {
639 return; 657 return;
640 } 658 }
641 } 659 }
642 } 660 }
643 this->internalDrawPath(fDrawTarget, &pipelineBuilder, viewMatrix, color, pai nt.isAntiAlias(), 661 this->internalDrawPath(this->getDrawTarget(), &pipelineBuilder, viewMatrix, color,
644 path, strokeInfo); 662 paint.isAntiAlias(), path, strokeInfo);
645 } 663 }
646 664
647 void GrDrawContext::internalDrawPath(GrDrawTarget* target, 665 void GrDrawContext::internalDrawPath(GrDrawTarget* target,
648 GrPipelineBuilder* pipelineBuilder, 666 GrPipelineBuilder* pipelineBuilder,
649 const SkMatrix& viewMatrix, 667 const SkMatrix& viewMatrix,
650 GrColor color, 668 GrColor color,
651 bool useAA, 669 bool useAA,
652 const SkPath& path, 670 const SkPath& path,
653 const GrStrokeInfo& strokeInfo) { 671 const GrStrokeInfo& strokeInfo) {
654 RETURN_IF_ABANDONED 672 RETURN_IF_ABANDONED
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 args.fPath = pathPtr; 747 args.fPath = pathPtr;
730 args.fStroke = strokeInfoPtr; 748 args.fStroke = strokeInfoPtr;
731 args.fAntiAlias = useCoverageAA; 749 args.fAntiAlias = useCoverageAA;
732 pr->drawPath(args); 750 pr->drawPath(args);
733 } 751 }
734 752
735 void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrDrawBatch* b atch) { 753 void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrDrawBatch* b atch) {
736 RETURN_IF_ABANDONED 754 RETURN_IF_ABANDONED
737 SkDEBUGCODE(this->validate();) 755 SkDEBUGCODE(this->validate();)
738 756
739 fDrawTarget->drawBatch(*pipelineBuilder, batch); 757 this->getDrawTarget()->drawBatch(*pipelineBuilder, batch);
740 } 758 }
OLDNEW
« no previous file with comments | « src/gpu/GrContext.cpp ('k') | src/gpu/GrDrawTarget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698