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

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

Issue 630063002: Make createOptDrawState return NULL if we would end up not drawing (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase and Nits Created 6 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
« no previous file with comments | « src/gpu/GrOptDrawState.h ('k') | src/gpu/gl/GrGpuGL_program.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 2014 Google Inc. 2 * Copyright 2014 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 "GrOptDrawState.h" 8 #include "GrOptDrawState.h"
9 9
10 #include "GrDrawState.h" 10 #include "GrDrawState.h"
11 #include "GrDrawTargetCaps.h" 11 #include "GrDrawTargetCaps.h"
12 #include "GrGpu.h"
13 12
14 GrOptDrawState::GrOptDrawState(const GrDrawState& drawState, 13 GrOptDrawState::GrOptDrawState(const GrDrawState& drawState,
15 BlendOptFlags blendOptFlags, 14 BlendOptFlags blendOptFlags,
16 GrBlendCoeff optSrcCoeff, 15 GrBlendCoeff optSrcCoeff,
17 GrBlendCoeff optDstCoeff, 16 GrBlendCoeff optDstCoeff,
18 const GrDrawTargetCaps& caps) { 17 const GrDrawTargetCaps& caps) {
19 fRenderTarget.set(SkSafeRef(drawState.getRenderTarget()), 18 fRenderTarget.set(SkSafeRef(drawState.getRenderTarget()),
20 GrIORef::kWrite_IOType); 19 GrIORef::kWrite_IOType);
21 fColor = drawState.getColor(); 20 fColor = drawState.getColor();
22 fCoverage = drawState.getCoverage(); 21 fCoverage = drawState.getCoverage();
(...skipping 23 matching lines...) Expand all
46 fGeometryProcessor.reset(NULL); 45 fGeometryProcessor.reset(NULL);
47 } 46 }
48 47
49 this->copyEffectiveColorStages(drawState); 48 this->copyEffectiveColorStages(drawState);
50 this->copyEffectiveCoverageStages(drawState); 49 this->copyEffectiveCoverageStages(drawState);
51 this->adjustFromBlendOpts(); 50 this->adjustFromBlendOpts();
52 this->getStageStats(); 51 this->getStageStats();
53 this->setOutputStateInfo(caps); 52 this->setOutputStateInfo(caps);
54 }; 53 };
55 54
55 GrOptDrawState* GrOptDrawState::Create(const GrDrawState& drawState, const GrDra wTargetCaps& caps,
56 GrGpu::DrawType drawType) {
57 if (NULL == drawState.fCachedOptState || caps.getUniqueID() != drawState.fCa chedCapsID) {
58 GrBlendCoeff srcCoeff;
59 GrBlendCoeff dstCoeff;
60 BlendOptFlags blendFlags = (BlendOptFlags) drawState.getBlendOpts(false,
61 &srcCo eff,
62 &dstCo eff);
63
64 // If our blend coeffs are set to 0,1 we know we will not end up drawing unless we are
65 // stenciling. When path rendering the stencil settings are not always s et on the draw state
66 // so we must check the draw type. In cases where we will skip drawing w e simply return a
67 // null GrOptDrawState.
68 if (kZero_GrBlendCoeff == srcCoeff && kOne_GrBlendCoeff == dstCoeff &&
69 !drawState.getStencil().doesWrite() && GrGpu::kStencilPath_DrawType != drawType) {
70 return NULL;
71 }
72
73 drawState.fCachedOptState = SkNEW_ARGS(GrOptDrawState, (drawState, blend Flags, srcCoeff,
74 dstCoeff, caps)) ;
75 drawState.fCachedCapsID = caps.getUniqueID();
76 } else {
77 #ifdef SK_DEBUG
78 GrBlendCoeff srcCoeff;
79 GrBlendCoeff dstCoeff;
80 BlendOptFlags blendFlags = (BlendOptFlags) drawState.getBlendOpts(false,
81 &srcCo eff,
82 &dstCo eff);
83 SkASSERT(GrOptDrawState(drawState, blendFlags, srcCoeff, dstCoeff, caps) ==
84 *drawState.fCachedOptState);
85 #endif
86 }
87 drawState.fCachedOptState->ref();
88 return drawState.fCachedOptState;
89 }
90
56 void GrOptDrawState::setOutputStateInfo(const GrDrawTargetCaps& caps) { 91 void GrOptDrawState::setOutputStateInfo(const GrDrawTargetCaps& caps) {
57 // Set this default and then possibly change our mind if there is coverage. 92 // Set this default and then possibly change our mind if there is coverage.
58 fPrimaryOutputType = kModulate_PrimaryOutputType; 93 fPrimaryOutputType = kModulate_PrimaryOutputType;
59 fSecondaryOutputType = kNone_SecondaryOutputType; 94 fSecondaryOutputType = kNone_SecondaryOutputType;
60 95
61 // If we do have coverage determine whether it matters. 96 // If we do have coverage determine whether it matters.
62 bool separateCoverageFromColor = this->hasGeometryProcessor(); 97 bool separateCoverageFromColor = this->hasGeometryProcessor();
63 if (!this->isCoverageDrawing() && 98 if (!this->isCoverageDrawing() &&
64 (this->numCoverageStages() > 0 || 99 (this->numCoverageStages() > 0 ||
65 this->hasGeometryProcessor() || 100 this->hasGeometryProcessor() ||
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 } 366 }
332 } 367 }
333 368
334 SkASSERT(0 == memcmp(this->fFixedFunctionVertexAttribIndices, 369 SkASSERT(0 == memcmp(this->fFixedFunctionVertexAttribIndices,
335 that.fFixedFunctionVertexAttribIndices, 370 that.fFixedFunctionVertexAttribIndices,
336 sizeof(this->fFixedFunctionVertexAttribIndices))); 371 sizeof(this->fFixedFunctionVertexAttribIndices)));
337 372
338 return true; 373 return true;
339 } 374 }
340 375
OLDNEW
« no previous file with comments | « src/gpu/GrOptDrawState.h ('k') | src/gpu/gl/GrGpuGL_program.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698