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

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

Issue 1175553002: Make GrTextContext be owned by the GrDrawContext (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Added more dox Created 5 years, 6 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
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 "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() && renderTarget-> isMultisampled()) {
65 GrStencilAttachment* sb = renderTarget->renderTargetPriv().attachStencil Attachment();
66 if (sb) {
67 return GrStencilAndCoverTextContext::Create(fContext, this,
68 leakyProperties,
69 enableDistanceFieldFonts );
70 }
71 }
72
73 return GrAtlasTextContext::Create(fContext, this, leakyProperties, enableDis tanceFieldFonts);
74 }
75
76 void GrDrawContext::drawText(GrRenderTarget* rt, const GrClip& clip, const GrPai nt& grPaint,
77 const SkPaint& skPaint,
78 const SkMatrix& viewMatrix,
79 const char text[], size_t byteLength,
80 SkScalar x, SkScalar y, const SkIRect& clipBounds) {
81 if (!fTextContext) {
82 fTextContext = this->createTextContext(rt, *fDevProps, fUseDFT);
83 }
84
85 fTextContext->drawText(rt, clip, grPaint, skPaint, viewMatrix,
86 text, byteLength, x, y, clipBounds);
87
88 }
89 void GrDrawContext::drawPosText(GrRenderTarget* rt, const GrClip& clip, const Gr Paint& grPaint,
90 const SkPaint& skPaint,
91 const SkMatrix& viewMatrix,
92 const char text[], size_t byteLength,
93 const SkScalar pos[], int scalarsPerPosition,
94 const SkPoint& offset, const SkIRect& clipBounds ) {
95 if (!fTextContext) {
96 fTextContext = this->createTextContext(rt, *fDevProps, fUseDFT);
97 }
98
99 fTextContext->drawPosText(rt, clip, grPaint, skPaint, viewMatrix, text, byte Length,
100 pos, scalarsPerPosition, offset, clipBounds);
101
102 }
103 void GrDrawContext::drawTextBlob(GrRenderTarget* rt, const GrClip& clip, const S kPaint& skPaint,
104 const SkMatrix& viewMatrix, const SkTextBlob* b lob,
105 SkScalar x, SkScalar y,
106 SkDrawFilter* filter, const SkIRect& clipBounds ) {
107 if (!fTextContext) {
108 fTextContext = this->createTextContext(rt, *fDevProps, fUseDFT);
109 }
110
111 fTextContext->drawTextBlob(rt, clip, skPaint, viewMatrix, blob, x, y, filter , clipBounds);
51 } 112 }
52 113
53 void GrDrawContext::drawPaths(GrPipelineBuilder* pipelineBuilder, 114 void GrDrawContext::drawPaths(GrPipelineBuilder* pipelineBuilder,
54 const GrPathProcessor* pathProc, 115 const GrPathProcessor* pathProc,
55 const GrPathRange* pathRange, 116 const GrPathRange* pathRange,
56 const void* indices, 117 const void* indices,
57 int /*GrDrawTarget::PathIndexType*/ indexType, 118 int /*GrDrawTarget::PathIndexType*/ indexType,
58 const float transformValues[], 119 const float transformValues[],
59 int /*GrDrawTarget::PathTransformType*/ transformT ype, 120 int /*GrDrawTarget::PathTransformType*/ transformT ype,
60 int count, 121 int count,
(...skipping 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 } 1200 }
1140 1201
1141 bool GrDrawContext::prepareToDraw(GrRenderTarget* rt) { 1202 bool GrDrawContext::prepareToDraw(GrRenderTarget* rt) {
1142 RETURN_FALSE_IF_ABANDONED 1203 RETURN_FALSE_IF_ABANDONED
1143 1204
1144 ASSERT_OWNED_RESOURCE(rt); 1205 ASSERT_OWNED_RESOURCE(rt);
1145 SkASSERT(rt); 1206 SkASSERT(rt);
1146 return true; 1207 return true;
1147 } 1208 }
1148 1209
1210 void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrBatch* batch ) {
1211 fDrawTarget->drawBatch(pipelineBuilder, batch);
1212 }
1213
1149 //////////////////////////////////////////////////////////////////////////////// /////////////////// 1214 //////////////////////////////////////////////////////////////////////////////// ///////////////////
1150 1215
1151 #ifdef GR_TEST_UTILS 1216 #ifdef GR_TEST_UTILS
1152 1217
1153 BATCH_TEST_DEFINE(StrokeRectBatch) { 1218 BATCH_TEST_DEFINE(StrokeRectBatch) {
1154 StrokeRectBatch::Geometry geometry; 1219 StrokeRectBatch::Geometry geometry;
1155 geometry.fViewMatrix = GrTest::TestMatrix(random); 1220 geometry.fViewMatrix = GrTest::TestMatrix(random);
1156 geometry.fColor = GrRandomColor(random); 1221 geometry.fColor = GrRandomColor(random);
1157 geometry.fRect = GrTest::TestRect(random); 1222 geometry.fRect = GrTest::TestRect(random);
1158 geometry.fStrokeWidth = random->nextBool() ? 0.0f : 1.0f; 1223 geometry.fStrokeWidth = random->nextBool() ? 0.0f : 1.0f;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1266 return DrawVerticesBatch::Create(geometry, type, viewMatrix, 1331 return DrawVerticesBatch::Create(geometry, type, viewMatrix,
1267 positions.begin(), vertexCount, 1332 positions.begin(), vertexCount,
1268 indices.begin(), hasIndices ? vertexCount : 0, 1333 indices.begin(), hasIndices ? vertexCount : 0,
1269 colors.begin(), 1334 colors.begin(),
1270 texCoords.begin(), 1335 texCoords.begin(),
1271 bounds); 1336 bounds);
1272 } 1337 }
1273 1338
1274 #endif 1339 #endif
1275 1340
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698