SkLocalMatrixShader.h revision 9cc1775e7230579ad15345bdcb59fa517c17f870
1/* 2 * Copyright 2014 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8#ifndef SkLocalMatrixShader_DEFINED 9#define SkLocalMatrixShader_DEFINED 10 11#include "SkShader.h" 12#include "SkReadBuffer.h" 13#include "SkWriteBuffer.h" 14 15class SkLocalMatrixShader : public SkShader { 16public: 17 SkLocalMatrixShader(SkShader* proxy, const SkMatrix& localMatrix) 18 : INHERITED(&localMatrix) 19 , fProxyShader(SkRef(proxy)) 20 {} 21 22 size_t contextSize() const override { 23 return fProxyShader->contextSize(); 24 } 25 26 virtual BitmapType asABitmap(SkBitmap* bitmap, SkMatrix* matrix, 27 TileMode* mode) const override { 28 return fProxyShader->asABitmap(bitmap, matrix, mode); 29 } 30 31 GradientType asAGradient(GradientInfo* info) const override { 32 return fProxyShader->asAGradient(info); 33 } 34 35#if SK_SUPPORT_GPU 36 37 virtual bool asFragmentProcessor(GrContext* context, const SkPaint& paint, 38 const SkMatrix& viewM, const SkMatrix* localMatrix, 39 GrColor* grColor, GrProcessorDataManager* procDataManager, 40 GrFragmentProcessor** fp) const override { 41 SkMatrix tmp = this->getLocalMatrix(); 42 if (localMatrix) { 43 tmp.preConcat(*localMatrix); 44 } 45 return fProxyShader->asFragmentProcessor(context, paint, viewM, &tmp, grColor, 46 procDataManager, fp); 47 } 48 49#else 50 51 virtual bool asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix&, 52 const SkMatrix*, GrColor*, GrProcessorDataManager*, 53 GrFragmentProcessor**) const override { 54 SkDEBUGFAIL("Should not call in GPU-less build"); 55 return false; 56 } 57 58#endif 59 60 SkShader* refAsALocalMatrixShader(SkMatrix* localMatrix) const override { 61 if (localMatrix) { 62 *localMatrix = this->getLocalMatrix(); 63 } 64 return SkRef(fProxyShader.get()); 65 } 66 67 SK_TO_STRING_OVERRIDE() 68 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLocalMatrixShader) 69 70protected: 71 void flatten(SkWriteBuffer&) const override; 72 Context* onCreateContext(const ContextRec&, void*) const override; 73 74private: 75 SkAutoTUnref<SkShader> fProxyShader; 76 77 typedef SkShader INHERITED; 78}; 79 80#endif 81