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

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

Issue 1806983002: Update how we send draws to gpu backend to reduce state setting. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: nit Created 4 years, 9 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/GrDrawAtlasBatch.cpp ('k') | src/gpu/batches/GrDrawVerticesBatch.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrDrawPathBatch.h" 8 #include "GrDrawPathBatch.h"
9 9
10 static void pre_translate_transform_values(const float* xforms, 10 static void pre_translate_transform_values(const float* xforms,
11 GrPathRendering::PathTransformType ty pe, int count, 11 GrPathRendering::PathTransformType ty pe, int count,
12 SkScalar x, SkScalar y, float* dst); 12 SkScalar x, SkScalar y, float* dst);
13 13
14 SkString GrDrawPathBatch::dumpInfo() const { 14 SkString GrDrawPathBatch::dumpInfo() const {
15 SkString string; 15 SkString string;
16 string.printf("PATH: 0x%p", fPath.get()); 16 string.printf("PATH: 0x%p", fPath.get());
17 return string; 17 return string;
18 } 18 }
19 19
20 void GrDrawPathBatch::onDraw(GrBatchFlushState* state) { 20 void GrDrawPathBatch::onDraw(GrBatchFlushState* state) {
21 GrProgramDesc desc; 21 GrProgramDesc desc;
22 22
23 SkAutoTUnref<GrPathProcessor> pathProc(GrPathProcessor::Create(this->color() , 23 SkAutoTUnref<GrPathProcessor> pathProc(GrPathProcessor::Create(this->color() ,
24 this->overrid es(), 24 this->overrid es(),
25 this->viewMat rix())); 25 this->viewMat rix()));
26 state->gpu()->buildProgramDesc(&desc, *pathProc, *this->pipeline()); 26 state->gpu()->pathRendering()->drawPath(*this->pipeline(), *pathProc, this-> stencilSettings(),
27 GrPathRendering::DrawPathArgs args(pathProc, this->pipeline(), 27 fPath.get());
28 &desc, &this->stencilSettings());
29 state->gpu()->pathRendering()->drawPath(args, fPath.get());
30 } 28 }
31 29
32 SkString GrDrawPathRangeBatch::dumpInfo() const { 30 SkString GrDrawPathRangeBatch::dumpInfo() const {
33 SkString string; 31 SkString string;
34 string.printf("RANGE: 0x%p COUNTS: [", fPathRange.get()); 32 string.printf("RANGE: 0x%p COUNTS: [", fPathRange.get());
35 for (DrawList::Iter iter(fDraws); iter.get(); iter.next()) { 33 for (DrawList::Iter iter(fDraws); iter.get(); iter.next()) {
36 string.appendf("%d, ", iter.get()->fInstanceData->count()); 34 string.appendf("%d, ", iter.get()->fInstanceData->count());
37 } 35 }
38 string.remove(string.size() - 2, 2); 36 string.remove(string.size() - 2, 2);
39 string.append("]"); 37 string.append("]");
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 114
117 SkMatrix localMatrix; 115 SkMatrix localMatrix;
118 localMatrix.setScale(fScale, fScale); 116 localMatrix.setScale(fScale, fScale);
119 localMatrix.preTranslate(head.fX, head.fY); 117 localMatrix.preTranslate(head.fX, head.fY);
120 118
121 SkAutoTUnref<GrPathProcessor> pathProc(GrPathProcessor::Create(this->color() , 119 SkAutoTUnref<GrPathProcessor> pathProc(GrPathProcessor::Create(this->color() ,
122 this->overrid es(), 120 this->overrid es(),
123 drawMatrix, 121 drawMatrix,
124 localMatrix)) ; 122 localMatrix)) ;
125 123
126 GrProgramDesc desc;
127 state->gpu()->buildProgramDesc(&desc, *pathProc, *this->pipeline());
128 GrPathRendering::DrawPathArgs args(pathProc, this->pipeline(),
129 &desc, &this->stencilSettings());
130
131 if (fDraws.count() == 1) { 124 if (fDraws.count() == 1) {
132 const InstanceData& instances = *head.fInstanceData; 125 const InstanceData& instances = *head.fInstanceData;
133 state->gpu()->pathRendering()->drawPaths(args, fPathRange.get(), instanc es.indices(), 126 state->gpu()->pathRendering()->drawPaths(*this->pipeline(),
127 *pathProc,
128 this->stencilSettings(),
129 fPathRange.get(),
130 instances.indices(),
134 GrPathRange::kU16_PathIndexType , 131 GrPathRange::kU16_PathIndexType ,
135 instances.transformValues(), 132 instances.transformValues(),
136 instances.transformType(), 133 instances.transformType(),
137 instances.count()); 134 instances.count());
138 } else { 135 } else {
139 int floatsPerTransform = GrPathRendering::PathTransformSize(this->transf ormType()); 136 int floatsPerTransform = GrPathRendering::PathTransformSize(this->transf ormType());
140 SkAutoSTMalloc<4096, float> transformStorage(floatsPerTransform * fTotal PathCount); 137 SkAutoSTMalloc<4096, float> transformStorage(floatsPerTransform * fTotal PathCount);
141 SkAutoSTMalloc<2048, uint16_t> indexStorage(fTotalPathCount); 138 SkAutoSTMalloc<2048, uint16_t> indexStorage(fTotalPathCount);
142 int idx = 0; 139 int idx = 0;
143 for (DrawList::Iter iter(fDraws); iter.get(); iter.next()) { 140 for (DrawList::Iter iter(fDraws); iter.get(); iter.next()) {
144 const Draw& draw = *iter.get(); 141 const Draw& draw = *iter.get();
145 const InstanceData& instances = *draw.fInstanceData; 142 const InstanceData& instances = *draw.fInstanceData;
146 memcpy(&indexStorage[idx], instances.indices(), instances.count() * sizeof(uint16_t)); 143 memcpy(&indexStorage[idx], instances.indices(), instances.count() * sizeof(uint16_t));
147 pre_translate_transform_values(instances.transformValues(), this->tr ansformType(), 144 pre_translate_transform_values(instances.transformValues(), this->tr ansformType(),
148 instances.count(), 145 instances.count(),
149 draw.fX - head.fX, draw.fY - head.fY, 146 draw.fX - head.fX, draw.fY - head.fY,
150 &transformStorage[floatsPerTransform * idx]); 147 &transformStorage[floatsPerTransform * idx]);
151 idx += instances.count(); 148 idx += instances.count();
152 149
153 // TODO: Support mismatched transform types if we start using more t ypes other than 2D. 150 // TODO: Support mismatched transform types if we start using more t ypes other than 2D.
154 SkASSERT(instances.transformType() == this->transformType()); 151 SkASSERT(instances.transformType() == this->transformType());
155 } 152 }
156 SkASSERT(idx == fTotalPathCount); 153 SkASSERT(idx == fTotalPathCount);
157 154
158 state->gpu()->pathRendering()->drawPaths(args, fPathRange.get(), indexSt orage, 155 state->gpu()->pathRendering()->drawPaths(*this->pipeline(),
159 GrPathRange::kU16_PathIndexType , transformStorage, 156 *pathProc,
160 this->transformType(), fTotalPa thCount); 157 this->stencilSettings(),
158 fPathRange.get(),
159 indexStorage,
160 GrPathRange::kU16_PathIndexType ,
161 transformStorage,
162 this->transformType(),
163 fTotalPathCount);
161 } 164 }
162 } 165 }
163 166
164 inline void pre_translate_transform_values(const float* xforms, 167 inline void pre_translate_transform_values(const float* xforms,
165 GrPathRendering::PathTransformType ty pe, int count, 168 GrPathRendering::PathTransformType ty pe, int count,
166 SkScalar x, SkScalar y, float* dst) { 169 SkScalar x, SkScalar y, float* dst) {
167 if (0 == x && 0 == y) { 170 if (0 == x && 0 == y) {
168 memcpy(dst, xforms, count * GrPathRendering::PathTransformSize(type) * s izeof(float)); 171 memcpy(dst, xforms, count * GrPathRendering::PathTransformSize(type) * s izeof(float));
169 return; 172 return;
170 } 173 }
(...skipping 27 matching lines...) Expand all
198 dst[i + 3] = xforms[i + 3]; 201 dst[i + 3] = xforms[i + 3];
199 dst[i + 4] = xforms[i + 4]; 202 dst[i + 4] = xforms[i + 4];
200 dst[i + 5] = xforms[i + 3] * x + xforms[i + 4] * y + xforms[i + 5]; 203 dst[i + 5] = xforms[i + 3] * x + xforms[i + 4] * y + xforms[i + 5];
201 } 204 }
202 break; 205 break;
203 default: 206 default:
204 SkFAIL("Unknown transform type."); 207 SkFAIL("Unknown transform type.");
205 break; 208 break;
206 } 209 }
207 } 210 }
OLDNEW
« no previous file with comments | « src/gpu/batches/GrDrawAtlasBatch.cpp ('k') | src/gpu/batches/GrDrawVerticesBatch.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698