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

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

Issue 2043393002: Refactoring of GPU NormalMap handling out into its own class (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Created 4 years, 6 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
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 "SkBitmapProcState.h" 8 #include "SkBitmapProcState.h"
9 #include "SkColor.h" 9 #include "SkColor.h"
10 #include "SkEmptyShader.h" 10 #include "SkEmptyShader.h"
11 #include "SkErrorInternals.h" 11 #include "SkErrorInternals.h"
12 #include "SkLightingShader.h" 12 #include "SkLightingShader.h"
13 #include "SkMathPriv.h" 13 #include "SkMathPriv.h"
14 #include "SkPoint3.h" 14 #include "SkPoint3.h"
15 #include "SkReadBuffer.h" 15 #include "SkReadBuffer.h"
16 #include "SkWriteBuffer.h" 16 #include "SkWriteBuffer.h"
17 #include "SkNormalSourceImpl.h"
egdaniel 2016/06/09 16:56:37 we place include in alphabetical order, so move th
dvonbeck 2016/06/09 18:51:29 Done.
17 18
18 //////////////////////////////////////////////////////////////////////////// 19 ////////////////////////////////////////////////////////////////////////////
19 20
20 /* 21 /*
21 SkLightingShader TODOs: 22 SkLightingShader TODOs:
22 support other than clamp mode 23 support other than clamp mode
23 allow 'diffuse' & 'normal' to be of different dimensions? 24 allow 'diffuse' & 'normal' to be of different dimensions?
24 support different light types 25 support different light types
25 support multiple lights 26 support multiple lights
26 enforce normal map is 4 channel 27 enforce normal map is 4 channel
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 , fInvNormRotation(invNormRotation) { 61 , fInvNormRotation(invNormRotation) {
61 62
62 if (normLocalM) { 63 if (normLocalM) {
63 fNormLocalMatrix = *normLocalM; 64 fNormLocalMatrix = *normLocalM;
64 } else { 65 } else {
65 fNormLocalMatrix.reset(); 66 fNormLocalMatrix.reset();
66 } 67 }
67 // Pre-cache so future calls to fNormLocalMatrix.getType() are threadsaf e. 68 // Pre-cache so future calls to fNormLocalMatrix.getType() are threadsaf e.
68 (void)fNormLocalMatrix.getType(); 69 (void)fNormLocalMatrix.getType();
69 70
71 fNormalSource = NormalMapSource::Make(fNormalMap, fInvNormRotation, &fNo rmLocalMatrix);
70 } 72 }
71 73
72 bool isOpaque() const override; 74 bool isOpaque() const override;
73 75
74 #if SK_SUPPORT_GPU 76 #if SK_SUPPORT_GPU
75 const GrFragmentProcessor* asFragmentProcessor(GrContext*, 77 const GrFragmentProcessor* asFragmentProcessor(GrContext*,
76 const SkMatrix& viewM, 78 const SkMatrix& viewM,
77 const SkMatrix* localMatrix, 79 const SkMatrix* localMatrix,
78 SkFilterQuality, 80 SkFilterQuality,
79 SkSourceGammaTreatment) const override; 81 SkSourceGammaTreatment) const override;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 SkBitmap fDiffuseMap; 114 SkBitmap fDiffuseMap;
113 SkBitmap fNormalMap; 115 SkBitmap fNormalMap;
114 116
115 sk_sp<SkLights> fLights; 117 sk_sp<SkLights> fLights;
116 118
117 SkMatrix fNormLocalMatrix; 119 SkMatrix fNormLocalMatrix;
118 SkVector fInvNormRotation; 120 SkVector fInvNormRotation;
119 121
120 friend class SkLightingShader; 122 friend class SkLightingShader;
121 123
124 sk_sp<NormalSource> fNormalSource;
125
122 typedef SkShader INHERITED; 126 typedef SkShader INHERITED;
123 }; 127 };
124 128
125 //////////////////////////////////////////////////////////////////////////// 129 ////////////////////////////////////////////////////////////////////////////
126 130
127 #if SK_SUPPORT_GPU 131 #if SK_SUPPORT_GPU
128 132
129 #include "GrCoordTransform.h" 133 #include "GrCoordTransform.h"
130 #include "GrFragmentProcessor.h" 134 #include "GrFragmentProcessor.h"
131 #include "GrInvariantOutput.h" 135 #include "GrInvariantOutput.h"
132 #include "GrTextureAccess.h" 136 #include "GrTextureAccess.h"
133 #include "glsl/GrGLSLFragmentProcessor.h" 137 #include "glsl/GrGLSLFragmentProcessor.h"
134 #include "glsl/GrGLSLFragmentShaderBuilder.h" 138 #include "glsl/GrGLSLFragmentShaderBuilder.h"
135 #include "glsl/GrGLSLProgramDataManager.h" 139 #include "glsl/GrGLSLProgramDataManager.h"
136 #include "glsl/GrGLSLUniformHandler.h" 140 #include "glsl/GrGLSLUniformHandler.h"
137 #include "SkGr.h" 141 #include "SkGr.h"
138 #include "SkGrPriv.h" 142 #include "SkGrPriv.h"
139 143
140 class LightingFP : public GrFragmentProcessor { 144 class LightingFP : public GrFragmentProcessor {
141 public: 145 public:
142 LightingFP(GrTexture* diffuse, GrTexture* normal, const SkMatrix& diffMatrix , 146 LightingFP(GrTexture* diffuse, const SkMatrix& diffMatrix, const GrTexturePa rams& diffParams,
143 const SkMatrix& normMatrix, const GrTextureParams& diffParams, 147 sk_sp<SkLights> lights, const GrFragmentProcessor* normalFP)
144 const GrTextureParams& normParams, sk_sp<SkLights> lights,
145 const SkVector& invNormRotation)
146 : fDiffDeviceTransform(kLocal_GrCoordSet, diffMatrix, diffuse, diffParam s.filterMode()) 148 : fDiffDeviceTransform(kLocal_GrCoordSet, diffMatrix, diffuse, diffParam s.filterMode())
147 , fNormDeviceTransform(kLocal_GrCoordSet, normMatrix, normal, normParams .filterMode()) 149 , fDiffuseTextureAccess(diffuse, diffParams) {
148 , fDiffuseTextureAccess(diffuse, diffParams)
149 , fNormalTextureAccess(normal, normParams)
150 , fInvNormRotation(invNormRotation) {
151 this->addCoordTransform(&fDiffDeviceTransform); 150 this->addCoordTransform(&fDiffDeviceTransform);
152 this->addCoordTransform(&fNormDeviceTransform);
153 this->addTextureAccess(&fDiffuseTextureAccess); 151 this->addTextureAccess(&fDiffuseTextureAccess);
154 this->addTextureAccess(&fNormalTextureAccess);
155 152
156 // fuse all ambient lights into a single one 153 // fuse all ambient lights into a single one
157 fAmbientColor.set(0.0f, 0.0f, 0.0f); 154 fAmbientColor.set(0.0f, 0.0f, 0.0f);
158 for (int i = 0; i < lights->numLights(); ++i) { 155 for (int i = 0; i < lights->numLights(); ++i) {
159 if (SkLights::Light::kAmbient_LightType == lights->light(i).type()) { 156 if (SkLights::Light::kAmbient_LightType == lights->light(i).type()) {
160 fAmbientColor += lights->light(i).color(); 157 fAmbientColor += lights->light(i).color();
161 } else { 158 } else {
162 // TODO: handle more than one of these 159 // TODO: handle more than one of these
163 fLightColor = lights->light(i).color(); 160 fLightColor = lights->light(i).color();
164 fLightDir = lights->light(i).dir(); 161 fLightDir = lights->light(i).dir();
165 } 162 }
166 } 163 }
167 164
165 this->registerChildProcessor(normalFP);
168 this->initClassID<LightingFP>(); 166 this->initClassID<LightingFP>();
169 } 167 }
170 168
171 class LightingGLFP : public GrGLSLFragmentProcessor { 169 class LightingGLFP : public GrGLSLFragmentProcessor {
172 public: 170 public:
173 LightingGLFP() { 171 LightingGLFP() {
174 fLightDir.fX = 10000.0f; 172 fLightDir.fX = 10000.0f;
175 fLightColor.fX = 0.0f; 173 fLightColor.fX = 0.0f;
176 fAmbientColor.fX = 0.0f; 174 fAmbientColor.fX = 0.0f;
177 fInvNormRotation.set(0.0f, 0.0f);
178 } 175 }
179 176
180 void emitCode(EmitArgs& args) override { 177 void emitCode(EmitArgs& args) override {
181 178
182 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; 179 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
183 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; 180 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
184 181
185 // add uniforms 182 // add uniforms
186 const char* lightDirUniName = nullptr; 183 const char* lightDirUniName = nullptr;
187 fLightDirUni = uniformHandler->addUniform(kFragment_GrShaderFlag, 184 fLightDirUni = uniformHandler->addUniform(kFragment_GrShaderFlag,
188 kVec3f_GrSLType, kDefault_ GrSLPrecision, 185 kVec3f_GrSLType, kDefault_ GrSLPrecision,
189 "LightDir", &lightDirUniNa me); 186 "LightDir", &lightDirUniNa me);
190 187
191 const char* lightColorUniName = nullptr; 188 const char* lightColorUniName = nullptr;
192 fLightColorUni = uniformHandler->addUniform(kFragment_GrShaderFlag, 189 fLightColorUni = uniformHandler->addUniform(kFragment_GrShaderFlag,
193 kVec3f_GrSLType, kDefaul t_GrSLPrecision, 190 kVec3f_GrSLType, kDefaul t_GrSLPrecision,
194 "LightColor", &lightColo rUniName); 191 "LightColor", &lightColo rUniName);
195 192
196 const char* ambientColorUniName = nullptr; 193 const char* ambientColorUniName = nullptr;
197 fAmbientColorUni = uniformHandler->addUniform(kFragment_GrShaderFlag , 194 fAmbientColorUni = uniformHandler->addUniform(kFragment_GrShaderFlag ,
198 kVec3f_GrSLType, kDefa ult_GrSLPrecision, 195 kVec3f_GrSLType, kDefa ult_GrSLPrecision,
199 "AmbientColor", &ambie ntColorUniName); 196 "AmbientColor", &ambie ntColorUniName);
200 197
201 const char* xformUniName = nullptr;
202 fXformUni = uniformHandler->addUniform(kFragment_GrShaderFlag,
203 kVec2f_GrSLType, kDefault_GrS LPrecision,
204 "Xform", &xformUniName);
205
206 fragBuilder->codeAppend("vec4 diffuseColor = "); 198 fragBuilder->codeAppend("vec4 diffuseColor = ");
207 fragBuilder->appendTextureLookupAndModulate(args.fInputColor, args.f TexSamplers[0], 199 fragBuilder->appendTextureLookupAndModulate(args.fInputColor, args.f TexSamplers[0],
208 args.fCoords[0].c_str(), 200 args.fCoords[0].c_str(),
209 args.fCoords[0].getType()); 201 args.fCoords[0].getType());
210 fragBuilder->codeAppend(";"); 202 fragBuilder->codeAppend(";");
211 203
212 fragBuilder->codeAppend("vec4 normalColor = "); 204 SkString dstNormalName("dstNormal");
213 fragBuilder->appendTextureLookup(args.fTexSamplers[1], 205 this->emitChild(0, nullptr, &dstNormalName, args);
214 args.fCoords[1].c_str(),
215 args.fCoords[1].getType());
216 fragBuilder->codeAppend(";");
217 206
218 fragBuilder->codeAppend("vec3 normal = normalColor.rgb - vec3(0.5);" ); 207 fragBuilder->codeAppendf("vec3 normal = %s.xyz;", dstNormalName.c_st r());
219
220 fragBuilder->codeAppendf(
221 "mat3 m = mat3(%s.x, -%s.y, 0.0, %s.y, %s.x, 0. 0, 0.0, 0.0, 1.0);",
222 xformUniName, xformUniName, xformUniName, xform UniName);
223
224 // TODO: inverse map the light direction vectors in the vertex shade r rather than
225 // transforming all the normals here!
226 fragBuilder->codeAppend("normal = normalize(m*normal);");
227
228 fragBuilder->codeAppendf("float NdotL = clamp(dot(normal, %s), 0.0, 1.0);", 208 fragBuilder->codeAppendf("float NdotL = clamp(dot(normal, %s), 0.0, 1.0);",
229 lightDirUniName); 209 lightDirUniName);
230 // diffuse light 210 // diffuse light
231 fragBuilder->codeAppendf("vec3 result = %s*diffuseColor.rgb*NdotL;", lightColorUniName); 211 fragBuilder->codeAppendf("vec3 result = %s*diffuseColor.rgb*NdotL;", lightColorUniName);
232 // ambient light 212 // ambient light
233 fragBuilder->codeAppendf("result += %s;", ambientColorUniName); 213 fragBuilder->codeAppendf("result += %s;", ambientColorUniName);
234 fragBuilder->codeAppendf("%s = vec4(result.rgb, diffuseColor.a);", a rgs.fOutputColor); 214 fragBuilder->codeAppendf("%s = vec4(result.rgb, diffuseColor.a);", a rgs.fOutputColor);
235 } 215 }
236 216
217 // TODO does this need changing now?
egdaniel 2016/06/09 16:56:37 It shouldn't need to. The parent and child process
dvonbeck 2016/06/09 18:51:28 Done.
237 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, 218 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&,
238 GrProcessorKeyBuilder* b) { 219 GrProcessorKeyBuilder* b) {
239 // const LightingFP& lightingFP = proc.cast<LightingFP>(); 220 // const LightingFP& lightingFP = proc.cast<LightingFP>();
240 // only one shader generated currently 221 // only one shader generated currently
241 b->add32(0x0); 222 b->add32(0x0);
242 } 223 }
243 224
244 protected: 225 protected:
245 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) override { 226 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) override {
246 const LightingFP& lightingFP = proc.cast<LightingFP>(); 227 const LightingFP& lightingFP = proc.cast<LightingFP>();
247 228
248 const SkVector3& lightDir = lightingFP.lightDir(); 229 const SkVector3& lightDir = lightingFP.lightDir();
249 if (lightDir != fLightDir) { 230 if (lightDir != fLightDir) {
250 pdman.set3fv(fLightDirUni, 1, &lightDir.fX); 231 pdman.set3fv(fLightDirUni, 1, &lightDir.fX);
251 fLightDir = lightDir; 232 fLightDir = lightDir;
252 } 233 }
253 234
254 const SkColor3f& lightColor = lightingFP.lightColor(); 235 const SkColor3f& lightColor = lightingFP.lightColor();
255 if (lightColor != fLightColor) { 236 if (lightColor != fLightColor) {
256 pdman.set3fv(fLightColorUni, 1, &lightColor.fX); 237 pdman.set3fv(fLightColorUni, 1, &lightColor.fX);
257 fLightColor = lightColor; 238 fLightColor = lightColor;
258 } 239 }
259 240
260 const SkColor3f& ambientColor = lightingFP.ambientColor(); 241 const SkColor3f& ambientColor = lightingFP.ambientColor();
261 if (ambientColor != fAmbientColor) { 242 if (ambientColor != fAmbientColor) {
262 pdman.set3fv(fAmbientColorUni, 1, &ambientColor.fX); 243 pdman.set3fv(fAmbientColorUni, 1, &ambientColor.fX);
263 fAmbientColor = ambientColor; 244 fAmbientColor = ambientColor;
264 } 245 }
265
266 const SkVector& invNormRotation = lightingFP.invNormRotation();
267 if (invNormRotation != fInvNormRotation) {
268 pdman.set2fv(fXformUni, 1, &invNormRotation.fX);
269 fInvNormRotation = invNormRotation;
270 }
271 } 246 }
272 247
273 private: 248 private:
274 SkVector3 fLightDir; 249 SkVector3 fLightDir;
275 GrGLSLProgramDataManager::UniformHandle fLightDirUni; 250 GrGLSLProgramDataManager::UniformHandle fLightDirUni;
276 251
277 SkColor3f fLightColor; 252 SkColor3f fLightColor;
278 GrGLSLProgramDataManager::UniformHandle fLightColorUni; 253 GrGLSLProgramDataManager::UniformHandle fLightColorUni;
279 254
280 SkColor3f fAmbientColor; 255 SkColor3f fAmbientColor;
281 GrGLSLProgramDataManager::UniformHandle fAmbientColorUni; 256 GrGLSLProgramDataManager::UniformHandle fAmbientColorUni;
282
283 SkVector fInvNormRotation;
284 GrGLSLProgramDataManager::UniformHandle fXformUni;
285 }; 257 };
286 258
287 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override { 259 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override {
288 LightingGLFP::GenKey(*this, caps, b); 260 LightingGLFP::GenKey(*this, caps, b);
289 } 261 }
290 262
291 const char* name() const override { return "LightingFP"; } 263 const char* name() const override { return "LightingFP"; }
292 264
293 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { 265 void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
294 inout->mulByUnknownFourComponents(); 266 inout->mulByUnknownFourComponents();
295 } 267 }
296 268
297 const SkVector3& lightDir() const { return fLightDir; } 269 const SkVector3& lightDir() const { return fLightDir; }
298 const SkColor3f& lightColor() const { return fLightColor; } 270 const SkColor3f& lightColor() const { return fLightColor; }
299 const SkColor3f& ambientColor() const { return fAmbientColor; } 271 const SkColor3f& ambientColor() const { return fAmbientColor; }
300 const SkVector& invNormRotation() const { return fInvNormRotation; }
301 272
302 private: 273 private:
303 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return new LightingGLFP; } 274 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return new LightingGLFP; }
304 275
305 bool onIsEqual(const GrFragmentProcessor& proc) const override { 276 bool onIsEqual(const GrFragmentProcessor& proc) const override {
306 const LightingFP& lightingFP = proc.cast<LightingFP>(); 277 const LightingFP& lightingFP = proc.cast<LightingFP>();
307 return fDiffDeviceTransform == lightingFP.fDiffDeviceTransform && 278 return fDiffDeviceTransform == lightingFP.fDiffDeviceTransform &&
308 fNormDeviceTransform == lightingFP.fNormDeviceTransform &&
309 fDiffuseTextureAccess == lightingFP.fDiffuseTextureAccess && 279 fDiffuseTextureAccess == lightingFP.fDiffuseTextureAccess &&
310 fNormalTextureAccess == lightingFP.fNormalTextureAccess &&
311 fLightDir == lightingFP.fLightDir && 280 fLightDir == lightingFP.fLightDir &&
312 fLightColor == lightingFP.fLightColor && 281 fLightColor == lightingFP.fLightColor &&
313 fAmbientColor == lightingFP.fAmbientColor && 282 fAmbientColor == lightingFP.fAmbientColor;
314 fInvNormRotation == lightingFP.fInvNormRotation;
315 } 283 }
316 284
317 GrCoordTransform fDiffDeviceTransform; 285 GrCoordTransform fDiffDeviceTransform;
318 GrCoordTransform fNormDeviceTransform;
319 GrTextureAccess fDiffuseTextureAccess; 286 GrTextureAccess fDiffuseTextureAccess;
320 GrTextureAccess fNormalTextureAccess;
321 SkVector3 fLightDir; 287 SkVector3 fLightDir;
322 SkColor3f fLightColor; 288 SkColor3f fLightColor;
323 SkColor3f fAmbientColor; 289 SkColor3f fAmbientColor;
324
325 SkVector fInvNormRotation;
326 }; 290 };
327 291
328 //////////////////////////////////////////////////////////////////////////// 292 ////////////////////////////////////////////////////////////////////////////
329 293
330 static bool make_mat(const SkBitmap& bm, 294 static bool make_mat(const SkBitmap& bm,
331 const SkMatrix& localMatrix1, 295 const SkMatrix& localMatrix1,
332 const SkMatrix* localMatrix2, 296 const SkMatrix* localMatrix2,
333 SkMatrix* result) { 297 SkMatrix* result) {
334 298
335 result->setIDiv(bm.width(), bm.height()); 299 result->setIDiv(bm.width(), bm.height());
336 300
337 SkMatrix lmInverse; 301 SkMatrix lmInverse;
338 if (!localMatrix1.invert(&lmInverse)) { 302 if (!localMatrix1.invert(&lmInverse)) {
339 return false; 303 return false;
340 } 304 }
341 if (localMatrix2) { 305 if (localMatrix2) {
342 SkMatrix inv; 306 SkMatrix inv;
343 if (!localMatrix2->invert(&inv)) { 307 if (!localMatrix2->invert(&inv)) {
344 return false; 308 return false;
345 } 309 }
346 lmInverse.postConcat(inv); 310 lmInverse.postConcat(inv);
347 } 311 }
348 result->preConcat(lmInverse); 312 result->preConcat(lmInverse);
349 313
350 return true; 314 return true;
351 } 315 }
352 316
317 //const GrFragmentProcessor*
318
353 const GrFragmentProcessor* SkLightingShaderImpl::asFragmentProcessor( 319 const GrFragmentProcessor* SkLightingShaderImpl::asFragmentProcessor(
354 GrContext* context, 320 GrContext* context,
355 const SkMatrix& viewM, 321 const SkMatrix& viewM,
356 const SkMatrix* localMatrix , 322 const SkMatrix* localMatrix ,
357 SkFilterQuality filterQuali ty, 323 SkFilterQuality filterQuali ty,
358 SkSourceGammaTreatment gamm aTreatment) const { 324 SkSourceGammaTreatment gamm aTreatment) const {
359 // we assume diffuse and normal maps have same width and height 325 // we assume diffuse and normal maps have same width and height
360 // TODO: support different sizes 326 // TODO: support different sizes
361 SkASSERT(fDiffuseMap.width() == fNormalMap.width() && 327 SkASSERT(fDiffuseMap.width() == fNormalMap.width() &&
362 fDiffuseMap.height() == fNormalMap.height()); 328 fDiffuseMap.height() == fNormalMap.height());
363 SkMatrix diffM, normM; 329 SkMatrix diffM;
364 330
365 if (!make_mat(fDiffuseMap, this->getLocalMatrix(), localMatrix, &diffM)) { 331 if (!make_mat(fDiffuseMap, this->getLocalMatrix(), localMatrix, &diffM)) {
366 return nullptr; 332 return nullptr;
367 } 333 }
368 334
369 if (!make_mat(fNormalMap, fNormLocalMatrix, localMatrix, &normM)) {
370 return nullptr;
371 }
372
373 bool doBicubic; 335 bool doBicubic;
374 GrTextureParams::FilterMode diffFilterMode = GrSkFilterQualityToGrFilterMode ( 336 GrTextureParams::FilterMode diffFilterMode = GrSkFilterQualityToGrFilterMode (
375 SkTMin(filterQuality, kMedium_SkFilterQu ality), 337 SkTMin(filterQuality, kMedium_SkFilterQu ality),
376 viewM, 338 viewM,
377 this->getLocalMatrix(), 339 this->getLocalMatrix(),
378 &doBicubic); 340 &doBicubic);
379 SkASSERT(!doBicubic); 341 SkASSERT(!doBicubic);
380 342
381 GrTextureParams::FilterMode normFilterMode = GrSkFilterQualityToGrFilterMode (
382 SkTMin(filterQuality, kMedium_SkFilterQu ality),
383 viewM,
384 fNormLocalMatrix,
385 &doBicubic);
386 SkASSERT(!doBicubic);
387
388 // TODO: support other tile modes 343 // TODO: support other tile modes
389 GrTextureParams diffParams(kClamp_TileMode, diffFilterMode); 344 GrTextureParams diffParams(kClamp_TileMode, diffFilterMode);
390 SkAutoTUnref<GrTexture> diffuseTexture(GrRefCachedBitmapTexture(context, 345 SkAutoTUnref<GrTexture> diffuseTexture(GrRefCachedBitmapTexture(context,
391 fDiffuseMap, diffParams, 346 fDiffuseMap, diffParams,
392 gammaTreatme nt)); 347 gammaTreatme nt));
393 if (!diffuseTexture) { 348 if (!diffuseTexture) {
394 SkErrorInternals::SetError(kInternalError_SkError, "Couldn't convert bit map to texture."); 349 SkErrorInternals::SetError(kInternalError_SkError, "Couldn't convert bit map to texture.");
395 return nullptr; 350 return nullptr;
396 } 351 }
397 352
398 GrTextureParams normParams(kClamp_TileMode, normFilterMode); 353 // TODO is this correct memory handling?
egdaniel 2016/06/09 16:56:37 should work. When you pass it into LightingFP and
dvonbeck 2016/06/09 18:51:28 The master upstream changed and asFragmentProcesso
399 SkAutoTUnref<GrTexture> normalTexture(GrRefCachedBitmapTexture(context, 354 SkAutoTUnref<const GrFragmentProcessor> normalFP(
400 fNormalMap, n ormParams, 355 fNormalSource->asFragmentProcessor(context, viewM, localMatrix, filt erQuality,
401 gammaTreatmen t)); 356 gammaTreatment)
402 if (!normalTexture) { 357 );
403 SkErrorInternals::SetError(kInternalError_SkError, "Couldn't convert bit map to texture.");
404 return nullptr;
405 }
406
407 SkAutoTUnref<const GrFragmentProcessor> inner ( 358 SkAutoTUnref<const GrFragmentProcessor> inner (
408 new LightingFP(diffuseTexture, normalTexture, diffM, normM, diffParams, normParams, fLights, 359 new LightingFP(diffuseTexture, diffM, diffParams, fLights, normalFP));
409 fInvNormRotation));
410 return GrFragmentProcessor::MulOutputByInputAlpha(inner); 360 return GrFragmentProcessor::MulOutputByInputAlpha(inner);
411 } 361 }
412 362
413 #endif 363 #endif
414 364
415 //////////////////////////////////////////////////////////////////////////// 365 ////////////////////////////////////////////////////////////////////////////
416 366
417 bool SkLightingShaderImpl::isOpaque() const { 367 bool SkLightingShaderImpl::isOpaque() const {
418 return fDiffuseMap.isOpaque(); 368 return fDiffuseMap.isOpaque();
419 } 369 }
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 invNormRotation, diffLocalM, normLoc alM); 676 invNormRotation, diffLocalM, normLoc alM);
727 } 677 }
728 678
729 /////////////////////////////////////////////////////////////////////////////// 679 ///////////////////////////////////////////////////////////////////////////////
730 680
731 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) 681 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader)
732 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) 682 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl)
733 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 683 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
734 684
735 /////////////////////////////////////////////////////////////////////////////// 685 ///////////////////////////////////////////////////////////////////////////////
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698