| OLD | NEW |
| 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" |
| 11 #include "GrColor.h" | 11 #include "GrColor.h" |
| 12 #include "GrDrawContext.h" | 12 #include "GrDrawContext.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 "GrStencilAndCoverTextContext.h" | 18 #include "GrStencilAndCoverTextContext.h" |
| 19 #include "SkSurfacePriv.h" | 19 #include "SkSurfacePriv.h" |
| 20 | 20 |
| 21 #include "batches/GrBatch.h" | 21 #include "batches/GrBatch.h" |
| 22 #include "batches/GrDrawAtlasBatch.h" | 22 #include "batches/GrDrawAtlasBatch.h" |
| 23 #include "batches/GrDrawVerticesBatch.h" | 23 #include "batches/GrDrawVerticesBatch.h" |
| 24 #include "batches/GrRectBatchFactory.h" | 24 #include "batches/GrRectBatchFactory.h" |
| 25 | 25 |
| 26 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == fContext) | 26 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == fDrawingM
gr->getContext()) |
| 27 #define RETURN_IF_ABANDONED if (fContext->abandoned()) { return; } | 27 #define RETURN_IF_ABANDONED if (fDrawingMgr->abandoned()) { return; } |
| 28 #define RETURN_FALSE_IF_ABANDONED if (fContext->abandoned()) { return false; } | 28 #define RETURN_FALSE_IF_ABANDONED if (fDrawingMgr->abandoned()) { return false;
} |
| 29 #define RETURN_NULL_IF_ABANDONED if (fContext->abandoned()) { return nullptr;
} | 29 #define RETURN_NULL_IF_ABANDONED if (fDrawingMgr->abandoned()) { return nullpt
r; } |
| 30 | 30 |
| 31 class AutoCheckFlush { | 31 class AutoCheckFlush { |
| 32 public: | 32 public: |
| 33 AutoCheckFlush(GrContext* context) : fContext(context) { SkASSERT(context);
} | 33 AutoCheckFlush(GrContext::DrawingMgr* drawingMgr) : fDrawingMgr(drawingMgr)
{ |
| 34 ~AutoCheckFlush() { fContext->flushIfNecessary(); } | 34 SkASSERT(fDrawingMgr); |
| 35 } |
| 36 ~AutoCheckFlush() { fDrawingMgr->getContext()->flushIfNecessary(); } |
| 35 | 37 |
| 36 private: | 38 private: |
| 37 GrContext* fContext; | 39 GrContext::DrawingMgr* fDrawingMgr; |
| 38 }; | 40 }; |
| 39 | 41 |
| 40 // In MDB mode the reffing of the 'getLastDrawTarget' call's result allows in-pr
ogress | 42 // 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 | 43 // 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 | 44 // stack. When this occurs with a closed drawTarget, a new one will be allocated |
| 43 // when the drawContext attempts to use it (via getDrawTarget). | 45 // when the drawContext attempts to use it (via getDrawTarget). |
| 44 GrDrawContext::GrDrawContext(GrContext* context, | 46 GrDrawContext::GrDrawContext(GrContext::DrawingMgr* drawingMgr, |
| 45 GrRenderTarget* rt, | 47 GrRenderTarget* rt, |
| 46 const SkSurfaceProps* surfaceProps) | 48 const SkSurfaceProps* surfaceProps) |
| 47 : fContext(context) | 49 : fDrawingMgr(drawingMgr) |
| 48 , fRenderTarget(rt) | 50 , fRenderTarget(rt) |
| 49 , fDrawTarget(SkSafeRef(rt->getLastDrawTarget())) | 51 , fDrawTarget(SkSafeRef(rt->getLastDrawTarget())) |
| 50 , fTextContext(nullptr) | 52 , fTextContext(nullptr) |
| 51 , fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps)) { | 53 , fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps)) { |
| 52 SkDEBUGCODE(this->validate();) | 54 SkDEBUGCODE(this->validate();) |
| 53 } | 55 } |
| 54 | 56 |
| 55 #ifdef SK_DEBUG | 57 #ifdef SK_DEBUG |
| 56 void GrDrawContext::validate() const { | 58 void GrDrawContext::validate() const { |
| 57 SkASSERT(fRenderTarget); | 59 SkASSERT(fRenderTarget); |
| 58 ASSERT_OWNED_RESOURCE(fRenderTarget); | 60 ASSERT_OWNED_RESOURCE(fRenderTarget); |
| 59 | 61 |
| 60 if (fDrawTarget && !fDrawTarget->isClosed()) { | 62 if (fDrawTarget && !fDrawTarget->isClosed()) { |
| 61 SkASSERT(fRenderTarget->getLastDrawTarget() == fDrawTarget); | 63 SkASSERT(fRenderTarget->getLastDrawTarget() == fDrawTarget); |
| 62 } | 64 } |
| 63 } | 65 } |
| 64 #endif | 66 #endif |
| 65 | 67 |
| 66 GrDrawContext::~GrDrawContext() { | 68 GrDrawContext::~GrDrawContext() { |
| 67 SkSafeUnref(fDrawTarget); | 69 SkSafeUnref(fDrawTarget); |
| 68 } | 70 } |
| 69 | 71 |
| 70 GrDrawTarget* GrDrawContext::getDrawTarget() { | 72 GrDrawTarget* GrDrawContext::getDrawTarget() { |
| 71 SkDEBUGCODE(this->validate();) | 73 SkDEBUGCODE(this->validate();) |
| 72 | 74 |
| 73 if (!fDrawTarget || fDrawTarget->isClosed()) { | 75 if (!fDrawTarget || fDrawTarget->isClosed()) { |
| 74 fDrawTarget = fContext->newDrawTarget(fRenderTarget); | 76 fDrawTarget = fDrawingMgr->newDrawTarget(fRenderTarget); |
| 75 fRenderTarget->setLastDrawTarget(fDrawTarget); | 77 fRenderTarget->setLastDrawTarget(fDrawTarget); |
| 76 } | 78 } |
| 77 | 79 |
| 78 return fDrawTarget; | 80 return fDrawTarget; |
| 79 } | 81 } |
| 80 | 82 |
| 81 void GrDrawContext::copySurface(GrSurface* src, const SkIRect& srcRect, const Sk
IPoint& dstPoint) { | 83 void GrDrawContext::copySurface(GrSurface* src, const SkIRect& srcRect, const Sk
IPoint& dstPoint) { |
| 82 RETURN_IF_ABANDONED | 84 RETURN_IF_ABANDONED |
| 83 SkDEBUGCODE(this->validate();) | 85 SkDEBUGCODE(this->validate();) |
| 84 | 86 |
| 85 this->getDrawTarget()->copySurface(fRenderTarget, src, srcRect, dstPoint); | 87 this->getDrawTarget()->copySurface(fRenderTarget, src, srcRect, dstPoint); |
| 86 } | 88 } |
| 87 | 89 |
| 88 | 90 |
| 89 void GrDrawContext::drawText(const GrClip& clip, const GrPaint& grPaint, | 91 void GrDrawContext::drawText(const GrClip& clip, const GrPaint& grPaint, |
| 90 const SkPaint& skPaint, | 92 const SkPaint& skPaint, |
| 91 const SkMatrix& viewMatrix, | 93 const SkMatrix& viewMatrix, |
| 92 const char text[], size_t byteLength, | 94 const char text[], size_t byteLength, |
| 93 SkScalar x, SkScalar y, const SkIRect& clipBounds)
{ | 95 SkScalar x, SkScalar y, const SkIRect& clipBounds)
{ |
| 94 RETURN_IF_ABANDONED | 96 RETURN_IF_ABANDONED |
| 95 SkDEBUGCODE(this->validate();) | 97 SkDEBUGCODE(this->validate();) |
| 96 | 98 |
| 97 if (!fTextContext) { | 99 if (!fTextContext) { |
| 98 fTextContext = fContext->textContext(fSurfaceProps, fRenderTarget); | 100 fTextContext = fDrawingMgr->textContext(fSurfaceProps, fRenderTarget); |
| 99 } | 101 } |
| 100 | 102 |
| 101 fTextContext->drawText(this, fRenderTarget, clip, grPaint, skPaint, viewMatr
ix, | 103 fTextContext->drawText(this, fRenderTarget, clip, grPaint, skPaint, viewMatr
ix, |
| 102 text, byteLength, x, y, clipBounds); | 104 text, byteLength, x, y, clipBounds); |
| 103 | 105 |
| 104 } | 106 } |
| 105 void GrDrawContext::drawPosText(const GrClip& clip, const GrPaint& grPaint, | 107 void GrDrawContext::drawPosText(const GrClip& clip, const GrPaint& grPaint, |
| 106 const SkPaint& skPaint, | 108 const SkPaint& skPaint, |
| 107 const SkMatrix& viewMatrix, | 109 const SkMatrix& viewMatrix, |
| 108 const char text[], size_t byteLength, | 110 const char text[], size_t byteLength, |
| 109 const SkScalar pos[], int scalarsPerPosition, | 111 const SkScalar pos[], int scalarsPerPosition, |
| 110 const SkPoint& offset, const SkIRect& clipBounds
) { | 112 const SkPoint& offset, const SkIRect& clipBounds
) { |
| 111 RETURN_IF_ABANDONED | 113 RETURN_IF_ABANDONED |
| 112 SkDEBUGCODE(this->validate();) | 114 SkDEBUGCODE(this->validate();) |
| 113 | 115 |
| 114 if (!fTextContext) { | 116 if (!fTextContext) { |
| 115 fTextContext = fContext->textContext(fSurfaceProps, fRenderTarget); | 117 fTextContext = fDrawingMgr->textContext(fSurfaceProps, fRenderTarget); |
| 116 } | 118 } |
| 117 | 119 |
| 118 fTextContext->drawPosText(this, fRenderTarget, clip, grPaint, skPaint, viewM
atrix, text, byteLength, | 120 fTextContext->drawPosText(this, fRenderTarget, clip, grPaint, skPaint, viewM
atrix, text, byteLength, |
| 119 pos, scalarsPerPosition, offset, clipBounds); | 121 pos, scalarsPerPosition, offset, clipBounds); |
| 120 | 122 |
| 121 } | 123 } |
| 122 void GrDrawContext::drawTextBlob(const GrClip& clip, const SkPaint& skPaint, | 124 void GrDrawContext::drawTextBlob(const GrClip& clip, const SkPaint& skPaint, |
| 123 const SkMatrix& viewMatrix, const SkTextBlob* b
lob, | 125 const SkMatrix& viewMatrix, const SkTextBlob* b
lob, |
| 124 SkScalar x, SkScalar y, | 126 SkScalar x, SkScalar y, |
| 125 SkDrawFilter* filter, const SkIRect& clipBounds
) { | 127 SkDrawFilter* filter, const SkIRect& clipBounds
) { |
| 126 RETURN_IF_ABANDONED | 128 RETURN_IF_ABANDONED |
| 127 SkDEBUGCODE(this->validate();) | 129 SkDEBUGCODE(this->validate();) |
| 128 | 130 |
| 129 if (!fTextContext) { | 131 if (!fTextContext) { |
| 130 fTextContext = fContext->textContext(fSurfaceProps, fRenderTarget); | 132 fTextContext = fDrawingMgr->textContext(fSurfaceProps, fRenderTarget); |
| 131 } | 133 } |
| 132 | 134 |
| 133 fTextContext->drawTextBlob(this, fRenderTarget, | 135 fTextContext->drawTextBlob(this, fRenderTarget, |
| 134 clip, skPaint, viewMatrix, blob, x, y, filter, cl
ipBounds); | 136 clip, skPaint, viewMatrix, blob, x, y, filter, cl
ipBounds); |
| 135 } | 137 } |
| 136 | 138 |
| 137 void GrDrawContext::drawPathsFromRange(const GrPipelineBuilder* pipelineBuilder, | 139 void GrDrawContext::drawPathsFromRange(const GrPipelineBuilder* pipelineBuilder, |
| 138 const SkMatrix& viewMatrix, | 140 const SkMatrix& viewMatrix, |
| 139 const SkMatrix& localMatrix, | 141 const SkMatrix& localMatrix, |
| 140 GrColor color, | 142 GrColor color, |
| 141 GrPathRange* range, | 143 GrPathRange* range, |
| 142 GrPathRangeDraw* draw, | 144 GrPathRangeDraw* draw, |
| 143 int /*GrPathRendering::FillType*/ fill) { | 145 int /*GrPathRendering::FillType*/ fill) { |
| 144 RETURN_IF_ABANDONED | 146 RETURN_IF_ABANDONED |
| 145 SkDEBUGCODE(this->validate();) | 147 SkDEBUGCODE(this->validate();) |
| 146 | 148 |
| 147 this->getDrawTarget()->drawPathsFromRange(*pipelineBuilder, viewMatrix, loca
lMatrix, color, | 149 this->getDrawTarget()->drawPathsFromRange(*pipelineBuilder, viewMatrix, loca
lMatrix, color, |
| 148 range, draw, (GrPathRendering::Fil
lType) fill); | 150 range, draw, (GrPathRendering::Fil
lType) fill); |
| 149 } | 151 } |
| 150 | 152 |
| 151 void GrDrawContext::discard() { | 153 void GrDrawContext::discard() { |
| 152 RETURN_IF_ABANDONED | 154 RETURN_IF_ABANDONED |
| 153 SkDEBUGCODE(this->validate();) | 155 SkDEBUGCODE(this->validate();) |
| 154 | 156 |
| 155 AutoCheckFlush acf(fContext); | 157 AutoCheckFlush acf(fDrawingMgr); |
| 156 this->getDrawTarget()->discard(fRenderTarget); | 158 this->getDrawTarget()->discard(fRenderTarget); |
| 157 } | 159 } |
| 158 | 160 |
| 159 void GrDrawContext::clear(const SkIRect* rect, | 161 void GrDrawContext::clear(const SkIRect* rect, |
| 160 const GrColor color, | 162 const GrColor color, |
| 161 bool canIgnoreRect) { | 163 bool canIgnoreRect) { |
| 162 RETURN_IF_ABANDONED | 164 RETURN_IF_ABANDONED |
| 163 SkDEBUGCODE(this->validate();) | 165 SkDEBUGCODE(this->validate();) |
| 164 | 166 |
| 165 AutoCheckFlush acf(fContext); | 167 AutoCheckFlush acf(fDrawingMgr); |
| 166 this->getDrawTarget()->clear(rect, color, canIgnoreRect, fRenderTarget); | 168 this->getDrawTarget()->clear(rect, color, canIgnoreRect, fRenderTarget); |
| 167 } | 169 } |
| 168 | 170 |
| 169 | 171 |
| 170 void GrDrawContext::drawPaint(const GrClip& clip, | 172 void GrDrawContext::drawPaint(const GrClip& clip, |
| 171 const GrPaint& origPaint, | 173 const GrPaint& origPaint, |
| 172 const SkMatrix& viewMatrix) { | 174 const SkMatrix& viewMatrix) { |
| 173 RETURN_IF_ABANDONED | 175 RETURN_IF_ABANDONED |
| 174 SkDEBUGCODE(this->validate();) | 176 SkDEBUGCODE(this->validate();) |
| 175 | 177 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 199 } | 201 } |
| 200 inverse.mapRect(&r); | 202 inverse.mapRect(&r); |
| 201 this->drawRect(clip, *paint, viewMatrix, r); | 203 this->drawRect(clip, *paint, viewMatrix, r); |
| 202 } else { | 204 } else { |
| 203 SkMatrix localMatrix; | 205 SkMatrix localMatrix; |
| 204 if (!viewMatrix.invert(&localMatrix)) { | 206 if (!viewMatrix.invert(&localMatrix)) { |
| 205 SkDebugf("Could not invert matrix\n"); | 207 SkDebugf("Could not invert matrix\n"); |
| 206 return; | 208 return; |
| 207 } | 209 } |
| 208 | 210 |
| 209 AutoCheckFlush acf(fContext); | 211 AutoCheckFlush acf(fDrawingMgr); |
| 210 | 212 |
| 211 GrPipelineBuilder pipelineBuilder(*paint, fRenderTarget, clip); | 213 GrPipelineBuilder pipelineBuilder(*paint, fRenderTarget, clip); |
| 212 this->getDrawTarget()->drawNonAARect(pipelineBuilder, | 214 this->getDrawTarget()->drawNonAARect(pipelineBuilder, |
| 213 paint->getColor(), | 215 paint->getColor(), |
| 214 SkMatrix::I(), | 216 SkMatrix::I(), |
| 215 r, | 217 r, |
| 216 localMatrix); | 218 localMatrix); |
| 217 } | 219 } |
| 218 } | 220 } |
| 219 | 221 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 231 SkDEBUGCODE(this->validate();) | 233 SkDEBUGCODE(this->validate();) |
| 232 | 234 |
| 233 if (strokeInfo && strokeInfo->isDashed()) { | 235 if (strokeInfo && strokeInfo->isDashed()) { |
| 234 SkPath path; | 236 SkPath path; |
| 235 path.setIsVolatile(true); | 237 path.setIsVolatile(true); |
| 236 path.addRect(rect); | 238 path.addRect(rect); |
| 237 this->drawPath(clip, paint, viewMatrix, path, *strokeInfo); | 239 this->drawPath(clip, paint, viewMatrix, path, *strokeInfo); |
| 238 return; | 240 return; |
| 239 } | 241 } |
| 240 | 242 |
| 241 AutoCheckFlush acf(fContext); | 243 AutoCheckFlush acf(fDrawingMgr); |
| 242 | 244 |
| 243 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); | 245 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
| 244 | 246 |
| 245 SkScalar width = nullptr == strokeInfo ? -1 : strokeInfo->getWidth(); | 247 SkScalar width = nullptr == strokeInfo ? -1 : strokeInfo->getWidth(); |
| 246 | 248 |
| 247 // Check if this is a full RT draw and can be replaced with a clear. We don'
t bother checking | 249 // Check if this is a full RT draw and can be replaced with a clear. We don'
t bother checking |
| 248 // cases where the RT is fully inside a stroke. | 250 // cases where the RT is fully inside a stroke. |
| 249 if (width < 0) { | 251 if (width < 0) { |
| 250 SkRect rtRect; | 252 SkRect rtRect; |
| 251 pipelineBuilder.getRenderTarget()->getBoundsRect(&rtRect); | 253 pipelineBuilder.getRenderTarget()->getBoundsRect(&rtRect); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 } | 322 } |
| 321 | 323 |
| 322 void GrDrawContext::drawNonAARectToRect(const GrClip& clip, | 324 void GrDrawContext::drawNonAARectToRect(const GrClip& clip, |
| 323 const GrPaint& paint, | 325 const GrPaint& paint, |
| 324 const SkMatrix& viewMatrix, | 326 const SkMatrix& viewMatrix, |
| 325 const SkRect& rectToDraw, | 327 const SkRect& rectToDraw, |
| 326 const SkRect& localRect) { | 328 const SkRect& localRect) { |
| 327 RETURN_IF_ABANDONED | 329 RETURN_IF_ABANDONED |
| 328 SkDEBUGCODE(this->validate();) | 330 SkDEBUGCODE(this->validate();) |
| 329 | 331 |
| 330 AutoCheckFlush acf(fContext); | 332 AutoCheckFlush acf(fDrawingMgr); |
| 331 | 333 |
| 332 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); | 334 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
| 333 this->getDrawTarget()->drawNonAARect(pipelineBuilder, | 335 this->getDrawTarget()->drawNonAARect(pipelineBuilder, |
| 334 paint.getColor(), | 336 paint.getColor(), |
| 335 viewMatrix, | 337 viewMatrix, |
| 336 rectToDraw, | 338 rectToDraw, |
| 337 localRect); | 339 localRect); |
| 338 } | 340 } |
| 339 | 341 |
| 340 void GrDrawContext::drawNonAARectWithLocalMatrix(const GrClip& clip, | 342 void GrDrawContext::drawNonAARectWithLocalMatrix(const GrClip& clip, |
| 341 const GrPaint& paint, | 343 const GrPaint& paint, |
| 342 const SkMatrix& viewMatrix, | 344 const SkMatrix& viewMatrix, |
| 343 const SkRect& rectToDraw, | 345 const SkRect& rectToDraw, |
| 344 const SkMatrix& localMatrix) { | 346 const SkMatrix& localMatrix) { |
| 345 RETURN_IF_ABANDONED | 347 RETURN_IF_ABANDONED |
| 346 SkDEBUGCODE(this->validate();) | 348 SkDEBUGCODE(this->validate();) |
| 347 | 349 |
| 348 AutoCheckFlush acf(fContext); | 350 AutoCheckFlush acf(fDrawingMgr); |
| 349 | 351 |
| 350 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); | 352 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
| 351 this->getDrawTarget()->drawNonAARect(pipelineBuilder, | 353 this->getDrawTarget()->drawNonAARect(pipelineBuilder, |
| 352 paint.getColor(), | 354 paint.getColor(), |
| 353 viewMatrix, | 355 viewMatrix, |
| 354 rectToDraw, | 356 rectToDraw, |
| 355 localMatrix); | 357 localMatrix); |
| 356 } | 358 } |
| 357 | 359 |
| 358 void GrDrawContext::drawVertices(const GrClip& clip, | 360 void GrDrawContext::drawVertices(const GrClip& clip, |
| 359 const GrPaint& paint, | 361 const GrPaint& paint, |
| 360 const SkMatrix& viewMatrix, | 362 const SkMatrix& viewMatrix, |
| 361 GrPrimitiveType primitiveType, | 363 GrPrimitiveType primitiveType, |
| 362 int vertexCount, | 364 int vertexCount, |
| 363 const SkPoint positions[], | 365 const SkPoint positions[], |
| 364 const SkPoint texCoords[], | 366 const SkPoint texCoords[], |
| 365 const GrColor colors[], | 367 const GrColor colors[], |
| 366 const uint16_t indices[], | 368 const uint16_t indices[], |
| 367 int indexCount) { | 369 int indexCount) { |
| 368 RETURN_IF_ABANDONED | 370 RETURN_IF_ABANDONED |
| 369 SkDEBUGCODE(this->validate();) | 371 SkDEBUGCODE(this->validate();) |
| 370 | 372 |
| 371 AutoCheckFlush acf(fContext); | 373 AutoCheckFlush acf(fDrawingMgr); |
| 372 | 374 |
| 373 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); | 375 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
| 374 | 376 |
| 375 // TODO clients should give us bounds | 377 // TODO clients should give us bounds |
| 376 SkRect bounds; | 378 SkRect bounds; |
| 377 if (!bounds.setBoundsCheck(positions, vertexCount)) { | 379 if (!bounds.setBoundsCheck(positions, vertexCount)) { |
| 378 SkDebugf("drawVertices call empty bounds\n"); | 380 SkDebugf("drawVertices call empty bounds\n"); |
| 379 return; | 381 return; |
| 380 } | 382 } |
| 381 | 383 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 402 void GrDrawContext::drawAtlas(const GrClip& clip, | 404 void GrDrawContext::drawAtlas(const GrClip& clip, |
| 403 const GrPaint& paint, | 405 const GrPaint& paint, |
| 404 const SkMatrix& viewMatrix, | 406 const SkMatrix& viewMatrix, |
| 405 int spriteCount, | 407 int spriteCount, |
| 406 const SkRSXform xform[], | 408 const SkRSXform xform[], |
| 407 const SkRect texRect[], | 409 const SkRect texRect[], |
| 408 const SkColor colors[]) { | 410 const SkColor colors[]) { |
| 409 RETURN_IF_ABANDONED | 411 RETURN_IF_ABANDONED |
| 410 SkDEBUGCODE(this->validate();) | 412 SkDEBUGCODE(this->validate();) |
| 411 | 413 |
| 412 AutoCheckFlush acf(fContext); | 414 AutoCheckFlush acf(fDrawingMgr); |
| 413 | 415 |
| 414 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); | 416 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
| 415 | 417 |
| 416 GrDrawAtlasBatch::Geometry geometry; | 418 GrDrawAtlasBatch::Geometry geometry; |
| 417 geometry.fColor = paint.getColor(); | 419 geometry.fColor = paint.getColor(); |
| 418 SkAutoTUnref<GrDrawBatch> batch(GrDrawAtlasBatch::Create(geometry, viewMatri
x, spriteCount, | 420 SkAutoTUnref<GrDrawBatch> batch(GrDrawAtlasBatch::Create(geometry, viewMatri
x, spriteCount, |
| 419 xform, texRect, col
ors)); | 421 xform, texRect, col
ors)); |
| 420 | 422 |
| 421 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); | 423 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); |
| 422 } | 424 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 436 } | 438 } |
| 437 | 439 |
| 438 if (strokeInfo.isDashed()) { | 440 if (strokeInfo.isDashed()) { |
| 439 SkPath path; | 441 SkPath path; |
| 440 path.setIsVolatile(true); | 442 path.setIsVolatile(true); |
| 441 path.addRRect(rrect); | 443 path.addRRect(rrect); |
| 442 this->drawPath(clip, paint, viewMatrix, path, strokeInfo); | 444 this->drawPath(clip, paint, viewMatrix, path, strokeInfo); |
| 443 return; | 445 return; |
| 444 } | 446 } |
| 445 | 447 |
| 446 AutoCheckFlush acf(fContext); | 448 AutoCheckFlush acf(fDrawingMgr); |
| 447 | 449 |
| 448 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); | 450 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
| 449 GrColor color = paint.getColor(); | 451 GrColor color = paint.getColor(); |
| 450 | 452 |
| 451 if (!GrOvalRenderer::DrawRRect(this->getDrawTarget(), | 453 if (!GrOvalRenderer::DrawRRect(this->getDrawTarget(), |
| 452 pipelineBuilder, | 454 pipelineBuilder, |
| 453 color, | 455 color, |
| 454 viewMatrix, | 456 viewMatrix, |
| 455 paint.isAntiAlias(), | 457 paint.isAntiAlias(), |
| 456 rrect, | 458 rrect, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 470 const SkMatrix& viewMatrix, | 472 const SkMatrix& viewMatrix, |
| 471 const SkRRect& outer, | 473 const SkRRect& outer, |
| 472 const SkRRect& inner) { | 474 const SkRRect& inner) { |
| 473 RETURN_IF_ABANDONED | 475 RETURN_IF_ABANDONED |
| 474 SkDEBUGCODE(this->validate();) | 476 SkDEBUGCODE(this->validate();) |
| 475 | 477 |
| 476 if (outer.isEmpty()) { | 478 if (outer.isEmpty()) { |
| 477 return; | 479 return; |
| 478 } | 480 } |
| 479 | 481 |
| 480 AutoCheckFlush acf(fContext); | 482 AutoCheckFlush acf(fDrawingMgr); |
| 481 | 483 |
| 482 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); | 484 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
| 483 GrColor color = paint.getColor(); | 485 GrColor color = paint.getColor(); |
| 484 if (!GrOvalRenderer::DrawDRRect(this->getDrawTarget(), | 486 if (!GrOvalRenderer::DrawDRRect(this->getDrawTarget(), |
| 485 pipelineBuilder, | 487 pipelineBuilder, |
| 486 color, | 488 color, |
| 487 viewMatrix, | 489 viewMatrix, |
| 488 paint.isAntiAlias(), | 490 paint.isAntiAlias(), |
| 489 outer, | 491 outer, |
| 490 inner)) { | 492 inner)) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 515 } | 517 } |
| 516 | 518 |
| 517 if (strokeInfo.isDashed()) { | 519 if (strokeInfo.isDashed()) { |
| 518 SkPath path; | 520 SkPath path; |
| 519 path.setIsVolatile(true); | 521 path.setIsVolatile(true); |
| 520 path.addOval(oval); | 522 path.addOval(oval); |
| 521 this->drawPath(clip, paint, viewMatrix, path, strokeInfo); | 523 this->drawPath(clip, paint, viewMatrix, path, strokeInfo); |
| 522 return; | 524 return; |
| 523 } | 525 } |
| 524 | 526 |
| 525 AutoCheckFlush acf(fContext); | 527 AutoCheckFlush acf(fDrawingMgr); |
| 526 | 528 |
| 527 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); | 529 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
| 528 GrColor color = paint.getColor(); | 530 GrColor color = paint.getColor(); |
| 529 | 531 |
| 530 if (!GrOvalRenderer::DrawOval(this->getDrawTarget(), | 532 if (!GrOvalRenderer::DrawOval(this->getDrawTarget(), |
| 531 pipelineBuilder, | 533 pipelineBuilder, |
| 532 color, | 534 color, |
| 533 viewMatrix, | 535 viewMatrix, |
| 534 paint.isAntiAlias(), | 536 paint.isAntiAlias(), |
| 535 oval, | 537 oval, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 } | 592 } |
| 591 | 593 |
| 592 return allEq || allGoE1; | 594 return allEq || allGoE1; |
| 593 } | 595 } |
| 594 | 596 |
| 595 void GrDrawContext::drawBatch(const GrClip& clip, | 597 void GrDrawContext::drawBatch(const GrClip& clip, |
| 596 const GrPaint& paint, GrDrawBatch* batch) { | 598 const GrPaint& paint, GrDrawBatch* batch) { |
| 597 RETURN_IF_ABANDONED | 599 RETURN_IF_ABANDONED |
| 598 SkDEBUGCODE(this->validate();) | 600 SkDEBUGCODE(this->validate();) |
| 599 | 601 |
| 600 AutoCheckFlush acf(fContext); | 602 AutoCheckFlush acf(fDrawingMgr); |
| 601 | 603 |
| 602 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); | 604 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
| 603 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); | 605 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); |
| 604 } | 606 } |
| 605 | 607 |
| 606 void GrDrawContext::drawPath(const GrClip& clip, | 608 void GrDrawContext::drawPath(const GrClip& clip, |
| 607 const GrPaint& paint, | 609 const GrPaint& paint, |
| 608 const SkMatrix& viewMatrix, | 610 const SkMatrix& viewMatrix, |
| 609 const SkPath& path, | 611 const SkPath& path, |
| 610 const GrStrokeInfo& strokeInfo) { | 612 const GrStrokeInfo& strokeInfo) { |
| 611 RETURN_IF_ABANDONED | 613 RETURN_IF_ABANDONED |
| 612 SkDEBUGCODE(this->validate();) | 614 SkDEBUGCODE(this->validate();) |
| 613 | 615 |
| 614 if (path.isEmpty()) { | 616 if (path.isEmpty()) { |
| 615 if (path.isInverseFillType()) { | 617 if (path.isInverseFillType()) { |
| 616 this->drawPaint(clip, paint, viewMatrix); | 618 this->drawPaint(clip, paint, viewMatrix); |
| 617 } | 619 } |
| 618 return; | 620 return; |
| 619 } | 621 } |
| 620 | 622 |
| 621 GrColor color = paint.getColor(); | 623 GrColor color = paint.getColor(); |
| 622 | 624 |
| 623 // Note that internalDrawPath may sw-rasterize the path into a scratch textu
re. | 625 // Note that internalDrawPath may sw-rasterize the path into a scratch textu
re. |
| 624 // Scratch textures can be recycled after they are returned to the texture | 626 // Scratch textures can be recycled after they are returned to the texture |
| 625 // cache. This presents a potential hazard for buffered drawing. However, | 627 // cache. This presents a potential hazard for buffered drawing. However, |
| 626 // the writePixels that uploads to the scratch will perform a flush so we're | 628 // the writePixels that uploads to the scratch will perform a flush so we're |
| 627 // OK. | 629 // OK. |
| 628 AutoCheckFlush acf(fContext); | 630 AutoCheckFlush acf(fDrawingMgr); |
| 629 | 631 |
| 630 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); | 632 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
| 631 if (!strokeInfo.isDashed()) { | 633 if (!strokeInfo.isDashed()) { |
| 632 bool useCoverageAA = paint.isAntiAlias() && | 634 bool useCoverageAA = paint.isAntiAlias() && |
| 633 !pipelineBuilder.getRenderTarget()->isUnifiedMultisampled(); | 635 !pipelineBuilder.getRenderTarget()->isUnifiedMultisampled(); |
| 634 | 636 |
| 635 if (useCoverageAA && strokeInfo.getWidth() < 0 && !path.isConvex()) { | 637 if (useCoverageAA && strokeInfo.getWidth() < 0 && !path.isConvex()) { |
| 636 // Concave AA paths are expensive - try to avoid them for special ca
ses | 638 // Concave AA paths are expensive - try to avoid them for special ca
ses |
| 637 SkRect rects[2]; | 639 SkRect rects[2]; |
| 638 | 640 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 | 684 |
| 683 GrPathRendererChain::DrawType type = | 685 GrPathRendererChain::DrawType type = |
| 684 useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType : | 686 useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType : |
| 685 GrPathRendererChain::kColor_DrawType; | 687 GrPathRendererChain::kColor_DrawType; |
| 686 | 688 |
| 687 const SkPath* pathPtr = &path; | 689 const SkPath* pathPtr = &path; |
| 688 SkTLazy<SkPath> tmpPath; | 690 SkTLazy<SkPath> tmpPath; |
| 689 const GrStrokeInfo* strokeInfoPtr = &strokeInfo; | 691 const GrStrokeInfo* strokeInfoPtr = &strokeInfo; |
| 690 | 692 |
| 691 // Try a 1st time without stroking the path and without allowing the SW rend
erer | 693 // Try a 1st time without stroking the path and without allowing the SW rend
erer |
| 692 GrPathRenderer* pr = fContext->getPathRenderer(target, pipelineBuilder, view
Matrix, *pathPtr, | 694 GrPathRenderer* pr = fDrawingMgr->getContext()->getPathRenderer(target, pipe
lineBuilder, |
| 693 *strokeInfoPtr, false, type)
; | 695 viewMatrix,
*pathPtr, |
| 696 *strokeInfoP
tr, false, type); |
| 694 | 697 |
| 695 GrStrokeInfo dashlessStrokeInfo(strokeInfo, false); | 698 GrStrokeInfo dashlessStrokeInfo(strokeInfo, false); |
| 696 if (nullptr == pr && strokeInfo.isDashed()) { | 699 if (nullptr == pr && strokeInfo.isDashed()) { |
| 697 // It didn't work above, so try again with dashed stroke converted to a
dashless stroke. | 700 // It didn't work above, so try again with dashed stroke converted to a
dashless stroke. |
| 698 if (!strokeInfo.applyDashToPath(tmpPath.init(), &dashlessStrokeInfo, *pa
thPtr)) { | 701 if (!strokeInfo.applyDashToPath(tmpPath.init(), &dashlessStrokeInfo, *pa
thPtr)) { |
| 699 return; | 702 return; |
| 700 } | 703 } |
| 701 pathPtr = tmpPath.get(); | 704 pathPtr = tmpPath.get(); |
| 702 if (pathPtr->isEmpty()) { | 705 if (pathPtr->isEmpty()) { |
| 703 return; | 706 return; |
| 704 } | 707 } |
| 705 strokeInfoPtr = &dashlessStrokeInfo; | 708 strokeInfoPtr = &dashlessStrokeInfo; |
| 706 pr = fContext->getPathRenderer(target, pipelineBuilder, viewMatrix, *pat
hPtr, *strokeInfoPtr, | 709 pr = fDrawingMgr->getContext()->getPathRenderer(target, pipelineBuilder,
viewMatrix, |
| 707 false, type); | 710 *pathPtr, *strokeInfoPtr
, |
| 711 false, type); |
| 708 } | 712 } |
| 709 | 713 |
| 710 if (nullptr == pr) { | 714 if (nullptr == pr) { |
| 711 if (!GrPathRenderer::IsStrokeHairlineOrEquivalent(*strokeInfoPtr, viewMa
trix, nullptr) && | 715 if (!GrPathRenderer::IsStrokeHairlineOrEquivalent(*strokeInfoPtr, viewMa
trix, nullptr) && |
| 712 !strokeInfoPtr->isFillStyle()) { | 716 !strokeInfoPtr->isFillStyle()) { |
| 713 // It didn't work above, so try again with stroke converted to a fil
l. | 717 // It didn't work above, so try again with stroke converted to a fil
l. |
| 714 if (!tmpPath.isValid()) { | 718 if (!tmpPath.isValid()) { |
| 715 tmpPath.init(); | 719 tmpPath.init(); |
| 716 } | 720 } |
| 717 dashlessStrokeInfo.setResScale(SkScalarAbs(viewMatrix.getMaxScale())
); | 721 dashlessStrokeInfo.setResScale(SkScalarAbs(viewMatrix.getMaxScale())
); |
| 718 if (!dashlessStrokeInfo.applyToPath(tmpPath.get(), *pathPtr)) { | 722 if (!dashlessStrokeInfo.applyToPath(tmpPath.get(), *pathPtr)) { |
| 719 return; | 723 return; |
| 720 } | 724 } |
| 721 pathPtr = tmpPath.get(); | 725 pathPtr = tmpPath.get(); |
| 722 if (pathPtr->isEmpty()) { | 726 if (pathPtr->isEmpty()) { |
| 723 return; | 727 return; |
| 724 } | 728 } |
| 725 dashlessStrokeInfo.setFillStyle(); | 729 dashlessStrokeInfo.setFillStyle(); |
| 726 strokeInfoPtr = &dashlessStrokeInfo; | 730 strokeInfoPtr = &dashlessStrokeInfo; |
| 727 } | 731 } |
| 728 | 732 |
| 729 // This time, allow SW renderer | 733 // This time, allow SW renderer |
| 730 pr = fContext->getPathRenderer(target, pipelineBuilder, viewMatrix, *pat
hPtr, *strokeInfoPtr, | 734 pr = fDrawingMgr->getContext()->getPathRenderer(target, pipelineBuilder,
viewMatrix, |
| 731 true, type); | 735 *pathPtr, *strokeInfoPtr
, |
| 736 true, type); |
| 732 } | 737 } |
| 733 | 738 |
| 734 if (nullptr == pr) { | 739 if (nullptr == pr) { |
| 735 #ifdef SK_DEBUG | 740 #ifdef SK_DEBUG |
| 736 SkDebugf("Unable to find path renderer compatible with path.\n"); | 741 SkDebugf("Unable to find path renderer compatible with path.\n"); |
| 737 #endif | 742 #endif |
| 738 return; | 743 return; |
| 739 } | 744 } |
| 740 | 745 |
| 741 GrPathRenderer::DrawPathArgs args; | 746 GrPathRenderer::DrawPathArgs args; |
| 742 args.fTarget = target; | 747 args.fTarget = target; |
| 743 args.fResourceProvider = fContext->resourceProvider(); | 748 args.fResourceProvider = fDrawingMgr->getContext()->resourceProvider(); |
| 744 args.fPipelineBuilder = pipelineBuilder; | 749 args.fPipelineBuilder = pipelineBuilder; |
| 745 args.fColor = color; | 750 args.fColor = color; |
| 746 args.fViewMatrix = &viewMatrix; | 751 args.fViewMatrix = &viewMatrix; |
| 747 args.fPath = pathPtr; | 752 args.fPath = pathPtr; |
| 748 args.fStroke = strokeInfoPtr; | 753 args.fStroke = strokeInfoPtr; |
| 749 args.fAntiAlias = useCoverageAA; | 754 args.fAntiAlias = useCoverageAA; |
| 750 pr->drawPath(args); | 755 pr->drawPath(args); |
| 751 } | 756 } |
| 752 | 757 |
| 753 void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrDrawBatch* b
atch) { | 758 void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrDrawBatch* b
atch) { |
| 754 RETURN_IF_ABANDONED | 759 RETURN_IF_ABANDONED |
| 755 SkDEBUGCODE(this->validate();) | 760 SkDEBUGCODE(this->validate();) |
| 756 | 761 |
| 757 this->getDrawTarget()->drawBatch(*pipelineBuilder, batch); | 762 this->getDrawTarget()->drawBatch(*pipelineBuilder, batch); |
| 758 } | 763 } |
| OLD | NEW |