| 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 "GrAARectRenderer.h" | 9 #include "GrAARectRenderer.h" |
| 10 #include "GrAtlasTextContext.h" | |
| 11 #include "GrBatch.h" | 10 #include "GrBatch.h" |
| 12 #include "GrBatchTest.h" | 11 #include "GrBatchTest.h" |
| 13 #include "GrDefaultGeoProcFactory.h" | 12 #include "GrDefaultGeoProcFactory.h" |
| 14 #include "GrDrawContext.h" | 13 #include "GrDrawContext.h" |
| 15 #include "GrOvalRenderer.h" | 14 #include "GrOvalRenderer.h" |
| 16 #include "GrPathRenderer.h" | 15 #include "GrPathRenderer.h" |
| 17 #include "GrRenderTarget.h" | |
| 18 #include "GrRenderTargetPriv.h" | |
| 19 #include "GrStencilAndCoverTextContext.h" | |
| 20 | 16 |
| 21 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == fContext) | 17 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == fContext) |
| 22 #define RETURN_IF_ABANDONED if (!fDrawTarget) { return; } | 18 #define RETURN_IF_ABANDONED if (!fDrawTarget) { return; } |
| 23 #define RETURN_FALSE_IF_ABANDONED if (!fDrawTarget) { return false; } | 19 #define RETURN_FALSE_IF_ABANDONED if (!fDrawTarget) { return false; } |
| 24 #define RETURN_NULL_IF_ABANDONED if (!fDrawTarget) { return NULL; } | 20 #define RETURN_NULL_IF_ABANDONED if (!fDrawTarget) { return NULL; } |
| 25 | 21 |
| 26 class AutoCheckFlush { | 22 class AutoCheckFlush { |
| 27 public: | 23 public: |
| 28 AutoCheckFlush(GrContext* context) : fContext(context) { SkASSERT(context);
} | 24 AutoCheckFlush(GrContext* context) : fContext(context) { SkASSERT(context);
} |
| 29 ~AutoCheckFlush() { fContext->flushIfNecessary(); } | 25 ~AutoCheckFlush() { fContext->flushIfNecessary(); } |
| 30 | 26 |
| 31 private: | 27 private: |
| 32 GrContext* fContext; | 28 GrContext* fContext; |
| 33 }; | 29 }; |
| 34 | 30 |
| 35 GrDrawContext::GrDrawContext(GrContext* context, | 31 GrDrawContext::GrDrawContext(GrContext* context, GrDrawTarget* drawTarget) |
| 36 GrDrawTarget* drawTarget, | |
| 37 const SkDeviceProperties& devProps, | |
| 38 bool useDFT) | |
| 39 : fContext(context) | 32 : fContext(context) |
| 40 , fDrawTarget(SkRef(drawTarget)) | 33 , fDrawTarget(SkRef(drawTarget)) { |
| 41 , fTextContext(NULL) | |
| 42 , fDevProps(SkNEW_ARGS(SkDeviceProperties, (devProps))) | |
| 43 , fUseDFT(useDFT) { | |
| 44 } | 34 } |
| 45 | 35 |
| 46 GrDrawContext::~GrDrawContext() { | 36 GrDrawContext::~GrDrawContext() { |
| 47 SkSafeUnref(fDrawTarget); | 37 SkSafeUnref(fDrawTarget); |
| 48 SkDELETE(fTextContext); | |
| 49 SkDELETE(fDevProps); | |
| 50 } | 38 } |
| 51 | 39 |
| 52 void GrDrawContext::copySurface(GrRenderTarget* dst, GrSurface* src, | 40 void GrDrawContext::copySurface(GrRenderTarget* dst, GrSurface* src, |
| 53 const SkIRect& srcRect, const SkIPoint& dstPoint
) { | 41 const SkIRect& srcRect, const SkIPoint& dstPoint
) { |
| 54 if (!this->prepareToDraw(dst)) { | 42 if (!this->prepareToDraw(dst)) { |
| 55 return; | 43 return; |
| 56 } | 44 } |
| 57 | 45 |
| 58 fDrawTarget->copySurface(dst, src, srcRect, dstPoint); | 46 fDrawTarget->copySurface(dst, src, srcRect, dstPoint); |
| 59 } | 47 } |
| 60 | 48 |
| 61 GrTextContext* GrDrawContext::createTextContext(GrRenderTarget* renderTarget, | 49 void GrDrawContext::drawText(GrPipelineBuilder* pipelineBuilder, GrBatch* batch)
{ |
| 62 const SkDeviceProperties& leakyP
roperties, | 50 fDrawTarget->drawBatch(pipelineBuilder, batch); |
| 63 bool enableDistanceFieldFonts) { | |
| 64 if (fContext->caps()->shaderCaps()->pathRenderingSupport() && | |
| 65 renderTarget->isStencilBufferMultisampled()) { | |
| 66 GrStencilAttachment* sb = renderTarget->renderTargetPriv().attachStencil
Attachment(); | |
| 67 if (sb) { | |
| 68 return GrStencilAndCoverTextContext::Create(fContext, this, | |
| 69 leakyProperties, | |
| 70 enableDistanceFieldFonts
); | |
| 71 } | |
| 72 } | |
| 73 | |
| 74 return GrAtlasTextContext::Create(fContext, this, leakyProperties, enableDis
tanceFieldFonts); | |
| 75 } | |
| 76 | |
| 77 void GrDrawContext::drawText(GrRenderTarget* rt, const GrClip& clip, const GrPai
nt& grPaint, | |
| 78 const SkPaint& skPaint, | |
| 79 const SkMatrix& viewMatrix, | |
| 80 const char text[], size_t byteLength, | |
| 81 SkScalar x, SkScalar y, const SkIRect& clipBounds)
{ | |
| 82 if (!fTextContext) { | |
| 83 fTextContext = this->createTextContext(rt, *fDevProps, fUseDFT); | |
| 84 } | |
| 85 | |
| 86 fTextContext->drawText(rt, clip, grPaint, skPaint, viewMatrix, | |
| 87 text, byteLength, x, y, clipBounds); | |
| 88 | |
| 89 } | |
| 90 void GrDrawContext::drawPosText(GrRenderTarget* rt, const GrClip& clip, const Gr
Paint& grPaint, | |
| 91 const SkPaint& skPaint, | |
| 92 const SkMatrix& viewMatrix, | |
| 93 const char text[], size_t byteLength, | |
| 94 const SkScalar pos[], int scalarsPerPosition, | |
| 95 const SkPoint& offset, const SkIRect& clipBounds
) { | |
| 96 if (!fTextContext) { | |
| 97 fTextContext = this->createTextContext(rt, *fDevProps, fUseDFT); | |
| 98 } | |
| 99 | |
| 100 fTextContext->drawPosText(rt, clip, grPaint, skPaint, viewMatrix, text, byte
Length, | |
| 101 pos, scalarsPerPosition, offset, clipBounds); | |
| 102 | |
| 103 } | |
| 104 void GrDrawContext::drawTextBlob(GrRenderTarget* rt, const GrClip& clip, const S
kPaint& skPaint, | |
| 105 const SkMatrix& viewMatrix, const SkTextBlob* b
lob, | |
| 106 SkScalar x, SkScalar y, | |
| 107 SkDrawFilter* filter, const SkIRect& clipBounds
) { | |
| 108 if (!fTextContext) { | |
| 109 fTextContext = this->createTextContext(rt, *fDevProps, fUseDFT); | |
| 110 } | |
| 111 | |
| 112 fTextContext->drawTextBlob(rt, clip, skPaint, viewMatrix, blob, x, y, filter
, clipBounds); | |
| 113 } | 51 } |
| 114 | 52 |
| 115 void GrDrawContext::drawPaths(GrPipelineBuilder* pipelineBuilder, | 53 void GrDrawContext::drawPaths(GrPipelineBuilder* pipelineBuilder, |
| 116 const GrPathProcessor* pathProc, | 54 const GrPathProcessor* pathProc, |
| 117 const GrPathRange* pathRange, | 55 const GrPathRange* pathRange, |
| 118 const void* indices, | 56 const void* indices, |
| 119 int /*GrDrawTarget::PathIndexType*/ indexType, | 57 int /*GrDrawTarget::PathIndexType*/ indexType, |
| 120 const float transformValues[], | 58 const float transformValues[], |
| 121 int /*GrDrawTarget::PathTransformType*/ transformT
ype, | 59 int /*GrDrawTarget::PathTransformType*/ transformT
ype, |
| 122 int count, | 60 int count, |
| (...skipping 1079 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1202 } | 1140 } |
| 1203 | 1141 |
| 1204 bool GrDrawContext::prepareToDraw(GrRenderTarget* rt) { | 1142 bool GrDrawContext::prepareToDraw(GrRenderTarget* rt) { |
| 1205 RETURN_FALSE_IF_ABANDONED | 1143 RETURN_FALSE_IF_ABANDONED |
| 1206 | 1144 |
| 1207 ASSERT_OWNED_RESOURCE(rt); | 1145 ASSERT_OWNED_RESOURCE(rt); |
| 1208 SkASSERT(rt); | 1146 SkASSERT(rt); |
| 1209 return true; | 1147 return true; |
| 1210 } | 1148 } |
| 1211 | 1149 |
| 1212 void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrBatch* batch
) { | |
| 1213 fDrawTarget->drawBatch(pipelineBuilder, batch); | |
| 1214 } | |
| 1215 | |
| 1216 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 1150 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 1217 | 1151 |
| 1218 #ifdef GR_TEST_UTILS | 1152 #ifdef GR_TEST_UTILS |
| 1219 | 1153 |
| 1220 BATCH_TEST_DEFINE(StrokeRectBatch) { | 1154 BATCH_TEST_DEFINE(StrokeRectBatch) { |
| 1221 StrokeRectBatch::Geometry geometry; | 1155 StrokeRectBatch::Geometry geometry; |
| 1222 geometry.fViewMatrix = GrTest::TestMatrix(random); | 1156 geometry.fViewMatrix = GrTest::TestMatrix(random); |
| 1223 geometry.fColor = GrRandomColor(random); | 1157 geometry.fColor = GrRandomColor(random); |
| 1224 geometry.fRect = GrTest::TestRect(random); | 1158 geometry.fRect = GrTest::TestRect(random); |
| 1225 geometry.fStrokeWidth = random->nextBool() ? 0.0f : 1.0f; | 1159 geometry.fStrokeWidth = random->nextBool() ? 0.0f : 1.0f; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1333 return DrawVerticesBatch::Create(geometry, type, viewMatrix, | 1267 return DrawVerticesBatch::Create(geometry, type, viewMatrix, |
| 1334 positions.begin(), vertexCount, | 1268 positions.begin(), vertexCount, |
| 1335 indices.begin(), hasIndices ? vertexCount :
0, | 1269 indices.begin(), hasIndices ? vertexCount :
0, |
| 1336 colors.begin(), | 1270 colors.begin(), |
| 1337 texCoords.begin(), | 1271 texCoords.begin(), |
| 1338 bounds); | 1272 bounds); |
| 1339 } | 1273 } |
| 1340 | 1274 |
| 1341 #endif | 1275 #endif |
| 1342 | 1276 |
| OLD | NEW |