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" |
10 #include "GrBatch.h" | 11 #include "GrBatch.h" |
11 #include "GrBatchTest.h" | 12 #include "GrBatchTest.h" |
12 #include "GrDefaultGeoProcFactory.h" | 13 #include "GrDefaultGeoProcFactory.h" |
13 #include "GrDrawContext.h" | 14 #include "GrDrawContext.h" |
14 #include "GrOvalRenderer.h" | 15 #include "GrOvalRenderer.h" |
15 #include "GrPathRenderer.h" | 16 #include "GrPathRenderer.h" |
| 17 #include "GrRenderTarget.h" |
| 18 #include "GrRenderTargetPriv.h" |
| 19 #include "GrStencilAndCoverTextContext.h" |
16 | 20 |
17 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == fContext) | 21 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == fContext) |
18 #define RETURN_IF_ABANDONED if (!fDrawTarget) { return; } | 22 #define RETURN_IF_ABANDONED if (!fDrawTarget) { return; } |
19 #define RETURN_FALSE_IF_ABANDONED if (!fDrawTarget) { return false; } | 23 #define RETURN_FALSE_IF_ABANDONED if (!fDrawTarget) { return false; } |
20 #define RETURN_NULL_IF_ABANDONED if (!fDrawTarget) { return NULL; } | 24 #define RETURN_NULL_IF_ABANDONED if (!fDrawTarget) { return NULL; } |
21 | 25 |
22 class AutoCheckFlush { | 26 class AutoCheckFlush { |
23 public: | 27 public: |
24 AutoCheckFlush(GrContext* context) : fContext(context) { SkASSERT(context);
} | 28 AutoCheckFlush(GrContext* context) : fContext(context) { SkASSERT(context);
} |
25 ~AutoCheckFlush() { fContext->flushIfNecessary(); } | 29 ~AutoCheckFlush() { fContext->flushIfNecessary(); } |
26 | 30 |
27 private: | 31 private: |
28 GrContext* fContext; | 32 GrContext* fContext; |
29 }; | 33 }; |
30 | 34 |
31 GrDrawContext::GrDrawContext(GrContext* context, GrDrawTarget* drawTarget) | 35 GrDrawContext::GrDrawContext(GrContext* context, |
| 36 GrDrawTarget* drawTarget, |
| 37 const SkDeviceProperties& devProps, |
| 38 bool useDFT) |
32 : fContext(context) | 39 : fContext(context) |
33 , fDrawTarget(SkRef(drawTarget)) { | 40 , fDrawTarget(SkRef(drawTarget)) |
| 41 , fTextContext(NULL) |
| 42 , fDevProps(SkNEW_ARGS(SkDeviceProperties, (devProps))) |
| 43 , fUseDFT(useDFT) { |
34 } | 44 } |
35 | 45 |
36 GrDrawContext::~GrDrawContext() { | 46 GrDrawContext::~GrDrawContext() { |
37 SkSafeUnref(fDrawTarget); | 47 SkSafeUnref(fDrawTarget); |
| 48 SkDELETE(fTextContext); |
| 49 SkDELETE(fDevProps); |
38 } | 50 } |
39 | 51 |
40 void GrDrawContext::copySurface(GrRenderTarget* dst, GrSurface* src, | 52 void GrDrawContext::copySurface(GrRenderTarget* dst, GrSurface* src, |
41 const SkIRect& srcRect, const SkIPoint& dstPoint
) { | 53 const SkIRect& srcRect, const SkIPoint& dstPoint
) { |
42 if (!this->prepareToDraw(dst)) { | 54 if (!this->prepareToDraw(dst)) { |
43 return; | 55 return; |
44 } | 56 } |
45 | 57 |
46 fDrawTarget->copySurface(dst, src, srcRect, dstPoint); | 58 fDrawTarget->copySurface(dst, src, srcRect, dstPoint); |
47 } | 59 } |
48 | 60 |
49 void GrDrawContext::drawText(GrPipelineBuilder* pipelineBuilder, GrBatch* batch)
{ | 61 GrTextContext* GrDrawContext::createTextContext(GrRenderTarget* renderTarget, |
50 fDrawTarget->drawBatch(pipelineBuilder, batch); | 62 const SkDeviceProperties& leakyP
roperties, |
| 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); |
51 } | 113 } |
52 | 114 |
53 void GrDrawContext::drawPaths(GrPipelineBuilder* pipelineBuilder, | 115 void GrDrawContext::drawPaths(GrPipelineBuilder* pipelineBuilder, |
54 const GrPathProcessor* pathProc, | 116 const GrPathProcessor* pathProc, |
55 const GrPathRange* pathRange, | 117 const GrPathRange* pathRange, |
56 const void* indices, | 118 const void* indices, |
57 int /*GrDrawTarget::PathIndexType*/ indexType, | 119 int /*GrDrawTarget::PathIndexType*/ indexType, |
58 const float transformValues[], | 120 const float transformValues[], |
59 int /*GrDrawTarget::PathTransformType*/ transformT
ype, | 121 int /*GrDrawTarget::PathTransformType*/ transformT
ype, |
60 int count, | 122 int count, |
(...skipping 1079 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1140 } | 1202 } |
1141 | 1203 |
1142 bool GrDrawContext::prepareToDraw(GrRenderTarget* rt) { | 1204 bool GrDrawContext::prepareToDraw(GrRenderTarget* rt) { |
1143 RETURN_FALSE_IF_ABANDONED | 1205 RETURN_FALSE_IF_ABANDONED |
1144 | 1206 |
1145 ASSERT_OWNED_RESOURCE(rt); | 1207 ASSERT_OWNED_RESOURCE(rt); |
1146 SkASSERT(rt); | 1208 SkASSERT(rt); |
1147 return true; | 1209 return true; |
1148 } | 1210 } |
1149 | 1211 |
| 1212 void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrBatch* batch
) { |
| 1213 fDrawTarget->drawBatch(pipelineBuilder, batch); |
| 1214 } |
| 1215 |
1150 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 1216 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
1151 | 1217 |
1152 #ifdef GR_TEST_UTILS | 1218 #ifdef GR_TEST_UTILS |
1153 | 1219 |
1154 BATCH_TEST_DEFINE(StrokeRectBatch) { | 1220 BATCH_TEST_DEFINE(StrokeRectBatch) { |
1155 StrokeRectBatch::Geometry geometry; | 1221 StrokeRectBatch::Geometry geometry; |
1156 geometry.fViewMatrix = GrTest::TestMatrix(random); | 1222 geometry.fViewMatrix = GrTest::TestMatrix(random); |
1157 geometry.fColor = GrRandomColor(random); | 1223 geometry.fColor = GrRandomColor(random); |
1158 geometry.fRect = GrTest::TestRect(random); | 1224 geometry.fRect = GrTest::TestRect(random); |
1159 geometry.fStrokeWidth = random->nextBool() ? 0.0f : 1.0f; | 1225 geometry.fStrokeWidth = random->nextBool() ? 0.0f : 1.0f; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1267 return DrawVerticesBatch::Create(geometry, type, viewMatrix, | 1333 return DrawVerticesBatch::Create(geometry, type, viewMatrix, |
1268 positions.begin(), vertexCount, | 1334 positions.begin(), vertexCount, |
1269 indices.begin(), hasIndices ? vertexCount :
0, | 1335 indices.begin(), hasIndices ? vertexCount :
0, |
1270 colors.begin(), | 1336 colors.begin(), |
1271 texCoords.begin(), | 1337 texCoords.begin(), |
1272 bounds); | 1338 bounds); |
1273 } | 1339 } |
1274 | 1340 |
1275 #endif | 1341 #endif |
1276 | 1342 |
OLD | NEW |