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

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

Issue 1316123003: Style Change: SkNEW->new; SkDELETE->delete (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-26 (Wednesday) 15:59:00 EDT Created 5 years, 3 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/SkLightingShader.h ('k') | src/core/SkLocalMatrixShader.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 /* 2 /*
3 * Copyright 2015 Google Inc. 3 * Copyright 2015 Google Inc.
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 #include "SkBitmapProcState.h" 9 #include "SkBitmapProcState.h"
10 #include "SkColor.h" 10 #include "SkColor.h"
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { 284 void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
285 inout->mulByUnknownFourComponents(); 285 inout->mulByUnknownFourComponents();
286 } 286 }
287 287
288 const SkVector3& lightDir() const { return fLightDir; } 288 const SkVector3& lightDir() const { return fLightDir; }
289 const SkColor3f& lightColor() const { return fLightColor; } 289 const SkColor3f& lightColor() const { return fLightColor; }
290 const SkColor3f& ambientColor() const { return fAmbientColor; } 290 const SkColor3f& ambientColor() const { return fAmbientColor; }
291 const SkVector& invNormRotation() const { return fInvNormRotation; } 291 const SkVector& invNormRotation() const { return fInvNormRotation; }
292 292
293 private: 293 private:
294 GrGLFragmentProcessor* onCreateGLInstance() const override { return SkNEW(Li ghtingGLFP); } 294 GrGLFragmentProcessor* onCreateGLInstance() const override { return new Ligh tingGLFP; }
295 295
296 bool onIsEqual(const GrFragmentProcessor& proc) const override { 296 bool onIsEqual(const GrFragmentProcessor& proc) const override {
297 const LightingFP& lightingFP = proc.cast<LightingFP>(); 297 const LightingFP& lightingFP = proc.cast<LightingFP>();
298 return fDiffDeviceTransform == lightingFP.fDiffDeviceTransform && 298 return fDiffDeviceTransform == lightingFP.fDiffDeviceTransform &&
299 fNormDeviceTransform == lightingFP.fNormDeviceTransform && 299 fNormDeviceTransform == lightingFP.fNormDeviceTransform &&
300 fDiffuseTextureAccess == lightingFP.fDiffuseTextureAccess && 300 fDiffuseTextureAccess == lightingFP.fDiffuseTextureAccess &&
301 fNormalTextureAccess == lightingFP.fNormalTextureAccess && 301 fNormalTextureAccess == lightingFP.fNormalTextureAccess &&
302 fLightDir == lightingFP.fLightDir && 302 fLightDir == lightingFP.fLightDir &&
303 fLightColor == lightingFP.fLightColor && 303 fLightColor == lightingFP.fLightColor &&
304 fAmbientColor == lightingFP.fAmbientColor && 304 fAmbientColor == lightingFP.fAmbientColor &&
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 386
387 GrTextureParams normParams(kClamp_TileMode, normFilterMode); 387 GrTextureParams normParams(kClamp_TileMode, normFilterMode);
388 SkAutoTUnref<GrTexture> normalTexture(GrRefCachedBitmapTexture(context, 388 SkAutoTUnref<GrTexture> normalTexture(GrRefCachedBitmapTexture(context,
389 fNormalMap, & normParams)); 389 fNormalMap, & normParams));
390 if (!normalTexture) { 390 if (!normalTexture) {
391 SkErrorInternals::SetError(kInternalError_SkError, 391 SkErrorInternals::SetError(kInternalError_SkError,
392 "Couldn't convert bitmap to texture."); 392 "Couldn't convert bitmap to texture.");
393 return false; 393 return false;
394 } 394 }
395 395
396 396 *fp = new LightingFP(pdm, diffuseTexture, normalTexture, diffM, normM, diffP arams, normParams,
397 *fp = SkNEW_ARGS(LightingFP, (pdm, diffuseTexture, normalTexture, 397 fLights, fInvNormRotation);
398 diffM, normM, diffParams, normParams, fLights,
399 fInvNormRotation));
400 398
401 *color = GrColorPackA4(paint.getAlpha()); 399 *color = GrColorPackA4(paint.getAlpha());
402 return true; 400 return true;
403 } 401 }
404 #else 402 #else
405 403
406 bool SkLightingShaderImpl::asFragmentProcessor(GrContext* context, const SkPaint & paint, 404 bool SkLightingShaderImpl::asFragmentProcessor(GrContext* context, const SkPaint & paint,
407 const SkMatrix& viewM, const SkMa trix* localMatrix, 405 const SkMatrix& viewM, const SkMa trix* localMatrix,
408 GrColor* color, GrProcessorDataMa nager*, 406 GrColor* color, GrProcessorDataMa nager*,
409 GrFragmentProcessor** fp) const { 407 GrFragmentProcessor** fp) const {
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 SkVector3 dir; 606 SkVector3 dir;
609 if (!buf.readScalarArray(&dir.fX, 3)) { 607 if (!buf.readScalarArray(&dir.fX, 3)) {
610 return NULL; 608 return NULL;
611 } 609 }
612 builder.add(SkLight(color, dir)); 610 builder.add(SkLight(color, dir));
613 } 611 }
614 } 612 }
615 613
616 SkAutoTUnref<const SkLightingShader::Lights> lights(builder.finish()); 614 SkAutoTUnref<const SkLightingShader::Lights> lights(builder.finish());
617 615
618 return SkNEW_ARGS(SkLightingShaderImpl, (diffuse, normal, lights, 616 return new SkLightingShaderImpl(diffuse, normal, lights, SkVector::Make(1.0f , 0.0f),
619 SkVector::Make(1.0f, 0.0f), 617 &diffLocalM, &normLocalM);
620 &diffLocalM, &normLocalM));
621 } 618 }
622 619
623 void SkLightingShaderImpl::flatten(SkWriteBuffer& buf) const { 620 void SkLightingShaderImpl::flatten(SkWriteBuffer& buf) const {
624 this->INHERITED::flatten(buf); 621 this->INHERITED::flatten(buf);
625 622
626 bool hasNormLocalM = !fNormLocalMatrix.isIdentity(); 623 bool hasNormLocalM = !fNormLocalMatrix.isIdentity();
627 buf.writeBool(hasNormLocalM); 624 buf.writeBool(hasNormLocalM);
628 if (hasNormLocalM) { 625 if (hasNormLocalM) {
629 buf.writeMatrix(fNormLocalMatrix); 626 buf.writeMatrix(fNormLocalMatrix);
630 } 627 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 SkMatrix diffTotalInv; 662 SkMatrix diffTotalInv;
666 // computeTotalInverse was called in SkShader::createContext so we know it w ill succeed 663 // computeTotalInverse was called in SkShader::createContext so we know it w ill succeed
667 SkAssertResult(this->computeTotalInverse(rec, &diffTotalInv)); 664 SkAssertResult(this->computeTotalInverse(rec, &diffTotalInv));
668 665
669 SkMatrix normTotalInv; 666 SkMatrix normTotalInv;
670 if (!this->computeNormTotalInverse(rec, &normTotalInv)) { 667 if (!this->computeNormTotalInverse(rec, &normTotalInv)) {
671 return NULL; 668 return NULL;
672 } 669 }
673 670
674 void* diffuseStateStorage = (char*)storage + sizeof(LightingShaderContext); 671 void* diffuseStateStorage = (char*)storage + sizeof(LightingShaderContext);
675 SkBitmapProcState* diffuseState = SkNEW_PLACEMENT(diffuseStateStorage, SkBit mapProcState); 672 SkBitmapProcState* diffuseState = new (diffuseStateStorage) SkBitmapProcStat e;
676 SkASSERT(diffuseState); 673 SkASSERT(diffuseState);
677 674
678 diffuseState->fTileModeX = SkShader::kClamp_TileMode; 675 diffuseState->fTileModeX = SkShader::kClamp_TileMode;
679 diffuseState->fTileModeY = SkShader::kClamp_TileMode; 676 diffuseState->fTileModeY = SkShader::kClamp_TileMode;
680 diffuseState->fOrigBitmap = fDiffuseMap; 677 diffuseState->fOrigBitmap = fDiffuseMap;
681 if (!diffuseState->chooseProcs(diffTotalInv, *rec.fPaint)) { 678 if (!diffuseState->chooseProcs(diffTotalInv, *rec.fPaint)) {
682 diffuseState->~SkBitmapProcState(); 679 diffuseState->~SkBitmapProcState();
683 return NULL; 680 return NULL;
684 } 681 }
685 682
686 void* normalStateStorage = (char*)storage + sizeof(LightingShaderContext) + sizeof(SkBitmapProcState); 683 void* normalStateStorage = (char*)storage + sizeof(LightingShaderContext) + sizeof(SkBitmapProcState);
687 SkBitmapProcState* normalState = SkNEW_PLACEMENT(normalStateStorage, SkBitma pProcState); 684 SkBitmapProcState* normalState = new (normalStateStorage) SkBitmapProcState;
688 SkASSERT(normalState); 685 SkASSERT(normalState);
689 686
690 normalState->fTileModeX = SkShader::kClamp_TileMode; 687 normalState->fTileModeX = SkShader::kClamp_TileMode;
691 normalState->fTileModeY = SkShader::kClamp_TileMode; 688 normalState->fTileModeY = SkShader::kClamp_TileMode;
692 normalState->fOrigBitmap = fNormalMap; 689 normalState->fOrigBitmap = fNormalMap;
693 if (!normalState->chooseProcs(normTotalInv, *rec.fPaint)) { 690 if (!normalState->chooseProcs(normTotalInv, *rec.fPaint)) {
694 diffuseState->~SkBitmapProcState(); 691 diffuseState->~SkBitmapProcState();
695 normalState->~SkBitmapProcState(); 692 normalState->~SkBitmapProcState();
696 return NULL; 693 return NULL;
697 } 694 }
698 695
699 return SkNEW_PLACEMENT_ARGS(storage, LightingShaderContext, (*this, rec, 696 return new (storage) LightingShaderContext(*this, rec, diffuseState, normalS tate);
700 diffuseState, n ormalState));
701 } 697 }
702 698
703 /////////////////////////////////////////////////////////////////////////////// 699 ///////////////////////////////////////////////////////////////////////////////
704 700
705 static bool bitmap_is_too_big(const SkBitmap& bm) { 701 static bool bitmap_is_too_big(const SkBitmap& bm) {
706 // SkBitmapProcShader stores bitmap coordinates in a 16bit buffer, as it 702 // SkBitmapProcShader stores bitmap coordinates in a 16bit buffer, as it
707 // communicates between its matrix-proc and its sampler-proc. Until we can 703 // communicates between its matrix-proc and its sampler-proc. Until we can
708 // widen that, we have to reject bitmaps that are larger. 704 // widen that, we have to reject bitmaps that are larger.
709 // 705 //
710 static const int kMaxSize = 65535; 706 static const int kMaxSize = 65535;
711 707
712 return bm.width() > kMaxSize || bm.height() > kMaxSize; 708 return bm.width() > kMaxSize || bm.height() > kMaxSize;
713 } 709 }
714 710
715 SkShader* SkLightingShader::Create(const SkBitmap& diffuse, const SkBitmap& norm al, 711 SkShader* SkLightingShader::Create(const SkBitmap& diffuse, const SkBitmap& norm al,
716 const Lights* lights, 712 const Lights* lights,
717 const SkVector& invNormRotation, 713 const SkVector& invNormRotation,
718 const SkMatrix* diffLocalM, const SkMatrix* n ormLocalM) { 714 const SkMatrix* diffLocalM, const SkMatrix* n ormLocalM) {
719 if (diffuse.isNull() || bitmap_is_too_big(diffuse) || 715 if (diffuse.isNull() || bitmap_is_too_big(diffuse) ||
720 normal.isNull() || bitmap_is_too_big(normal) || 716 normal.isNull() || bitmap_is_too_big(normal) ||
721 diffuse.width() != normal.width() || 717 diffuse.width() != normal.width() ||
722 diffuse.height() != normal.height()) { 718 diffuse.height() != normal.height()) {
723 return nullptr; 719 return nullptr;
724 } 720 }
725 721
726 SkASSERT(SkScalarNearlyEqual(invNormRotation.lengthSqd(), SK_Scalar1)); 722 SkASSERT(SkScalarNearlyEqual(invNormRotation.lengthSqd(), SK_Scalar1));
727 723
728 return SkNEW_ARGS(SkLightingShaderImpl, (diffuse, normal, lights, 724 return new SkLightingShaderImpl(diffuse, normal, lights, invNormRotation, di ffLocalM,
729 invNormRotation, diffLocalM, normLo calM)); 725 normLocalM);
730 } 726 }
731 727
732 /////////////////////////////////////////////////////////////////////////////// 728 ///////////////////////////////////////////////////////////////////////////////
733 729
734 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) 730 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader)
735 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) 731 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl)
736 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 732 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
737 733
738 /////////////////////////////////////////////////////////////////////////////// 734 ///////////////////////////////////////////////////////////////////////////////
OLDNEW
« no previous file with comments | « src/core/SkLightingShader.h ('k') | src/core/SkLocalMatrixShader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698