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

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

Issue 1375153007: Dynamically allocate the GrDrawContexts (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix more bugs 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
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"
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 20
20 #include "batches/GrBatch.h" 21 #include "batches/GrBatch.h"
21 #include "batches/GrDrawAtlasBatch.h" 22 #include "batches/GrDrawAtlasBatch.h"
22 #include "batches/GrDrawVerticesBatch.h" 23 #include "batches/GrDrawVerticesBatch.h"
23 #include "batches/GrRectBatchFactory.h" 24 #include "batches/GrRectBatchFactory.h"
24 25
25 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == fContext) 26 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == fContext)
26 #define RETURN_IF_ABANDONED if (!fDrawTarget) { return; } 27 #define RETURN_IF_ABANDONED if (fContext->abandoned()) { return; }
27 #define RETURN_FALSE_IF_ABANDONED if (!fDrawTarget) { return false; } 28 #define RETURN_FALSE_IF_ABANDONED if (fContext->abandoned()) { return false; }
28 #define RETURN_NULL_IF_ABANDONED if (!fDrawTarget) { return nullptr; } 29 #define RETURN_NULL_IF_ABANDONED if (fContext->abandoned()) { return nullptr; }
29 30
30 class AutoCheckFlush { 31 class AutoCheckFlush {
31 public: 32 public:
32 AutoCheckFlush(GrContext* context) : fContext(context) { SkASSERT(context); } 33 AutoCheckFlush(GrContext* context) : fContext(context) { SkASSERT(context); }
33 ~AutoCheckFlush() { fContext->flushIfNecessary(); } 34 ~AutoCheckFlush() { fContext->flushIfNecessary(); }
34 35
35 private: 36 private:
36 GrContext* fContext; 37 GrContext* fContext;
37 }; 38 };
38 39
39 GrDrawContext::GrDrawContext(GrContext* context, 40 GrDrawContext::GrDrawContext(GrContext* context,
40 GrDrawTarget* drawTarget, 41 GrDrawTarget* drawTarget,
41 const SkSurfaceProps& surfaceProps) 42 const SkSurfaceProps* surfaceProps)
42 : fContext(context) 43 : fContext(context)
43 , fDrawTarget(SkRef(drawTarget)) 44 , fDrawTarget(SkRef(drawTarget))
44 , fTextContext(nullptr) 45 , fTextContext(nullptr)
45 , fSurfaceProps(surfaceProps) { 46 , fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps)) {
46 } 47 }
47 48
48 GrDrawContext::~GrDrawContext() { 49 GrDrawContext::~GrDrawContext() {
49 SkSafeUnref(fDrawTarget); 50 SkSafeUnref(fDrawTarget);
50 delete fTextContext;
51 } 51 }
52 52
53 void GrDrawContext::copySurface(GrRenderTarget* dst, GrSurface* src, 53 void GrDrawContext::copySurface(GrRenderTarget* dst, GrSurface* src,
54 const SkIRect& srcRect, const SkIPoint& dstPoint ) { 54 const SkIRect& srcRect, const SkIPoint& dstPoint ) {
55 RETURN_IF_ABANDONED
56
55 if (!this->prepareToDraw(dst)) { 57 if (!this->prepareToDraw(dst)) {
56 return; 58 return;
57 } 59 }
58 60
59 fDrawTarget->copySurface(dst, src, srcRect, dstPoint); 61 fDrawTarget->copySurface(dst, src, srcRect, dstPoint);
60 } 62 }
61 63
62 GrTextContext* GrDrawContext::createTextContext(GrRenderTarget* renderTarget,
63 const SkSurfaceProps& surfacePro ps) {
64 if (fContext->caps()->shaderCaps()->pathRenderingSupport() &&
65 renderTarget->isStencilBufferMultisampled() &&
66 fSurfaceProps.isUseDeviceIndependentFonts()) {
67 GrStencilAttachment* sb =
68 fContext->resourceProvider()->attachStencilAttachment(renderTarget);
69 if (sb) {
70 return GrStencilAndCoverTextContext::Create(fContext, surfaceProps);
71 }
72 }
73
74 return GrAtlasTextContext::Create(fContext, surfaceProps);
75 }
76 64
77 void GrDrawContext::drawText(GrRenderTarget* rt, const GrClip& clip, const GrPai nt& grPaint, 65 void GrDrawContext::drawText(GrRenderTarget* rt, const GrClip& clip, const GrPai nt& grPaint,
78 const SkPaint& skPaint, 66 const SkPaint& skPaint,
79 const SkMatrix& viewMatrix, 67 const SkMatrix& viewMatrix,
80 const char text[], size_t byteLength, 68 const char text[], size_t byteLength,
81 SkScalar x, SkScalar y, const SkIRect& clipBounds) { 69 SkScalar x, SkScalar y, const SkIRect& clipBounds) {
70 RETURN_IF_ABANDONED
71
82 if (!fTextContext) { 72 if (!fTextContext) {
83 fTextContext = this->createTextContext(rt, fSurfaceProps); 73 fTextContext = fContext->textContext(fSurfaceProps, rt);
84 } 74 }
85 75
86 fTextContext->drawText(this, rt, clip, grPaint, skPaint, viewMatrix, 76 fTextContext->drawText(this, rt, clip, grPaint, skPaint, viewMatrix,
87 text, byteLength, x, y, clipBounds); 77 text, byteLength, x, y, clipBounds);
88 78
89 } 79 }
90 void GrDrawContext::drawPosText(GrRenderTarget* rt, const GrClip& clip, const Gr Paint& grPaint, 80 void GrDrawContext::drawPosText(GrRenderTarget* rt, const GrClip& clip, const Gr Paint& grPaint,
91 const SkPaint& skPaint, 81 const SkPaint& skPaint,
92 const SkMatrix& viewMatrix, 82 const SkMatrix& viewMatrix,
93 const char text[], size_t byteLength, 83 const char text[], size_t byteLength,
94 const SkScalar pos[], int scalarsPerPosition, 84 const SkScalar pos[], int scalarsPerPosition,
95 const SkPoint& offset, const SkIRect& clipBounds ) { 85 const SkPoint& offset, const SkIRect& clipBounds ) {
86 RETURN_IF_ABANDONED
87
96 if (!fTextContext) { 88 if (!fTextContext) {
97 fTextContext = this->createTextContext(rt, fSurfaceProps); 89 fTextContext = fContext->textContext(fSurfaceProps, rt);
98 } 90 }
99 91
100 fTextContext->drawPosText(this, rt, clip, grPaint, skPaint, viewMatrix, text , byteLength, 92 fTextContext->drawPosText(this, rt, clip, grPaint, skPaint, viewMatrix, text , byteLength,
101 pos, scalarsPerPosition, offset, clipBounds); 93 pos, scalarsPerPosition, offset, clipBounds);
102 94
103 } 95 }
104 void GrDrawContext::drawTextBlob(GrRenderTarget* rt, const GrClip& clip, const S kPaint& skPaint, 96 void GrDrawContext::drawTextBlob(GrRenderTarget* rt, const GrClip& clip, const S kPaint& skPaint,
105 const SkMatrix& viewMatrix, const SkTextBlob* b lob, 97 const SkMatrix& viewMatrix, const SkTextBlob* b lob,
106 SkScalar x, SkScalar y, 98 SkScalar x, SkScalar y,
107 SkDrawFilter* filter, const SkIRect& clipBounds ) { 99 SkDrawFilter* filter, const SkIRect& clipBounds ) {
100 RETURN_IF_ABANDONED
101
108 if (!fTextContext) { 102 if (!fTextContext) {
109 fTextContext = this->createTextContext(rt, fSurfaceProps); 103 fTextContext = fContext->textContext(fSurfaceProps, rt);
110 } 104 }
111 105
112 fTextContext->drawTextBlob(this, rt, 106 fTextContext->drawTextBlob(this, rt,
113 clip, skPaint, viewMatrix, blob, x, y, filter, cl ipBounds); 107 clip, skPaint, viewMatrix, blob, x, y, filter, cl ipBounds);
114 } 108 }
115 109
116 void GrDrawContext::drawPathsFromRange(const GrPipelineBuilder* pipelineBuilder, 110 void GrDrawContext::drawPathsFromRange(const GrPipelineBuilder* pipelineBuilder,
117 const SkMatrix& viewMatrix, 111 const SkMatrix& viewMatrix,
118 const SkMatrix& localMatrix, 112 const SkMatrix& localMatrix,
119 GrColor color, 113 GrColor color,
120 GrPathRangeDraw* draw, 114 GrPathRangeDraw* draw,
121 int /*GrPathRendering::FillType*/ fill) { 115 int /*GrPathRendering::FillType*/ fill) {
116 RETURN_IF_ABANDONED
117
122 fDrawTarget->drawPathsFromRange(*pipelineBuilder, viewMatrix, localMatrix, c olor, draw, 118 fDrawTarget->drawPathsFromRange(*pipelineBuilder, viewMatrix, localMatrix, c olor, draw,
123 (GrPathRendering::FillType) fill); 119 (GrPathRendering::FillType) fill);
124 } 120 }
125 121
126 void GrDrawContext::discard(GrRenderTarget* renderTarget) { 122 void GrDrawContext::discard(GrRenderTarget* renderTarget) {
127 RETURN_IF_ABANDONED 123 RETURN_IF_ABANDONED
128 SkASSERT(renderTarget); 124 SkASSERT(renderTarget);
129 AutoCheckFlush acf(fContext); 125 AutoCheckFlush acf(fContext);
130 if (!this->prepareToDraw(renderTarget)) { 126 if (!this->prepareToDraw(renderTarget)) {
131 return; 127 return;
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 750
755 bool GrDrawContext::prepareToDraw(GrRenderTarget* rt) { 751 bool GrDrawContext::prepareToDraw(GrRenderTarget* rt) {
756 RETURN_FALSE_IF_ABANDONED 752 RETURN_FALSE_IF_ABANDONED
757 753
758 ASSERT_OWNED_RESOURCE(rt); 754 ASSERT_OWNED_RESOURCE(rt);
759 SkASSERT(rt); 755 SkASSERT(rt);
760 return true; 756 return true;
761 } 757 }
762 758
763 void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrDrawBatch* b atch) { 759 void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrDrawBatch* b atch) {
760 RETURN_IF_ABANDONED
761
764 fDrawTarget->drawBatch(*pipelineBuilder, batch); 762 fDrawTarget->drawBatch(*pipelineBuilder, batch);
765 } 763 }
OLDNEW
« include/gpu/GrContext.h ('K') | « src/gpu/GrContext.cpp ('k') | src/gpu/GrTextContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698