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

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

Issue 1467553002: New API for computing optimization invariants. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years 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/GrPipeline.h ('k') | src/gpu/GrPipelineBuilder.h » ('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 "GrPipeline.h" 8 #include "GrPipeline.h"
9 9
10 #include "GrCaps.h" 10 #include "GrCaps.h"
11 #include "GrDrawTarget.h" 11 #include "GrDrawTarget.h"
12 #include "GrGpu.h" 12 #include "GrGpu.h"
13 #include "GrPipelineBuilder.h" 13 #include "GrPipelineBuilder.h"
14 #include "GrProcOptInfo.h" 14 #include "GrProcOptInfo.h"
15 #include "GrXferProcessor.h" 15 #include "GrXferProcessor.h"
16 16
17 #include "batches/GrBatch.h" 17 #include "batches/GrBatch.h"
18 18
19 GrPipeline* GrPipeline::CreateAt(void* memory, const CreateArgs& args, 19 GrPipeline* GrPipeline::CreateAt(void* memory, const CreateArgs& args,
20 GrPipelineOptimizations* opts) { 20 GrXPOverridesForBatch* overrides) {
21 const GrPipelineBuilder& builder = *args.fPipelineBuilder; 21 const GrPipelineBuilder& builder = *args.fPipelineBuilder;
22 22
23 // Create XferProcessor from DS's XPFactory 23 // Create XferProcessor from DS's XPFactory
24 const GrXPFactory* xpFactory = builder.getXPFactory(); 24 const GrXPFactory* xpFactory = builder.getXPFactory();
25 SkAutoTUnref<GrXferProcessor> xferProcessor; 25 SkAutoTUnref<GrXferProcessor> xferProcessor;
26 if (xpFactory) { 26 if (xpFactory) {
27 xferProcessor.reset(xpFactory->createXferProcessor(args.fColorPOI, 27 xferProcessor.reset(xpFactory->createXferProcessor(args.fOpts.fColorPOI,
28 args.fCoveragePOI, 28 args.fOpts.fCoverageP OI,
29 builder.hasMixedSampl es(), 29 builder.hasMixedSampl es(),
30 &args.fDstTexture, 30 &args.fDstTexture,
31 *args.fCaps)); 31 *args.fCaps));
32 } else { 32 } else {
33 xferProcessor.reset(GrPorterDuffXPFactory::CreateSrcOverXferProcessor( 33 xferProcessor.reset(GrPorterDuffXPFactory::CreateSrcOverXferProcessor(
34 *args.fC aps, 34 *args.fC aps,
35 args.fCo lorPOI, 35 args.fOp ts.fColorPOI,
36 args.fCo veragePOI, 36 args.fOp ts.fCoveragePOI,
37 builder. hasMixedSamples(), 37 builder. hasMixedSamples(),
38 &args.fD stTexture)); 38 &args.fD stTexture));
39 } 39 }
40 40
41 if (!xferProcessor) { 41 if (!xferProcessor) {
42 return nullptr; 42 return nullptr;
43 } 43 }
44 44
45 GrColor overrideColor = GrColor_ILLEGAL; 45 GrColor overrideColor = GrColor_ILLEGAL;
46 if (args.fColorPOI.firstEffectiveProcessorIndex() != 0) { 46 if (args.fOpts.fColorPOI.firstEffectiveProcessorIndex() != 0) {
47 overrideColor = args.fColorPOI.inputColorToFirstEffectiveProccesor(); 47 overrideColor = args.fOpts.fColorPOI.inputColorToFirstEffectiveProccesor ();
48 } 48 }
49 49
50 GrXferProcessor::OptFlags optFlags = GrXferProcessor::kNone_OptFlags; 50 GrXferProcessor::OptFlags optFlags = GrXferProcessor::kNone_OptFlags;
51 51
52 optFlags = xferProcessor->getOptimizations(args.fColorPOI, 52 optFlags = xferProcessor->getOptimizations(args.fOpts.fColorPOI,
53 args.fCoveragePOI, 53 args.fOpts.fCoveragePOI,
54 builder.getStencil().doesWrite() , 54 builder.getStencil().doesWrite(),
55 &overrideColor, 55 &overrideColor,
56 *args.fCaps); 56 *args.fCaps);
57 57
58 // When path rendering the stencil settings are not always set on the GrPipe lineBuilder 58 // When path rendering the stencil settings are not always set on the GrPipe lineBuilder
59 // so we must check the draw type. In cases where we will skip drawing we si mply return a 59 // so we must check the draw type. In cases where we will skip drawing we si mply return a
60 // null GrPipeline. 60 // null GrPipeline.
61 if (GrXferProcessor::kSkipDraw_OptFlag & optFlags) { 61 if (GrXferProcessor::kSkipDraw_OptFlag & optFlags) {
62 return nullptr; 62 return nullptr;
63 } 63 }
64 64
65 // No need to have an override color if it isn't even going to be used. 65 // No need to have an override color if it isn't even going to be used.
66 if (SkToBool(GrXferProcessor::kIgnoreColor_OptFlag & optFlags)) { 66 if (SkToBool(GrXferProcessor::kIgnoreColor_OptFlag & optFlags)) {
(...skipping 10 matching lines...) Expand all
77 pipeline->fDrawFace = builder.getDrawFace(); 77 pipeline->fDrawFace = builder.getDrawFace();
78 78
79 pipeline->fFlags = 0; 79 pipeline->fFlags = 0;
80 if (builder.isHWAntialias()) { 80 if (builder.isHWAntialias()) {
81 pipeline->fFlags |= kHWAA_Flag; 81 pipeline->fFlags |= kHWAA_Flag;
82 } 82 }
83 if (builder.snapVerticesToPixelCenters()) { 83 if (builder.snapVerticesToPixelCenters()) {
84 pipeline->fFlags |= kSnapVertices_Flag; 84 pipeline->fFlags |= kSnapVertices_Flag;
85 } 85 }
86 86
87 int firstColorProcessorIdx = args.fColorPOI.firstEffectiveProcessorIndex(); 87 int firstColorProcessorIdx = args.fOpts.fColorPOI.firstEffectiveProcessorInd ex();
88 88
89 // TODO: Once we can handle single or four channel input into coverage GrFra gmentProcessors 89 // TODO: Once we can handle single or four channel input into coverage GrFra gmentProcessors
90 // then we can use GrPipelineBuilder's coverageProcInfo (like color above) t o set this initial 90 // then we can use GrPipelineBuilder's coverageProcInfo (like color above) t o set this initial
91 // information. 91 // information.
92 int firstCoverageProcessorIdx = 0; 92 int firstCoverageProcessorIdx = 0;
93 93
94 pipeline->adjustProgramFromOptimizations(builder, optFlags, args.fColorPOI, args.fCoveragePOI, 94 pipeline->adjustProgramFromOptimizations(builder, optFlags, args.fOpts.fColo rPOI,
95 &firstColorProcessorIdx, &firstCove rageProcessorIdx); 95 args.fOpts.fCoveragePOI, &firstColo rProcessorIdx,
96 &firstCoverageProcessorIdx);
96 97
97 bool usesLocalCoords = false; 98 bool usesLocalCoords = false;
98 99
99 // Copy GrFragmentProcessors from GrPipelineBuilder to Pipeline 100 // Copy GrFragmentProcessors from GrPipelineBuilder to Pipeline
100 pipeline->fNumColorProcessors = builder.numColorFragmentProcessors() - first ColorProcessorIdx; 101 pipeline->fNumColorProcessors = builder.numColorFragmentProcessors() - first ColorProcessorIdx;
101 int numTotalProcessors = pipeline->fNumColorProcessors + 102 int numTotalProcessors = pipeline->fNumColorProcessors +
102 builder.numCoverageFragmentProcessors() - firstCove rageProcessorIdx; 103 builder.numCoverageFragmentProcessors() - firstCove rageProcessorIdx;
103 pipeline->fFragmentProcessors.reset(numTotalProcessors); 104 pipeline->fFragmentProcessors.reset(numTotalProcessors);
104 int currFPIdx = 0; 105 int currFPIdx = 0;
105 for (int i = firstColorProcessorIdx; i < builder.numColorFragmentProcessors( ); 106 for (int i = firstColorProcessorIdx; i < builder.numColorFragmentProcessors( );
106 ++i, ++currFPIdx) { 107 ++i, ++currFPIdx) {
107 const GrFragmentProcessor* fp = builder.getColorFragmentProcessor(i); 108 const GrFragmentProcessor* fp = builder.getColorFragmentProcessor(i);
108 pipeline->fFragmentProcessors[currFPIdx].reset(fp); 109 pipeline->fFragmentProcessors[currFPIdx].reset(fp);
109 usesLocalCoords = usesLocalCoords || fp->usesLocalCoords(); 110 usesLocalCoords = usesLocalCoords || fp->usesLocalCoords();
110 } 111 }
111 112
112 for (int i = firstCoverageProcessorIdx; i < builder.numCoverageFragmentProce ssors(); 113 for (int i = firstCoverageProcessorIdx; i < builder.numCoverageFragmentProce ssors();
113 ++i, ++currFPIdx) { 114 ++i, ++currFPIdx) {
114 const GrFragmentProcessor* fp = builder.getCoverageFragmentProcessor(i); 115 const GrFragmentProcessor* fp = builder.getCoverageFragmentProcessor(i);
115 pipeline->fFragmentProcessors[currFPIdx].reset(fp); 116 pipeline->fFragmentProcessors[currFPIdx].reset(fp);
116 usesLocalCoords = usesLocalCoords || fp->usesLocalCoords(); 117 usesLocalCoords = usesLocalCoords || fp->usesLocalCoords();
117 } 118 }
118 119
119 // Setup info we need to pass to GrPrimitiveProcessors that are used with th is GrPipeline. 120 // Setup info we need to pass to GrPrimitiveProcessors that are used with th is GrPipeline.
120 opts->fFlags = 0; 121 overrides->fFlags = 0;
121 if (!SkToBool(optFlags & GrXferProcessor::kIgnoreColor_OptFlag)) { 122 if (!SkToBool(optFlags & GrXferProcessor::kIgnoreColor_OptFlag)) {
122 opts->fFlags |= GrPipelineOptimizations::kReadsColor_Flag; 123 overrides->fFlags |= GrXPOverridesForBatch::kReadsColor_Flag;
123 } 124 }
124 if (GrColor_ILLEGAL != overrideColor) { 125 if (GrColor_ILLEGAL != overrideColor) {
125 opts->fFlags |= GrPipelineOptimizations::kUseOverrideColor_Flag; 126 overrides->fFlags |= GrXPOverridesForBatch::kUseOverrideColor_Flag;
126 opts->fOverrideColor = overrideColor; 127 overrides->fOverrideColor = overrideColor;
127 } 128 }
128 if (!SkToBool(optFlags & GrXferProcessor::kIgnoreCoverage_OptFlag)) { 129 if (!SkToBool(optFlags & GrXferProcessor::kIgnoreCoverage_OptFlag)) {
129 opts->fFlags |= GrPipelineOptimizations::kReadsCoverage_Flag; 130 overrides->fFlags |= GrXPOverridesForBatch::kReadsCoverage_Flag;
130 } 131 }
131 if (usesLocalCoords) { 132 if (usesLocalCoords) {
132 opts->fFlags |= GrPipelineOptimizations::kReadsLocalCoords_Flag; 133 overrides->fFlags |= GrXPOverridesForBatch::kReadsLocalCoords_Flag;
133 } 134 }
134 if (SkToBool(optFlags & GrXferProcessor::kCanTweakAlphaForCoverage_OptFlag)) { 135 if (SkToBool(optFlags & GrXferProcessor::kCanTweakAlphaForCoverage_OptFlag)) {
135 opts->fFlags |= GrPipelineOptimizations::kCanTweakAlphaForCoverage_Flag; 136 overrides->fFlags |= GrXPOverridesForBatch::kCanTweakAlphaForCoverage_Fl ag;
136 } 137 }
137 138
138 GrXPFactory::InvariantBlendedColor blendedColor; 139 GrXPFactory::InvariantBlendedColor blendedColor;
139 if (xpFactory) { 140 if (xpFactory) {
140 xpFactory->getInvariantBlendedColor(args.fColorPOI, &blendedColor); 141 xpFactory->getInvariantBlendedColor(args.fOpts.fColorPOI, &blendedColor) ;
141 } else { 142 } else {
142 GrPorterDuffXPFactory::SrcOverInvariantBlendedColor(args.fColorPOI.color (), 143 GrPorterDuffXPFactory::SrcOverInvariantBlendedColor(args.fOpts.fColorPOI .color(),
143 args.fColorPOI.valid Flags(), 144 args.fOpts.fColorPOI .validFlags(),
144 args.fColorPOI.isOpa que(), 145 args.fOpts.fColorPOI .isOpaque(),
145 &blendedColor); 146 &blendedColor);
146 } 147 }
147 if (blendedColor.fWillBlendWithDst) { 148 if (blendedColor.fWillBlendWithDst) {
148 opts->fFlags |= GrPipelineOptimizations::kWillColorBlendWithDst_Flag; 149 overrides->fFlags |= GrXPOverridesForBatch::kWillColorBlendWithDst_Flag;
149 } 150 }
150 151
151 return pipeline; 152 return pipeline;
152 } 153 }
153 154
154 static void add_dependencies_for_processor(const GrFragmentProcessor* proc, GrRe nderTarget* rt) { 155 static void add_dependencies_for_processor(const GrFragmentProcessor* proc, GrRe nderTarget* rt) {
155 for (int i = 0; i < proc->numChildProcessors(); ++i) { 156 for (int i = 0; i < proc->numChildProcessors(); ++i) {
156 // need to recurse 157 // need to recurse
157 add_dependencies_for_processor(&proc->childProcessor(i), rt); 158 add_dependencies_for_processor(&proc->childProcessor(i), rt);
158 } 159 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } 228 }
228 229
229 for (int i = 0; i < a.numFragmentProcessors(); i++) { 230 for (int i = 0; i < a.numFragmentProcessors(); i++) {
230 if (!a.getFragmentProcessor(i).isEqual(b.getFragmentProcessor(i), ignore CoordTransforms)) { 231 if (!a.getFragmentProcessor(i).isEqual(b.getFragmentProcessor(i), ignore CoordTransforms)) {
231 return false; 232 return false;
232 } 233 }
233 } 234 }
234 return true; 235 return true;
235 } 236 }
236 237
OLDNEW
« no previous file with comments | « src/gpu/GrPipeline.h ('k') | src/gpu/GrPipelineBuilder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698