SkColorShader.h revision cc9dbfb1d21098c267d8b398b51a1db95e5099b5
13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/* 33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2007 The Android Open Source Project 43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Use of this source code is governed by a BSD-style license that can be 63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * found in the LICENSE file. 73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry */ 83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#ifndef SkColorShader_DEFINED 113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define SkColorShader_DEFINED 123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "SkShader.h" 143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/** \class SkColorShader 163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry A Shader that represents a single color. In general, this effect can be 173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry accomplished by just using the color field on the paint, but if an 183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry actual shader object is needed, this provides that feature. 193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry*/ 203c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass SK_API SkColorShader : public SkShader { 213c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry /** Create a ColorShader that ignores the color in the paint, and uses the 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry specified color. Note: like all shaders, at draw time the paint's alpha 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry will be respected, and is applied to the specified color. 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry */ 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry explicit SkColorShader(SkColor c); 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual bool isOpaque() const SK_OVERRIDE; 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual SkShader::Context* createContext(const SkBitmap& device, 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const SkPaint& paint, 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const SkMatrix& matrix, 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void* storage) const SK_OVERRIDE; 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual size_t contextSize() const SK_OVERRIDE { 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return sizeof(ColorShaderContext); 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry class ColorShaderContext : public SkShader::Context { 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry public: 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ColorShaderContext(const SkColorShader& shader, const SkBitmap& device, 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const SkPaint& paint, const SkMatrix& matrix); 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual uint32_t getFlags() const SK_OVERRIDE; 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual uint8_t getSpan16Alpha() const SK_OVERRIDE; 46 virtual void shadeSpan(int x, int y, SkPMColor span[], int count) SK_OVERRIDE; 47 virtual void shadeSpan16(int x, int y, uint16_t span[], int count) SK_OVERRIDE; 48 virtual void shadeSpanAlpha(int x, int y, uint8_t alpha[], int count) SK_OVERRIDE; 49 50 private: 51 SkPMColor fPMColor; 52 uint32_t fFlags; 53 uint16_t fColor16; 54 55 typedef SkShader::Context INHERITED; 56 }; 57 58 // we return false for this, use asAGradient 59 virtual BitmapType asABitmap(SkBitmap* outTexture, 60 SkMatrix* outMatrix, 61 TileMode xy[2]) const SK_OVERRIDE; 62 63 virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE; 64 65 SK_TO_STRING_OVERRIDE() 66 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorShader) 67 68protected: 69 SkColorShader(SkReadBuffer&); 70 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; 71 72private: 73 SkColor fColor; // ignored if fInheritColor is true 74 75 typedef SkShader INHERITED; 76}; 77 78#endif 79