OLD | NEW |
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 72 |
73 bool isOpaque() const override; | 73 bool isOpaque() const override; |
74 | 74 |
75 #if SK_SUPPORT_GPU | 75 #if SK_SUPPORT_GPU |
76 const GrFragmentProcessor* asFragmentProcessor(GrContext*, | 76 const GrFragmentProcessor* asFragmentProcessor(GrContext*, |
77 const SkMatrix& viewM, | 77 const SkMatrix& viewM, |
78 const SkMatrix* localMatrix, | 78 const SkMatrix* localMatrix, |
79 SkFilterQuality) const overri
de; | 79 SkFilterQuality) const overri
de; |
80 #endif | 80 #endif |
81 | 81 |
82 size_t contextSize(const ContextRec&) const override; | |
83 | |
84 class LightingShaderContext : public SkShader::Context { | 82 class LightingShaderContext : public SkShader::Context { |
85 public: | 83 public: |
86 // 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 |
87 // but will NOT free the memory. | 85 // but will NOT free the memory. |
88 LightingShaderContext(const SkLightingShaderImpl&, const ContextRec&, | 86 LightingShaderContext(const SkLightingShaderImpl&, const ContextRec&, |
89 SkBitmapProcState* diffuseState, SkBitmapProcState
* normalState); | 87 SkBitmapProcState* diffuseState, SkBitmapProcState
* normalState); |
90 ~LightingShaderContext() override; | 88 ~LightingShaderContext() override; |
91 | 89 |
92 void shadeSpan(int x, int y, SkPMColor[], int count) override; | 90 void shadeSpan(int x, int y, SkPMColor[], int count) override; |
93 | 91 |
94 uint32_t getFlags() const override { return fFlags; } | 92 uint32_t getFlags() const override { return fFlags; } |
95 | 93 |
96 private: | 94 private: |
97 SkBitmapProcState* fDiffuseState; | 95 SkBitmapProcState* fDiffuseState; |
98 SkBitmapProcState* fNormalState; | 96 SkBitmapProcState* fNormalState; |
99 uint32_t fFlags; | 97 uint32_t fFlags; |
100 | 98 |
101 typedef SkShader::Context INHERITED; | 99 typedef SkShader::Context INHERITED; |
102 }; | 100 }; |
103 | 101 |
104 SK_TO_STRING_OVERRIDE() | 102 SK_TO_STRING_OVERRIDE() |
105 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLightingShaderImpl) | 103 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLightingShaderImpl) |
106 | 104 |
107 protected: | 105 protected: |
108 void flatten(SkWriteBuffer&) const override; | 106 void flatten(SkWriteBuffer&) const override; |
| 107 size_t onContextSize(const ContextRec&) const override; |
109 Context* onCreateContext(const ContextRec&, void*) const override; | 108 Context* onCreateContext(const ContextRec&, void*) const override; |
110 bool computeNormTotalInverse(const ContextRec& rec, SkMatrix* normTotalInver
se) const; | 109 bool computeNormTotalInverse(const ContextRec& rec, SkMatrix* normTotalInver
se) const; |
111 | 110 |
112 private: | 111 private: |
113 SkBitmap fDiffuseMap; | 112 SkBitmap fDiffuseMap; |
114 SkBitmap fNormalMap; | 113 SkBitmap fNormalMap; |
115 | 114 |
116 SkAutoTUnref<const SkLightingShader::Lights> fLights; | 115 SkAutoTUnref<const SkLightingShader::Lights> fLights; |
117 | 116 |
118 SkMatrix fNormLocalMatrix; | 117 SkMatrix fNormLocalMatrix; |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 } | 408 } |
410 | 409 |
411 #endif | 410 #endif |
412 | 411 |
413 //////////////////////////////////////////////////////////////////////////// | 412 //////////////////////////////////////////////////////////////////////////// |
414 | 413 |
415 bool SkLightingShaderImpl::isOpaque() const { | 414 bool SkLightingShaderImpl::isOpaque() const { |
416 return fDiffuseMap.isOpaque(); | 415 return fDiffuseMap.isOpaque(); |
417 } | 416 } |
418 | 417 |
419 size_t SkLightingShaderImpl::contextSize(const ContextRec&) const { | |
420 return 2 * sizeof(SkBitmapProcState) + sizeof(LightingShaderContext); | |
421 } | |
422 | |
423 SkLightingShaderImpl::LightingShaderContext::LightingShaderContext(const SkLight
ingShaderImpl& shader, | 418 SkLightingShaderImpl::LightingShaderContext::LightingShaderContext(const SkLight
ingShaderImpl& shader, |
424 const Context
Rec& rec, | 419 const Context
Rec& rec, |
425 SkBitmapProcS
tate* diffuseState, | 420 SkBitmapProcS
tate* diffuseState, |
426 SkBitmapProcS
tate* normalState) | 421 SkBitmapProcS
tate* normalState) |
427 : INHERITED(shader, rec) | 422 : INHERITED(shader, rec) |
428 , fDiffuseState(diffuseState) | 423 , fDiffuseState(diffuseState) |
429 , fNormalState(normalState) | 424 , fNormalState(normalState) |
430 { | 425 { |
431 const SkPixmap& pixmap = fDiffuseState->fPixmap; | 426 const SkPixmap& pixmap = fDiffuseState->fPixmap; |
432 bool isOpaque = pixmap.isOpaque(); | 427 bool isOpaque = pixmap.isOpaque(); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 total.setConcat(*rec.fMatrix, fNormLocalMatrix); | 643 total.setConcat(*rec.fMatrix, fNormLocalMatrix); |
649 | 644 |
650 const SkMatrix* m = &total; | 645 const SkMatrix* m = &total; |
651 if (rec.fLocalMatrix) { | 646 if (rec.fLocalMatrix) { |
652 total.setConcat(*m, *rec.fLocalMatrix); | 647 total.setConcat(*m, *rec.fLocalMatrix); |
653 m = &total; | 648 m = &total; |
654 } | 649 } |
655 return m->invert(normTotalInverse); | 650 return m->invert(normTotalInverse); |
656 } | 651 } |
657 | 652 |
| 653 size_t SkLightingShaderImpl::onContextSize(const ContextRec&) const { |
| 654 return 2 * sizeof(SkBitmapProcState) + sizeof(LightingShaderContext); |
| 655 } |
| 656 |
658 SkShader::Context* SkLightingShaderImpl::onCreateContext(const ContextRec& rec, | 657 SkShader::Context* SkLightingShaderImpl::onCreateContext(const ContextRec& rec, |
659 void* storage) const { | 658 void* storage) const { |
660 | 659 |
661 SkMatrix diffTotalInv; | 660 SkMatrix diffTotalInv; |
662 // computeTotalInverse was called in SkShader::createContext so we know it w
ill succeed | 661 // computeTotalInverse was called in SkShader::createContext so we know it w
ill succeed |
663 SkAssertResult(this->computeTotalInverse(rec, &diffTotalInv)); | 662 SkAssertResult(this->computeTotalInverse(rec, &diffTotalInv)); |
664 | 663 |
665 SkMatrix normTotalInv; | 664 SkMatrix normTotalInv; |
666 if (!this->computeNormTotalInverse(rec, &normTotalInv)) { | 665 if (!this->computeNormTotalInverse(rec, &normTotalInv)) { |
667 return nullptr; | 666 return nullptr; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 normLocalM); | 717 normLocalM); |
719 } | 718 } |
720 | 719 |
721 /////////////////////////////////////////////////////////////////////////////// | 720 /////////////////////////////////////////////////////////////////////////////// |
722 | 721 |
723 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) | 722 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) |
724 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) | 723 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) |
725 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 724 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
726 | 725 |
727 /////////////////////////////////////////////////////////////////////////////// | 726 /////////////////////////////////////////////////////////////////////////////// |
OLD | NEW |