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

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

Issue 2041113004: sk_sp for gpu. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Reserve correctly. 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
« no previous file with comments | « src/core/SkImageFilter.cpp ('k') | src/core/SkLocalMatrixShader.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 "SkBitmapProcState.h" 8 #include "SkBitmapProcState.h"
9 #include "SkColor.h" 9 #include "SkColor.h"
10 #include "SkEmptyShader.h" 10 #include "SkEmptyShader.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 fNormLocalMatrix.reset(); 65 fNormLocalMatrix.reset();
66 } 66 }
67 // Pre-cache so future calls to fNormLocalMatrix.getType() are threadsaf e. 67 // Pre-cache so future calls to fNormLocalMatrix.getType() are threadsaf e.
68 (void)fNormLocalMatrix.getType(); 68 (void)fNormLocalMatrix.getType();
69 69
70 } 70 }
71 71
72 bool isOpaque() const override; 72 bool isOpaque() const override;
73 73
74 #if SK_SUPPORT_GPU 74 #if SK_SUPPORT_GPU
75 const GrFragmentProcessor* asFragmentProcessor(GrContext*, 75 sk_sp<GrFragmentProcessor> asFragmentProcessor(GrContext*,
76 const SkMatrix& viewM, 76 const SkMatrix& viewM,
77 const SkMatrix* localMatrix, 77 const SkMatrix* localMatrix,
78 SkFilterQuality, 78 SkFilterQuality,
79 SkSourceGammaTreatment) const override; 79 SkSourceGammaTreatment) const override;
80 #endif 80 #endif
81 81
82 class LightingShaderContext : public SkShader::Context { 82 class LightingShaderContext : public SkShader::Context {
83 public: 83 public:
84 // The context takes ownership of the states. It will call their destruc tors 84 // The context takes ownership of the states. It will call their destruc tors
85 // but will NOT free the memory. 85 // but will NOT free the memory.
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 if (!localMatrix2->invert(&inv)) { 343 if (!localMatrix2->invert(&inv)) {
344 return false; 344 return false;
345 } 345 }
346 lmInverse.postConcat(inv); 346 lmInverse.postConcat(inv);
347 } 347 }
348 result->preConcat(lmInverse); 348 result->preConcat(lmInverse);
349 349
350 return true; 350 return true;
351 } 351 }
352 352
353 const GrFragmentProcessor* SkLightingShaderImpl::asFragmentProcessor( 353 sk_sp<GrFragmentProcessor> SkLightingShaderImpl::asFragmentProcessor(
354 GrContext* context, 354 GrContext* context,
355 const SkMatrix& viewM, 355 const SkMatrix& viewM,
356 const SkMatrix* localMatrix , 356 const SkMatrix* localMatrix ,
357 SkFilterQuality filterQuali ty, 357 SkFilterQuality filterQuali ty,
358 SkSourceGammaTreatment gamm aTreatment) const { 358 SkSourceGammaTreatment gamm aTreatment) const {
359 // we assume diffuse and normal maps have same width and height 359 // we assume diffuse and normal maps have same width and height
360 // TODO: support different sizes 360 // TODO: support different sizes
361 SkASSERT(fDiffuseMap.width() == fNormalMap.width() && 361 SkASSERT(fDiffuseMap.width() == fNormalMap.width() &&
362 fDiffuseMap.height() == fNormalMap.height()); 362 fDiffuseMap.height() == fNormalMap.height());
363 SkMatrix diffM, normM; 363 SkMatrix diffM, normM;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 397
398 GrTextureParams normParams(kClamp_TileMode, normFilterMode); 398 GrTextureParams normParams(kClamp_TileMode, normFilterMode);
399 SkAutoTUnref<GrTexture> normalTexture(GrRefCachedBitmapTexture(context, 399 SkAutoTUnref<GrTexture> normalTexture(GrRefCachedBitmapTexture(context,
400 fNormalMap, n ormParams, 400 fNormalMap, n ormParams,
401 gammaTreatmen t)); 401 gammaTreatmen t));
402 if (!normalTexture) { 402 if (!normalTexture) {
403 SkErrorInternals::SetError(kInternalError_SkError, "Couldn't convert bit map to texture."); 403 SkErrorInternals::SetError(kInternalError_SkError, "Couldn't convert bit map to texture.");
404 return nullptr; 404 return nullptr;
405 } 405 }
406 406
407 SkAutoTUnref<const GrFragmentProcessor> inner ( 407 sk_sp<GrFragmentProcessor> inner (
408 new LightingFP(diffuseTexture, normalTexture, diffM, normM, diffParams, normParams, fLights, 408 new LightingFP(diffuseTexture, normalTexture, diffM, normM, diffParams, normParams, fLights,
409 fInvNormRotation)); 409 fInvNormRotation));
410 return GrFragmentProcessor::MulOutputByInputAlpha(inner); 410 return GrFragmentProcessor::MulOutputByInputAlpha(std::move(inner));
411 } 411 }
412 412
413 #endif 413 #endif
414 414
415 //////////////////////////////////////////////////////////////////////////// 415 ////////////////////////////////////////////////////////////////////////////
416 416
417 bool SkLightingShaderImpl::isOpaque() const { 417 bool SkLightingShaderImpl::isOpaque() const {
418 return fDiffuseMap.isOpaque(); 418 return fDiffuseMap.isOpaque();
419 } 419 }
420 420
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 invNormRotation, diffLocalM, normLoc alM); 726 invNormRotation, diffLocalM, normLoc alM);
727 } 727 }
728 728
729 /////////////////////////////////////////////////////////////////////////////// 729 ///////////////////////////////////////////////////////////////////////////////
730 730
731 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) 731 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader)
732 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) 732 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl)
733 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 733 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
734 734
735 /////////////////////////////////////////////////////////////////////////////// 735 ///////////////////////////////////////////////////////////////////////////////
OLDNEW
« no previous file with comments | « src/core/SkImageFilter.cpp ('k') | src/core/SkLocalMatrixShader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698