SkColorShader.h revision 9de5b514d38c5b36066bcdc14fba2f7e5196d372
1 2/* 3 * Copyright 2007 The Android Open Source Project 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9 10#ifndef SkColorShader_DEFINED 11#define SkColorShader_DEFINED 12 13#include "SkShader.h" 14 15/** \class SkColorShader 16 A Shader that represents a single color. In general, this effect can be 17 accomplished by just using the color field on the paint, but if an 18 actual shader object is needed, this provides that feature. 19*/ 20class SK_API SkColorShader : public SkShader { 21public: 22 /** Create a ColorShader that ignores the color in the paint, and uses the 23 specified color. Note: like all shaders, at draw time the paint's alpha 24 will be respected, and is applied to the specified color. 25 */ 26 explicit SkColorShader(SkColor c); 27 28 virtual bool isOpaque() const SK_OVERRIDE; 29 30 virtual size_t contextSize() const SK_OVERRIDE { 31 return sizeof(ColorShaderContext); 32 } 33 34 class ColorShaderContext : public SkShader::Context { 35 public: 36 ColorShaderContext(const SkColorShader& shader, const ContextRec&); 37 38 virtual uint32_t getFlags() const SK_OVERRIDE; 39 virtual uint8_t getSpan16Alpha() const SK_OVERRIDE; 40 virtual void shadeSpan(int x, int y, SkPMColor span[], int count) SK_OVERRIDE; 41 virtual void shadeSpan16(int x, int y, uint16_t span[], int count) SK_OVERRIDE; 42 virtual void shadeSpanAlpha(int x, int y, uint8_t alpha[], int count) SK_OVERRIDE; 43 44 private: 45 SkPMColor fPMColor; 46 uint32_t fFlags; 47 uint16_t fColor16; 48 49 typedef SkShader::Context INHERITED; 50 }; 51 52 // we return false for this, use asAGradient 53 virtual BitmapType asABitmap(SkBitmap* outTexture, 54 SkMatrix* outMatrix, 55 TileMode xy[2]) const SK_OVERRIDE; 56 57 virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE; 58 59 virtual bool asNewEffect(GrContext* context, const SkPaint& paint, 60 const SkMatrix* localMatrix, GrColor* grColor, 61 GrEffectRef** grEffect) const SK_OVERRIDE; 62 63 SK_TO_STRING_OVERRIDE() 64 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorShader) 65 66protected: 67 SkColorShader(SkReadBuffer&); 68 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; 69 virtual Context* onCreateContext(const ContextRec&, void* storage) const SK_OVERRIDE; 70 71private: 72 SkColor fColor; // ignored if fInheritColor is true 73 74 typedef SkShader INHERITED; 75}; 76 77#endif 78