| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 #ifndef SkLocalMatrixShader_DEFINED | 8 #ifndef SkLocalMatrixShader_DEFINED |
| 9 #define SkLocalMatrixShader_DEFINED | 9 #define SkLocalMatrixShader_DEFINED |
| 10 | 10 |
| 11 #include "SkShader.h" | 11 #include "SkShader.h" |
| 12 #include "SkReadBuffer.h" | 12 #include "SkReadBuffer.h" |
| 13 #include "SkWriteBuffer.h" | 13 #include "SkWriteBuffer.h" |
| 14 | 14 |
| 15 class SkLocalMatrixShader : public SkShader { | 15 class SkLocalMatrixShader : public SkShader { |
| 16 public: | 16 public: |
| 17 SkLocalMatrixShader(SkShader* proxy, const SkMatrix& localMatrix) | 17 SkLocalMatrixShader(SkShader* proxy, const SkMatrix& localMatrix) |
| 18 : INHERITED(&localMatrix) | 18 : INHERITED(&localMatrix) |
| 19 , fProxyShader(SkRef(proxy)) | 19 , fProxyShader(SkRef(proxy)) |
| 20 {} | 20 {} |
| 21 | 21 |
| 22 virtual size_t contextSize() const SK_OVERRIDE { | 22 size_t contextSize() const SK_OVERRIDE { |
| 23 return fProxyShader->contextSize(); | 23 return fProxyShader->contextSize(); |
| 24 } | 24 } |
| 25 | 25 |
| 26 virtual BitmapType asABitmap(SkBitmap* bitmap, SkMatrix* matrix, | 26 virtual BitmapType asABitmap(SkBitmap* bitmap, SkMatrix* matrix, |
| 27 TileMode* mode) const SK_OVERRIDE { | 27 TileMode* mode) const SK_OVERRIDE { |
| 28 return fProxyShader->asABitmap(bitmap, matrix, mode); | 28 return fProxyShader->asABitmap(bitmap, matrix, mode); |
| 29 } | 29 } |
| 30 | 30 |
| 31 virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE { | 31 GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE { |
| 32 return fProxyShader->asAGradient(info); | 32 return fProxyShader->asAGradient(info); |
| 33 } | 33 } |
| 34 | 34 |
| 35 #if SK_SUPPORT_GPU | 35 #if SK_SUPPORT_GPU |
| 36 | 36 |
| 37 virtual bool asFragmentProcessor(GrContext* context, const SkPaint& paint, | 37 virtual bool asFragmentProcessor(GrContext* context, const SkPaint& paint, |
| 38 const SkMatrix& viewM, const SkMatrix* loca
lMatrix, | 38 const SkMatrix& viewM, const SkMatrix* loca
lMatrix, |
| 39 GrColor* grColor, GrFragmentProcessor** fp)
const SK_OVERRIDE { | 39 GrColor* grColor, GrFragmentProcessor** fp)
const SK_OVERRIDE { |
| 40 SkMatrix tmp = this->getLocalMatrix(); | 40 SkMatrix tmp = this->getLocalMatrix(); |
| 41 if (localMatrix) { | 41 if (localMatrix) { |
| 42 tmp.preConcat(*localMatrix); | 42 tmp.preConcat(*localMatrix); |
| 43 } | 43 } |
| 44 return fProxyShader->asFragmentProcessor(context, paint, viewM, &tmp, gr
Color, fp); | 44 return fProxyShader->asFragmentProcessor(context, paint, viewM, &tmp, gr
Color, fp); |
| 45 } | 45 } |
| 46 | 46 |
| 47 #else | 47 #else |
| 48 | 48 |
| 49 virtual bool asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix&
, | 49 virtual bool asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix&
, |
| 50 const SkMatrix*, GrColor*, | 50 const SkMatrix*, GrColor*, |
| 51 GrFragmentProcessor**) const SK_OVERRIDE { | 51 GrFragmentProcessor**) const SK_OVERRIDE { |
| 52 SkDEBUGFAIL("Should not call in GPU-less build"); | 52 SkDEBUGFAIL("Should not call in GPU-less build"); |
| 53 return false; | 53 return false; |
| 54 } | 54 } |
| 55 | 55 |
| 56 #endif | 56 #endif |
| 57 | 57 |
| 58 virtual SkShader* refAsALocalMatrixShader(SkMatrix* localMatrix) const SK_OV
ERRIDE { | 58 SkShader* refAsALocalMatrixShader(SkMatrix* localMatrix) const SK_OVERRIDE { |
| 59 if (localMatrix) { | 59 if (localMatrix) { |
| 60 *localMatrix = this->getLocalMatrix(); | 60 *localMatrix = this->getLocalMatrix(); |
| 61 } | 61 } |
| 62 return SkRef(fProxyShader.get()); | 62 return SkRef(fProxyShader.get()); |
| 63 } | 63 } |
| 64 | 64 |
| 65 SK_TO_STRING_OVERRIDE() | 65 SK_TO_STRING_OVERRIDE() |
| 66 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLocalMatrixShader) | 66 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLocalMatrixShader) |
| 67 | 67 |
| 68 protected: | 68 protected: |
| 69 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; | 69 void flatten(SkWriteBuffer&) const SK_OVERRIDE; |
| 70 virtual Context* onCreateContext(const ContextRec&, void*) const SK_OVERRIDE
; | 70 Context* onCreateContext(const ContextRec&, void*) const SK_OVERRIDE; |
| 71 | 71 |
| 72 private: | 72 private: |
| 73 SkAutoTUnref<SkShader> fProxyShader; | 73 SkAutoTUnref<SkShader> fProxyShader; |
| 74 | 74 |
| 75 typedef SkShader INHERITED; | 75 typedef SkShader INHERITED; |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 #endif | 78 #endif |
| OLD | NEW |