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

Side by Side Diff: src/core/SkComposeShader.cpp

Issue 261773005: Remove SkShader virtual method validContext (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: create SkTransparentShaderContext to use if the shader context fails to create Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
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 9
10 #include "SkComposeShader.h" 10 #include "SkComposeShader.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 }; 66 };
67 #define SkAutoAlphaRestore(...) SK_REQUIRE_LOCAL_VAR(SkAutoAlphaRestore) 67 #define SkAutoAlphaRestore(...) SK_REQUIRE_LOCAL_VAR(SkAutoAlphaRestore)
68 68
69 void SkComposeShader::flatten(SkWriteBuffer& buffer) const { 69 void SkComposeShader::flatten(SkWriteBuffer& buffer) const {
70 this->INHERITED::flatten(buffer); 70 this->INHERITED::flatten(buffer);
71 buffer.writeFlattenable(fShaderA); 71 buffer.writeFlattenable(fShaderA);
72 buffer.writeFlattenable(fShaderB); 72 buffer.writeFlattenable(fShaderB);
73 buffer.writeFlattenable(fMode); 73 buffer.writeFlattenable(fMode);
74 } 74 }
75 75
76 /* We call validContext/createContext on our two worker shaders. 76 SkShader::Context* SkComposeShader::onCreateContext(const ContextRec& rec, void* storage) const {
77 However, we always let them see opaque alpha, and if the paint
78 really is translucent, then we apply that after the fact.
79
80 */
81 bool SkComposeShader::validContext(const ContextRec& rec, SkMatrix* totalInverse ) const {
82 if (!this->INHERITED::validContext(rec, totalInverse)) {
83 return false;
84 }
85
86 // we preconcat our localMatrix (if any) with the device matrix
87 // before calling our sub-shaders
88
89 SkMatrix tmpM;
90 tmpM.setConcat(*rec.fMatrix, this->getLocalMatrix());
91
92 ContextRec newRec(rec);
93 newRec.fMatrix = &tmpM;
94
95 return fShaderA->validContext(newRec) && fShaderB->validContext(newRec);
96 }
97
98 SkShader::Context* SkComposeShader::createContext(const ContextRec& rec, void* s torage) const {
99 if (!this->validContext(rec)) {
100 return NULL;
101 }
102
103 // TODO : must fix this to not "cheat" and modify fPaint
104 SkAutoAlphaRestore restore(const_cast<SkPaint*>(rec.fPaint), 0xFF);
105
106 char* aStorage = (char*) storage + sizeof(ComposeShaderContext); 77 char* aStorage = (char*) storage + sizeof(ComposeShaderContext);
107 char* bStorage = aStorage + fShaderA->contextSize(); 78 char* bStorage = aStorage + fShaderA->contextSize();
108 79
109 // we preconcat our localMatrix (if any) with the device matrix 80 // we preconcat our localMatrix (if any) with the device matrix
110 // before calling our sub-shaders 81 // before calling our sub-shaders
111 82
112 SkMatrix tmpM; 83 SkMatrix tmpM;
113 tmpM.setConcat(*rec.fMatrix, this->getLocalMatrix()); 84 tmpM.setConcat(*rec.fMatrix, this->getLocalMatrix());
114 85
115 ContextRec newRec(rec); 86 ContextRec newRec(rec);
116 newRec.fMatrix = &tmpM; 87 newRec.fMatrix = &tmpM;
117 88
118 SkShader::Context* contextA = fShaderA->createContext(newRec, aStorage); 89 SkShader::Context* contextA = fShaderA->createContext(newRec, aStorage);
119 SkShader::Context* contextB = fShaderB->createContext(newRec, bStorage); 90 SkShader::Context* contextB = fShaderB->createContext(newRec, bStorage);
120 91 if (!contextA || !contextB) {
121 // Both functions must succeed; otherwise validContext should have returned 92 return NULL;
122 // false. 93 }
123 SkASSERT(contextA);
124 SkASSERT(contextB);
125 94
126 return SkNEW_PLACEMENT_ARGS(storage, ComposeShaderContext, (*this, rec, cont extA, contextB)); 95 return SkNEW_PLACEMENT_ARGS(storage, ComposeShaderContext, (*this, rec, cont extA, contextB));
127 } 96 }
128 97
129 SkComposeShader::ComposeShaderContext::ComposeShaderContext( 98 SkComposeShader::ComposeShaderContext::ComposeShaderContext(
130 const SkComposeShader& shader, const ContextRec& rec, 99 const SkComposeShader& shader, const ContextRec& rec,
131 SkShader::Context* contextA, SkShader::Context* contextB) 100 SkShader::Context* contextA, SkShader::Context* contextB)
132 : INHERITED(shader, rec) 101 : INHERITED(shader, rec)
133 , fShaderContextA(contextA) 102 , fShaderContextA(contextA)
134 , fShaderContextB(contextB) {} 103 , fShaderContextB(contextB) {}
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 str->append(" ShaderB: "); 179 str->append(" ShaderB: ");
211 fShaderB->toString(str); 180 fShaderB->toString(str);
212 str->append(" Xfermode: "); 181 str->append(" Xfermode: ");
213 fMode->toString(str); 182 fMode->toString(str);
214 183
215 this->INHERITED::toString(str); 184 this->INHERITED::toString(str);
216 185
217 str->append(")"); 186 str->append(")");
218 } 187 }
219 #endif 188 #endif
OLDNEW
« src/core/SkBlitter.cpp ('K') | « src/core/SkBlitter.cpp ('k') | src/core/SkDraw.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698