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

Side by Side Diff: src/gpu/batches/GrDrawPathBatch.cpp

Issue 1315563003: GrPathRangeBatch (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix init order warning Created 5 years, 3 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
« no previous file with comments | « src/gpu/batches/GrDrawPathBatch.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "GrDrawPathBatch.h"
9
10 SkString GrDrawPathBatch::dumpInfo() const {
11 SkString string;
12 string.printf("PATH: 0x%p", fPath.get());
13 return string;
14 }
15
16 void GrDrawPathBatch::onDraw(GrBatchFlushState* state) {
17 GrProgramDesc desc;
18 state->gpu()->buildProgramDesc(&desc, *this->pathProcessor(),
19 *this->pipeline(), *this->tracker());
20 GrPathRendering::DrawPathArgs args(this->pathProcessor(), this->pipeline(),
21 &desc, this->tracker(), &this->stencilSe ttings());
22 state->gpu()->pathRendering()->drawPath(args, fPath.get());
23 }
24
25 GrDrawPathRangeBatch::~GrDrawPathRangeBatch() {
26 for (DrawList::Iter iter(fDraws); iter.get(); iter.next()) {
27 (*iter.get())->unref();
28 }
29 }
30
31 SkString GrDrawPathRangeBatch::dumpInfo() const {
32 SkString string;
33 string.printf("RANGE: 0x%p COUNTS: [", *fDraws.head());
34 for (DrawList::Iter iter(fDraws); iter.get(); iter.next()) {
35 string.appendf("%d ,", (*iter.get())->count());
36 }
37 string.remove(string.size() - 2, 2);
38 string.append("]");
39 return string;
40 }
41
42 bool GrDrawPathRangeBatch::isWinding() const {
43 static const GrStencilSettings::Face pathFace = GrStencilSettings::kFront_Fa ce;
44 bool isWinding = kInvert_StencilOp != this->stencilSettings().passOp(pathFac e);
45 if (isWinding) {
46 // Double check that it is in fact winding.
47 SkASSERT(kIncClamp_StencilOp == this->stencilSettings().passOp(pathFace) );
48 SkASSERT(kIncClamp_StencilOp == this->stencilSettings().failOp(pathFace) );
49 SkASSERT(0x1 != this->stencilSettings().writeMask(pathFace));
50 SkASSERT(!this->stencilSettings().isTwoSided());
51 }
52 return isWinding;
53 }
54
55 GrDrawPathRangeBatch::GrDrawPathRangeBatch(const GrPathProcessor* pathProc,
56 GrPathRangeDraw* pathRangeDraw)
57 : INHERITED(pathProc)
58 , fDraws(4) {
59 SkDEBUGCODE(pathRangeDraw->fUsedInBatch = true;)
60 this->initClassID<GrDrawPathRangeBatch>();
61 fDraws.addToHead(SkRef(pathRangeDraw));
62 fTotalPathCount = pathRangeDraw->count();
63 // Don't compute a bounding box. For dst copy texture, we'll opt instead for it to just copy
64 // the entire dst. Realistically this is a moot point, because any context t hat supports
65 // NV_path_rendering will also support NV_blend_equation_advanced.
66 // For clipping we'll just skip any optimizations based on the bounds.
67 fBounds.setLargest();
68 }
69
70 bool GrDrawPathRangeBatch::onCombineIfPossible(GrBatch* t, const GrCaps& caps) {
71 GrDrawPathRangeBatch* that = t->cast<GrDrawPathRangeBatch>();
72 if (!GrPathRangeDraw::CanMerge(**this->fDraws.head(), **that->fDraws.head()) ) {
73 return false;
74 }
75 if (!GrPipeline::AreEqual(*this->pipeline(), *that->pipeline(), false)) {
76 return false;
77 }
78 if (!this->pathProcessor()->isEqual(*this->tracker(), *that->pathProcessor() ,
79 *that->tracker())) {
80 return false;
81 }
82 // TODO: Check some other things here. (winding, opaque, pathProc color, vm, ...)
83 // Try to combine this call with the previous DrawPaths. We do this by stenc iling all the
84 // paths together and then covering them in a single pass. This is not equiv alent to two
85 // separate draw calls, so we can only do it if there is no blending (no ove rlap would also
86 // work). Note that it's also possible for overlapping paths to cancel each other's winding
87 // numbers, and we only partially account for this by not allowing even/odd paths to be
88 // combined. (Glyphs in the same font tend to wind the same direction so it works out OK.)
89 if (!this->isWinding() ||
90 this->stencilSettings() != that->stencilSettings() ||
91 this->opts().willColorBlendWithDst()) {
92 return false;
93 }
94 SkASSERT(!that->opts().willColorBlendWithDst());
95 fTotalPathCount += that->fTotalPathCount;
96 while (GrPathRangeDraw** head = that->fDraws.head()) {
97 fDraws.addToTail(*head);
98 // We're stealing that's refs, so pop without unreffing.
99 that->fDraws.popHead();
100 }
101 return true;
102 }
103
104 void GrDrawPathRangeBatch::onDraw(GrBatchFlushState* state) {
105 GrProgramDesc desc;
106 state->gpu()->buildProgramDesc(&desc, *this->pathProcessor(), *this->pipelin e(),
107 *this->tracker());
108 GrPathRendering::DrawPathArgs args(this->pathProcessor(), this->pipeline(),
109 &desc, this->tracker(), &this->stencilSe ttings());
110 if (fDraws.count() == 1) {
111 const GrPathRangeDraw& draw = **fDraws.head();
112 state->gpu()->pathRendering()->drawPaths(args, draw.range(), draw.indice s(),
113 GrPathRange::kU16_PathIndexType, draw.transforms(), draw.transformTy pe(),
114 draw.count());
115 return;
116 }
117
118 const GrPathRange* range = (*fDraws.head())->range();
119 GrPathRendering::PathTransformType transformType = (*fDraws.head())->transfo rmType();
120 int floatsPerTransform = GrPathRendering::PathTransformSize(transformType);
121 SkAutoSTMalloc<512, float> transformStorage(floatsPerTransform * fTotalPathC ount);
122 SkAutoSTMalloc<256, uint16_t> indexStorage(fTotalPathCount);
123 uint16_t* indices = indexStorage.get();
124 float* transforms = transformStorage.get();
125 for (DrawList::Iter iter(fDraws); iter.get(); iter.next()) {
126 SkASSERT((*iter.get())->transformType() == transformType);
127 SkASSERT((*iter.get())->range() == range);
128 int cnt = (*iter.get())->count();
129 memcpy(indices, (*iter.get())->indices(), cnt * sizeof(uint16_t));
130 indices += cnt;
131 memcpy(transforms, (*iter.get())->transforms(), cnt * floatsPerTransform * sizeof(float));
132 transforms += cnt * floatsPerTransform;
133 }
134 SkASSERT(indices - indexStorage.get() == fTotalPathCount);
135 state->gpu()->pathRendering()->drawPaths(args, range, indexStorage.get(),
136 GrPathRange::kU16_PathIndexType, transformStorage.get(), transformType,
137 fTotalPathCount);
138 }
OLDNEW
« no previous file with comments | « src/gpu/batches/GrDrawPathBatch.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698