SkLocalMatrixShader.h revision 97b9ab72cd5ee0cba4692082737266376425f27c
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 : fProxyShader(SkRef(proxy)) 19 , fProxyLocalMatrix(localMatrix) 20 {} 21 22 virtual size_t contextSize() const SK_OVERRIDE { 23 return fProxyShader->contextSize(); 24 } 25 26 virtual BitmapType asABitmap(SkBitmap* bitmap, SkMatrix* matrix, 27 TileMode* mode) const SK_OVERRIDE { 28 return fProxyShader->asABitmap(bitmap, matrix, mode); 29 } 30 31 virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE { 32 return fProxyShader->asAGradient(info); 33 } 34 35#if SK_SUPPORT_GPU 36 37 virtual bool asNewEffect(GrContext* context, const SkPaint& paint, const SkMatrix* localMatrix, 38 GrColor* grColor, GrEffect** grEffect) const SK_OVERRIDE { 39 SkMatrix tmp = fProxyLocalMatrix; 40 if (localMatrix) { 41 tmp.preConcat(*localMatrix); 42 } 43 return fProxyShader->asNewEffect(context, paint, &tmp, grColor, grEffect); 44 } 45 46#else 47 48 virtual bool asNewEffect(GrContext* context, const SkPaint& paint, const SkMatrix* localMatrix, 49 GrColor* grColor, GrEffect** grEffect) const SK_OVERRIDE { 50 SkDEBUGFAIL("Should not call in GPU-less build"); 51 return false; 52 } 53 54#endif 55 56 virtual SkShader* refAsALocalMatrixShader(SkMatrix* localMatrix) const SK_OVERRIDE { 57 if (localMatrix) { 58 *localMatrix = fProxyLocalMatrix; 59 } 60 return SkRef(fProxyShader.get()); 61 } 62 63 SK_TO_STRING_OVERRIDE() 64 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLocalMatrixShader) 65 66protected: 67 SkLocalMatrixShader(SkReadBuffer&); 68 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; 69 virtual Context* onCreateContext(const ContextRec&, void*) const SK_OVERRIDE; 70 71private: 72 SkAutoTUnref<SkShader> fProxyShader; 73 SkMatrix fProxyLocalMatrix; 74 75 typedef SkShader INHERITED; 76}; 77 78#endif 79