18a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/* 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project 38a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 68a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkShader_DEFINED 108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkShader_DEFINED 118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkBitmap.h" 138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkFlattenable.h" 148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkMask.h" 158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkMatrix.h" 168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPaint.h" 179de5b514d38c5b36066bcdc14fba2f7e5196d372dandov#include "../gpu/GrColor.h" 188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkPath; 20c5d9bb0f677069f62ec76373b9730e70e7352455commit-bot@chromium.orgclass SkPicture; 21795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.orgclass SkXfermode; 2203c1c359b336ad20d23ab07004cdafafd14c90a5rileya@google.comclass GrContext; 230ac6af49975c54c2debf41e9200af416ecd2d973bsalomon@google.comclass GrEffectRef; 248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkShader 26ad91799832b9ba2a3de30c0f57968148b4be17afreed@google.com * 27880dc472ab2c987083db9eb83efb2930787f0b26reed@google.com * Shaders specify the source color(s) for what is being drawn. If a paint 28880dc472ab2c987083db9eb83efb2930787f0b26reed@google.com * has no shader, then the paint's color is used. If the paint has a 29880dc472ab2c987083db9eb83efb2930787f0b26reed@google.com * shader, then the shader's color(s) are use instead, but they are 30880dc472ab2c987083db9eb83efb2930787f0b26reed@google.com * modulated by the paint's alpha. This makes it easy to create a shader 31880dc472ab2c987083db9eb83efb2930787f0b26reed@google.com * once (e.g. bitmap tiling or gradient) and then change its transparency 32880dc472ab2c987083db9eb83efb2930787f0b26reed@google.com * w/o having to modify the original shader... only the paint's alpha needs 33880dc472ab2c987083db9eb83efb2930787f0b26reed@google.com * to be modified. 34ad91799832b9ba2a3de30c0f57968148b4be17afreed@google.com */ 357ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.orgclass SK_API SkShader : public SkFlattenable { 368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 370456e0b7b85060e9b9597ce414c4c2b19aff4f58robertphillips@google.com SK_DECLARE_INST_COUNT(SkShader) 380456e0b7b85060e9b9597ce414c4c2b19aff4f58robertphillips@google.com 399c9005a347e9996f357bd79591bd34f74f8bbc66commit-bot@chromium.org SkShader(const SkMatrix* localMatrix = NULL); 408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual ~SkShader(); 418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 42ad91799832b9ba2a3de30c0f57968148b4be17afreed@google.com /** 435970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org * Returns the local matrix. 44ad91799832b9ba2a3de30c0f57968148b4be17afreed@google.com */ 455970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org const SkMatrix& getLocalMatrix() const { return fLocalMatrix; } 46f94b3a4cebd4adab09c40ebe23c02a615e10c394bsalomon@google.com 47f94b3a4cebd4adab09c40ebe23c02a615e10c394bsalomon@google.com /** 485970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org * Returns true if the local matrix is not an identity matrix. 49f94b3a4cebd4adab09c40ebe23c02a615e10c394bsalomon@google.com */ 505970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org bool hasLocalMatrix() const { return !fLocalMatrix.isIdentity(); } 51ad91799832b9ba2a3de30c0f57968148b4be17afreed@google.com 52de5553ae8b8805884821bcfcf8cee53d8ece8a1bcommit-bot@chromium.org#ifdef SK_SUPPORT_LEGACY_SHADER_LOCALMATRIX 53ad91799832b9ba2a3de30c0f57968148b4be17afreed@google.com /** 54ad91799832b9ba2a3de30c0f57968148b4be17afreed@google.com * Set the shader's local matrix. 55ad91799832b9ba2a3de30c0f57968148b4be17afreed@google.com * @param localM The shader's new local matrix. 56ad91799832b9ba2a3de30c0f57968148b4be17afreed@google.com */ 57f94b3a4cebd4adab09c40ebe23c02a615e10c394bsalomon@google.com void setLocalMatrix(const SkMatrix& localM) { fLocalMatrix = localM; } 58ad91799832b9ba2a3de30c0f57968148b4be17afreed@google.com 59ad91799832b9ba2a3de30c0f57968148b4be17afreed@google.com /** 60ad91799832b9ba2a3de30c0f57968148b4be17afreed@google.com * Reset the shader's local matrix to identity. 61ad91799832b9ba2a3de30c0f57968148b4be17afreed@google.com */ 62f94b3a4cebd4adab09c40ebe23c02a615e10c394bsalomon@google.com void resetLocalMatrix() { fLocalMatrix.reset(); } 635970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org#endif 648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum TileMode { 660beaba5b34888001c3811c26be6954696a2cdbdfreed@google.com /** replicate the edge color if the shader draws outside of its 670beaba5b34888001c3811c26be6954696a2cdbdfreed@google.com * original bounds 680beaba5b34888001c3811c26be6954696a2cdbdfreed@google.com */ 690beaba5b34888001c3811c26be6954696a2cdbdfreed@google.com kClamp_TileMode, 700beaba5b34888001c3811c26be6954696a2cdbdfreed@google.com 710beaba5b34888001c3811c26be6954696a2cdbdfreed@google.com /** repeat the shader's image horizontally and vertically */ 720beaba5b34888001c3811c26be6954696a2cdbdfreed@google.com kRepeat_TileMode, 730beaba5b34888001c3811c26be6954696a2cdbdfreed@google.com 740beaba5b34888001c3811c26be6954696a2cdbdfreed@google.com /** repeat the shader's image horizontally and vertically, alternating 750beaba5b34888001c3811c26be6954696a2cdbdfreed@google.com * mirror images so that adjacent images always seam 760beaba5b34888001c3811c26be6954696a2cdbdfreed@google.com */ 770beaba5b34888001c3811c26be6954696a2cdbdfreed@google.com kMirror_TileMode, 780beaba5b34888001c3811c26be6954696a2cdbdfreed@google.com 790beaba5b34888001c3811c26be6954696a2cdbdfreed@google.com#if 0 800beaba5b34888001c3811c26be6954696a2cdbdfreed@google.com /** only draw within the original domain, return 0 everywhere else */ 810beaba5b34888001c3811c26be6954696a2cdbdfreed@google.com kDecal_TileMode, 820beaba5b34888001c3811c26be6954696a2cdbdfreed@google.com#endif 838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kTileModeCount 858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // override these in your subclass 888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum Flags { 908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com //!< set if all of the colors will be opaque 913c9b2a4a0e4f57db23640e85959ee78b86634628reed@android.com kOpaqueAlpha_Flag = 0x01, 925119bdb952025a30f115b9c6a187173956e55097reed@android.com 938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com //! set if this shader's shadeSpan16() method can be called 943c9b2a4a0e4f57db23640e85959ee78b86634628reed@android.com kHasSpan16_Flag = 0x02, 955119bdb952025a30f115b9c6a187173956e55097reed@android.com 968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set this bit if the shader's native data type is instrinsically 16 978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bit, meaning that calling the 32bit shadeSpan() entry point will 988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mean the the impl has to up-sample 16bit data into 32bit. Used as a 998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com a means of clearing a dither request if the it will have no effect 1008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1015119bdb952025a30f115b9c6a187173956e55097reed@android.com kIntrinsicly16_Flag = 0x04, 1025119bdb952025a30f115b9c6a187173956e55097reed@android.com 10387fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org /** set if the spans only vary in X (const in Y). 1045119bdb952025a30f115b9c6a187173956e55097reed@android.com e.g. an Nx1 bitmap that is being tiled in Y, or a linear-gradient 1053c9b2a4a0e4f57db23640e85959ee78b86634628reed@android.com that varies from left-to-right. This flag specifies this for 1063c9b2a4a0e4f57db23640e85959ee78b86634628reed@android.com shadeSpan(). 1075119bdb952025a30f115b9c6a187173956e55097reed@android.com */ 1083c9b2a4a0e4f57db23640e85959ee78b86634628reed@android.com kConstInY32_Flag = 0x08, 1097c2f27d788fff9dbf66a6d52753e47f786a313c0reed@google.com 1103c9b2a4a0e4f57db23640e85959ee78b86634628reed@android.com /** same as kConstInY32_Flag, but is set if this is true for shadeSpan16 1113c9b2a4a0e4f57db23640e85959ee78b86634628reed@android.com which may not always be the case, since shadeSpan16 may be 1123c9b2a4a0e4f57db23640e85959ee78b86634628reed@android.com predithered, which would mean it was not const in Y, even though 1133c9b2a4a0e4f57db23640e85959ee78b86634628reed@android.com the 32bit shadeSpan() would be const. 1143c9b2a4a0e4f57db23640e85959ee78b86634628reed@android.com */ 1153c9b2a4a0e4f57db23640e85959ee78b86634628reed@android.com kConstInY16_Flag = 0x10 1168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 1178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 118ad91799832b9ba2a3de30c0f57968148b4be17afreed@google.com /** 119b6e161937bc890f0aa12ac5e27415d4d260ea6e0junov@chromium.org * Returns true if the shader is guaranteed to produce only opaque 120b6e161937bc890f0aa12ac5e27415d4d260ea6e0junov@chromium.org * colors, subject to the SkPaint using the shader to apply an opaque 121b6e161937bc890f0aa12ac5e27415d4d260ea6e0junov@chromium.org * alpha value. Subclasses should override this to allow some 12287fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org * optimizations. 123b6e161937bc890f0aa12ac5e27415d4d260ea6e0junov@chromium.org */ 124b6e161937bc890f0aa12ac5e27415d4d260ea6e0junov@chromium.org virtual bool isOpaque() const { return false; } 125b6e161937bc890f0aa12ac5e27415d4d260ea6e0junov@chromium.org 126e901b6de3ef8dea842008a08fc81e92fb1478d61commit-bot@chromium.org /** 127e901b6de3ef8dea842008a08fc81e92fb1478d61commit-bot@chromium.org * ContextRec acts as a parameter bundle for creating Contexts. 128e901b6de3ef8dea842008a08fc81e92fb1478d61commit-bot@chromium.org */ 129e901b6de3ef8dea842008a08fc81e92fb1478d61commit-bot@chromium.org struct ContextRec { 13080116dcf1e1baf9817ae42d0aca51f7eabaa2880commit-bot@chromium.org ContextRec() : fDevice(NULL), fPaint(NULL), fMatrix(NULL), fLocalMatrix(NULL) {} 131e901b6de3ef8dea842008a08fc81e92fb1478d61commit-bot@chromium.org ContextRec(const SkBitmap& device, const SkPaint& paint, const SkMatrix& matrix) 132e901b6de3ef8dea842008a08fc81e92fb1478d61commit-bot@chromium.org : fDevice(&device) 133e901b6de3ef8dea842008a08fc81e92fb1478d61commit-bot@chromium.org , fPaint(&paint) 13480116dcf1e1baf9817ae42d0aca51f7eabaa2880commit-bot@chromium.org , fMatrix(&matrix) 13580116dcf1e1baf9817ae42d0aca51f7eabaa2880commit-bot@chromium.org , fLocalMatrix(NULL) {} 136e901b6de3ef8dea842008a08fc81e92fb1478d61commit-bot@chromium.org 13780116dcf1e1baf9817ae42d0aca51f7eabaa2880commit-bot@chromium.org const SkBitmap* fDevice; // the bitmap we are drawing into 13880116dcf1e1baf9817ae42d0aca51f7eabaa2880commit-bot@chromium.org const SkPaint* fPaint; // the current paint associated with the draw 13980116dcf1e1baf9817ae42d0aca51f7eabaa2880commit-bot@chromium.org const SkMatrix* fMatrix; // the current matrix in the canvas 14080116dcf1e1baf9817ae42d0aca51f7eabaa2880commit-bot@chromium.org const SkMatrix* fLocalMatrix; // optional local matrix 141e901b6de3ef8dea842008a08fc81e92fb1478d61commit-bot@chromium.org }; 142e901b6de3ef8dea842008a08fc81e92fb1478d61commit-bot@chromium.org 14387fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org class Context : public ::SkNoncopyable { 14487fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org public: 145e901b6de3ef8dea842008a08fc81e92fb1478d61commit-bot@chromium.org Context(const SkShader& shader, const ContextRec&); 146001f4ed2fb62ecdc98ce2884d925de11b7516d23commit-bot@chromium.org 14787fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org virtual ~Context(); 148bc2f1dc85e458af7bdb87873e60207f9f7299e4acommit-bot@chromium.org 14987fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org /** 15087fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org * Called sometimes before drawing with this shader. Return the type of 15187fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org * alpha your shader will return. The default implementation returns 0. 15287fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org * Your subclass should override if it can (even sometimes) report a 15387fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org * non-zero value, since that will enable various blitters to perform 15487fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org * faster. 15587fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org */ 15687fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org virtual uint32_t getFlags() const { return 0; } 157bc2f1dc85e458af7bdb87873e60207f9f7299e4acommit-bot@chromium.org 15887fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org /** 15987fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org * Return the alpha associated with the data returned by shadeSpan16(). If 16087fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org * kHasSpan16_Flag is not set, this value is meaningless. 16187fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org */ 16287fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org virtual uint8_t getSpan16Alpha() const { return fPaintAlpha; } 163bc2f1dc85e458af7bdb87873e60207f9f7299e4acommit-bot@chromium.org 16487fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org /** 16587fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org * Called for each span of the object being drawn. Your subclass should 16687fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org * set the appropriate colors (with premultiplied alpha) that correspond 16787fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org * to the specified device coordinates. 16887fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org */ 16987fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org virtual void shadeSpan(int x, int y, SkPMColor[], int count) = 0; 17087fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org 17187fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org typedef void (*ShadeProc)(void* ctx, int x, int y, SkPMColor[], int count); 17287fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org virtual ShadeProc asAShadeProc(void** ctx); 17387fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org 17487fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org /** 17587fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org * Called only for 16bit devices when getFlags() returns 17687fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org * kOpaqueAlphaFlag | kHasSpan16_Flag 17787fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org */ 17887fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org virtual void shadeSpan16(int x, int y, uint16_t[], int count); 17987fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org 18087fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org /** 18187fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org * Similar to shadeSpan, but only returns the alpha-channel for a span. 18287fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org * The default implementation calls shadeSpan() and then extracts the alpha 18387fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org * values from the returned colors. 18487fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org */ 18587fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org virtual void shadeSpanAlpha(int x, int y, uint8_t alpha[], int count); 186ad91799832b9ba2a3de30c0f57968148b4be17afreed@google.com 18787fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org /** 18887fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org * Helper function that returns true if this shader's shadeSpan16() method 18987fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org * can be called. 19087fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org */ 19187fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org bool canCallShadeSpan16() { 19287fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org return SkShader::CanCallShadeSpan16(this->getFlags()); 19387fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org } 19487fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org 19587fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org protected: 19687fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org // Reference to shader, so we don't have to dupe information. 19787fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org const SkShader& fShader; 19887fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org 19987fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org enum MatrixClass { 20087fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org kLinear_MatrixClass, // no perspective 20187fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org kFixedStepInX_MatrixClass, // fast perspective, need to call fixedStepInX() each 20287fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org // scanline 20387fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org kPerspective_MatrixClass // slow perspective, need to mappoints each pixel 20487fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org }; 20587fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org static MatrixClass ComputeMatrixClass(const SkMatrix&); 20687fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org 20780116dcf1e1baf9817ae42d0aca51f7eabaa2880commit-bot@chromium.org uint8_t getPaintAlpha() const { return fPaintAlpha; } 20880116dcf1e1baf9817ae42d0aca51f7eabaa2880commit-bot@chromium.org const SkMatrix& getTotalInverse() const { return fTotalInverse; } 20980116dcf1e1baf9817ae42d0aca51f7eabaa2880commit-bot@chromium.org MatrixClass getInverseClass() const { return (MatrixClass)fTotalInverseClass; } 21080116dcf1e1baf9817ae42d0aca51f7eabaa2880commit-bot@chromium.org const SkMatrix& getCTM() const { return fCTM; } 21187fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org private: 21280116dcf1e1baf9817ae42d0aca51f7eabaa2880commit-bot@chromium.org SkMatrix fCTM; 21380116dcf1e1baf9817ae42d0aca51f7eabaa2880commit-bot@chromium.org SkMatrix fTotalInverse; 21480116dcf1e1baf9817ae42d0aca51f7eabaa2880commit-bot@chromium.org uint8_t fPaintAlpha; 21580116dcf1e1baf9817ae42d0aca51f7eabaa2880commit-bot@chromium.org uint8_t fTotalInverseClass; 21687fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org 21787fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org typedef SkNoncopyable INHERITED; 21887fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org }; 2193bafe74a29c37761082980ed4ee9b831256bd27ereed@google.com 220ad91799832b9ba2a3de30c0f57968148b4be17afreed@google.com /** 22187fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org * Create the actual object that does the shading. 22287fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org * Size of storage must be >= contextSize. 223ad91799832b9ba2a3de30c0f57968148b4be17afreed@google.com */ 224ce56d965069c1649afe14319cb239e6ad670682acommit-bot@chromium.org Context* createContext(const ContextRec&, void* storage) const; 2258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 226ad91799832b9ba2a3de30c0f57968148b4be17afreed@google.com /** 22787fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org * Return the size of a Context returned by createContext. 228f3e505984d08fb96e753be2b561f479dc3a4c544commit-bot@chromium.org * 229f3e505984d08fb96e753be2b561f479dc3a4c544commit-bot@chromium.org * Override this if your subclass overrides createContext, to return the correct size of 230f3e505984d08fb96e753be2b561f479dc3a4c544commit-bot@chromium.org * your subclass' context. 231ad91799832b9ba2a3de30c0f57968148b4be17afreed@google.com */ 232f3e505984d08fb96e753be2b561f479dc3a4c544commit-bot@chromium.org virtual size_t contextSize() const; 2338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 234ad91799832b9ba2a3de30c0f57968148b4be17afreed@google.com /** 235ad91799832b9ba2a3de30c0f57968148b4be17afreed@google.com * Helper to check the flags to know if it is legal to call shadeSpan16() 236ad91799832b9ba2a3de30c0f57968148b4be17afreed@google.com */ 2378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static bool CanCallShadeSpan16(uint32_t flags) { 2388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return (flags & kHasSpan16_Flag) != 0; 2398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 241ad91799832b9ba2a3de30c0f57968148b4be17afreed@google.com /** 242f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com Gives method bitmap should be read to implement a shader. 243f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com Also determines number and interpretation of "extra" parameters returned 244f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com by asABitmap 245f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com */ 246f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com enum BitmapType { 247f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com kNone_BitmapType, //<! Shader is not represented as a bitmap 2487c2f27d788fff9dbf66a6d52753e47f786a313c0reed@google.com kDefault_BitmapType,//<! Access bitmap using local coords transformed 249f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // by matrix. No extras 2507c2f27d788fff9dbf66a6d52753e47f786a313c0reed@google.com kRadial_BitmapType, //<! Access bitmap by transforming local coordinates 2517c2f27d788fff9dbf66a6d52753e47f786a313c0reed@google.com // by the matrix and taking the distance of result 2527c2f27d788fff9dbf66a6d52753e47f786a313c0reed@google.com // from (0,0) as bitmap column. Bitmap is 1 pixel 253f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // tall. No extras 2547c2f27d788fff9dbf66a6d52753e47f786a313c0reed@google.com kSweep_BitmapType, //<! Access bitmap by transforming local coordinates 255f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // by the matrix and taking the angle of result 256f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // to (0,0) as bitmap x coord, where angle = 0 is 2577c2f27d788fff9dbf66a6d52753e47f786a313c0reed@google.com // bitmap left edge of bitmap = 2pi is the 258f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // right edge. Bitmap is 1 pixel tall. No extras 259d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org kTwoPointRadial_BitmapType, 2607c2f27d788fff9dbf66a6d52753e47f786a313c0reed@google.com //<! Matrix transforms to space where (0,0) is 261f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // the center of the starting circle. The second 2627c2f27d788fff9dbf66a6d52753e47f786a313c0reed@google.com // circle will be centered (x, 0) where x may be 2637c2f27d788fff9dbf66a6d52753e47f786a313c0reed@google.com // 0. The post-matrix space is normalized such 264f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // that 1 is the second radius - first radius. 265f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // Three extra parameters are returned: 2667c2f27d788fff9dbf66a6d52753e47f786a313c0reed@google.com // 0: x-offset of second circle center 267f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // to first. 2687c2f27d788fff9dbf66a6d52753e47f786a313c0reed@google.com // 1: radius of first circle in post-matrix 269f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // space 270f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // 2: the second radius minus the first radius 2717c2f27d788fff9dbf66a6d52753e47f786a313c0reed@google.com // in pre-transformed space. 2723e33258cd15faae4a2906ddcc586e4008ee20e68rileya@google.com kTwoPointConical_BitmapType, 2733e33258cd15faae4a2906ddcc586e4008ee20e68rileya@google.com //<! Matrix transforms to space where (0,0) is 2743e33258cd15faae4a2906ddcc586e4008ee20e68rileya@google.com // the center of the starting circle. The second 2753e33258cd15faae4a2906ddcc586e4008ee20e68rileya@google.com // circle will be centered (x, 0) where x may be 2763e33258cd15faae4a2906ddcc586e4008ee20e68rileya@google.com // 0. 2773e33258cd15faae4a2906ddcc586e4008ee20e68rileya@google.com // Three extra parameters are returned: 2783e33258cd15faae4a2906ddcc586e4008ee20e68rileya@google.com // 0: x-offset of second circle center 2793e33258cd15faae4a2906ddcc586e4008ee20e68rileya@google.com // to first. 2803e33258cd15faae4a2906ddcc586e4008ee20e68rileya@google.com // 1: radius of first circle 2813e33258cd15faae4a2906ddcc586e4008ee20e68rileya@google.com // 2: the second radius minus the first radius 28222e57f991628451c02f970beea379ad632bb6a10rileya@google.com kLinear_BitmapType, //<! Access bitmap using local coords transformed 28322e57f991628451c02f970beea379ad632bb6a10rileya@google.com // by matrix. No extras 284d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org 28522e57f991628451c02f970beea379ad632bb6a10rileya@google.com kLast_BitmapType = kLinear_BitmapType 286f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com }; 2878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Optional methods for shaders that can pretend to be a bitmap/texture 2887c2f27d788fff9dbf66a6d52753e47f786a313c0reed@google.com to play along with opengl. Default just returns kNone_BitmapType and 289f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com ignores the out parameters. 290f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com 291f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com @param outTexture if non-NULL will be the bitmap representing the shader 292f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com after return. 293f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com @param outMatrix if non-NULL will be the matrix to apply to vertices 294f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com to access the bitmap after return. 295f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com @param xy if non-NULL will be the tile modes that should be 296f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com used to access the bitmap after return. 297f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com @param twoPointRadialParams Two extra return values needed for two point 298f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com radial bitmaps. The first is the x-offset of 299f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com the second point and the second is the radius 300f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com about the first point. 3018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 302f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com virtual BitmapType asABitmap(SkBitmap* outTexture, SkMatrix* outMatrix, 30391f319c5dc4493384f0a52aaeef3dcc311ef6ed0rileya@google.com TileMode xy[2]) const; 3048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 305d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org /** 306d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * If the shader subclass can be represented as a gradient, asAGradient 307d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * returns the matching GradientType enum (or kNone_GradientType if it 308d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * cannot). Also, if info is not null, asAGradient populates info with 309d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * the relevant (see below) parameters for the gradient. fColorCount 310d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * is both an input and output parameter. On input, it indicates how 311d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * many entries in fColors and fColorOffsets can be used, if they are 312d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * non-NULL. After asAGradient has run, fColorCount indicates how 313d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * many color-offset pairs there are in the gradient. If there is 314d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * insufficient space to store all of the color-offset pairs, fColors 315d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * and fColorOffsets will not be altered. fColorOffsets specifies 316d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * where on the range of 0 to 1 to transition to the given color. 317d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * The meaning of fPoint and fRadius is dependant on the type of gradient. 318d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * 319d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * None: 320d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * info is ignored. 321d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * Color: 322d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * fColorOffsets[0] is meaningless. 323d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * Linear: 324d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * fPoint[0] and fPoint[1] are the end-points of the gradient 325d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * Radial: 326d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * fPoint[0] and fRadius[0] are the center and radius 327d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * Radial2: 328d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * fPoint[0] and fRadius[0] are the center and radius of the 1st circle 329d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * fPoint[1] and fRadius[1] are the center and radius of the 2nd circle 330d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * Sweep: 331d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * fPoint[0] is the center of the sweep. 332d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org */ 333d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org 334d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org enum GradientType { 335d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org kNone_GradientType, 336d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org kColor_GradientType, 337d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org kLinear_GradientType, 338d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org kRadial_GradientType, 339d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org kRadial2_GradientType, 340d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org kSweep_GradientType, 34183226976b532141b26ff3a40f381a5d08ce3259dreed@google.com kConical_GradientType, 34283226976b532141b26ff3a40f381a5d08ce3259dreed@google.com kLast_GradientType = kConical_GradientType 343d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org }; 344d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org 345d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org struct GradientInfo { 346d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org int fColorCount; //!< In-out parameter, specifies passed size 347d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org // of fColors/fColorOffsets on input, and 348d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org // actual number of colors/offsets on 349d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org // output. 350d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org SkColor* fColors; //!< The colors in the gradient. 351d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org SkScalar* fColorOffsets; //!< The unit offset for color transitions. 352d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org SkPoint fPoint[2]; //!< Type specific, see above. 353d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org SkScalar fRadius[2]; //!< Type specific, see above. 354d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org TileMode fTileMode; //!< The tile mode used. 3553d3a860d0ba878adb905512a45c500a67532b0a3reed@google.com uint32_t fGradientFlags; //!< see SkGradientShader::Flags 356d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org }; 357d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org 358d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org virtual GradientType asAGradient(GradientInfo* info) const; 359d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org 36003c1c359b336ad20d23ab07004cdafafd14c90a5rileya@google.com /** 361795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org * If the shader subclass is composed of two shaders, return true, and if rec is not NULL, 362795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org * fill it out with info about the shader. 3633055879cbf88095a46343736f3f4417761b8afe7commit-bot@chromium.org * 3643055879cbf88095a46343736f3f4417761b8afe7commit-bot@chromium.org * These are bare pointers; the ownership and reference count are unchanged. 365795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org */ 366795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org 367795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org struct ComposeRec { 368795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org const SkShader* fShaderA; 369795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org const SkShader* fShaderB; 370795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org const SkXfermode* fMode; 371795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org }; 372795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org 373795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org virtual bool asACompose(ComposeRec* rec) const { return false; } 374795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org 375795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org 376795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org /** 3779de5b514d38c5b36066bcdc14fba2f7e5196d372dandov * Returns true if the shader subclass succeeds in setting the grEffect and the grColor output 3789de5b514d38c5b36066bcdc14fba2f7e5196d372dandov * parameters to a value, returns false if it fails or if there is not an implementation of 3799de5b514d38c5b36066bcdc14fba2f7e5196d372dandov * this method in the shader subclass. 38091a798f121a2238639f8e2d08cc776d4f0236cebcommit-bot@chromium.org * The incoming color to the effect has r=g=b=a all extracted from the SkPaint's alpha. 38191a798f121a2238639f8e2d08cc776d4f0236cebcommit-bot@chromium.org * The output color should be the computed SkShader premul color modulated by the incoming 38291a798f121a2238639f8e2d08cc776d4f0236cebcommit-bot@chromium.org * color. The GrContext may be used by the effect to create textures. The GPU device does not 38387fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org * call createContext. Instead we pass the SkPaint here in case the shader needs paint info. 38403c1c359b336ad20d23ab07004cdafafd14c90a5rileya@google.com */ 3859de5b514d38c5b36066bcdc14fba2f7e5196d372dandov virtual bool asNewEffect(GrContext* context, const SkPaint& paint, 3869de5b514d38c5b36066bcdc14fba2f7e5196d372dandov const SkMatrix* localMatrixOrNull, GrColor* grColor, 3879de5b514d38c5b36066bcdc14fba2f7e5196d372dandov GrEffectRef** grEffect) const; 38803c1c359b336ad20d23ab07004cdafafd14c90a5rileya@google.com 389795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK 390795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org /** 391795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org * If the shader is a custom shader which has data the caller might want, call this function 392795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org * to get that data. 393795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org */ 394795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org virtual bool asACustomShader(void** customData) const { return false; } 395795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org#endif 396795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org 3978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ////////////////////////////////////////////////////////////////////////// 3988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // Factory methods for stock shaders 3998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 400ce56d965069c1649afe14319cb239e6ad670682acommit-bot@chromium.org /** 401ce56d965069c1649afe14319cb239e6ad670682acommit-bot@chromium.org * Call this to create a new "empty" shader, that will not draw anything. 402ce56d965069c1649afe14319cb239e6ad670682acommit-bot@chromium.org */ 403ce56d965069c1649afe14319cb239e6ad670682acommit-bot@chromium.org static SkShader* CreateEmptyShader(); 404ce56d965069c1649afe14319cb239e6ad670682acommit-bot@chromium.org 4058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Call this to create a new shader that will draw with the specified bitmap. 40699c114e0ac732ba01705e24d12f5e4dd7e144abdreed@google.com * 40799c114e0ac732ba01705e24d12f5e4dd7e144abdreed@google.com * If the bitmap cannot be used (e.g. has no pixels, or its dimensions 40899c114e0ac732ba01705e24d12f5e4dd7e144abdreed@google.com * exceed implementation limits (currently at 64K - 1)) then SkEmptyShader 40999c114e0ac732ba01705e24d12f5e4dd7e144abdreed@google.com * may be returned. 41099c114e0ac732ba01705e24d12f5e4dd7e144abdreed@google.com * 41191246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org * If the src is kA8_Config then that mask will be colorized using the color on 41291246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org * the paint. 41391246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org * 41499c114e0ac732ba01705e24d12f5e4dd7e144abdreed@google.com * @param src The bitmap to use inside the shader 41599c114e0ac732ba01705e24d12f5e4dd7e144abdreed@google.com * @param tmx The tiling mode to use when sampling the bitmap in the x-direction. 41699c114e0ac732ba01705e24d12f5e4dd7e144abdreed@google.com * @param tmy The tiling mode to use when sampling the bitmap in the y-direction. 41799c114e0ac732ba01705e24d12f5e4dd7e144abdreed@google.com * @return Returns a new shader object. Note: this function never returns null. 4188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static SkShader* CreateBitmapShader(const SkBitmap& src, 4209c9005a347e9996f357bd79591bd34f74f8bbc66commit-bot@chromium.org TileMode tmx, TileMode tmy, 4219c9005a347e9996f357bd79591bd34f74f8bbc66commit-bot@chromium.org const SkMatrix* localMatrix = NULL); 4228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 423c5d9bb0f677069f62ec76373b9730e70e7352455commit-bot@chromium.org /** Call this to create a new shader that will draw with the specified picture. 424c5d9bb0f677069f62ec76373b9730e70e7352455commit-bot@chromium.org * 425c5d9bb0f677069f62ec76373b9730e70e7352455commit-bot@chromium.org * @param src The picture to use inside the shader (if not NULL, its ref count 426855e88edfafe4b3892e99f932c38fa7433b2fcbecommit-bot@chromium.org * is incremented). The SkPicture must not be changed after 427855e88edfafe4b3892e99f932c38fa7433b2fcbecommit-bot@chromium.org * successfully creating a picture shader. 428855e88edfafe4b3892e99f932c38fa7433b2fcbecommit-bot@chromium.org * FIXME: src cannot be const due to SkCanvas::drawPicture 429c5d9bb0f677069f62ec76373b9730e70e7352455commit-bot@chromium.org * @param tmx The tiling mode to use when sampling the bitmap in the x-direction. 430c5d9bb0f677069f62ec76373b9730e70e7352455commit-bot@chromium.org * @param tmy The tiling mode to use when sampling the bitmap in the y-direction. 431c5d9bb0f677069f62ec76373b9730e70e7352455commit-bot@chromium.org * @return Returns a new shader object. Note: this function never returns null. 432c5d9bb0f677069f62ec76373b9730e70e7352455commit-bot@chromium.org */ 4335aacfe9ffcf1849727dca6761b4a221bd4315f26commit-bot@chromium.org static SkShader* CreatePictureShader(SkPicture* src, TileMode tmx, TileMode tmy, 4345aacfe9ffcf1849727dca6761b4a221bd4315f26commit-bot@chromium.org const SkMatrix* localMatrix = NULL); 435c5d9bb0f677069f62ec76373b9730e70e7352455commit-bot@chromium.org 4368fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org /** 4378fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org * Return a shader that will apply the specified localMatrix to the proxy shader. 4388fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org * The specified matrix will be applied before any matrix associated with the proxy. 4398fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org * 4408fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org * Note: ownership of the proxy is not transferred (though a ref is taken). 4418fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org */ 4428fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org static SkShader* CreateLocalMatrixShader(SkShader* proxy, const SkMatrix& localMatrix); 4438fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org 4448fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org /** 4458fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org * If this shader can be represented by another shader + a localMatrix, return that shader 4468fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org * and, if not NULL, the localMatrix. If not, return NULL and ignore the localMatrix parameter. 4478fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org * 4488fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org * Note: the returned shader (if not NULL) will have been ref'd, and it is the responsibility 4498fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org * of the caller to balance that with unref() when they are done. 4508fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org */ 4518fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org virtual SkShader* refAsALocalMatrixShader(SkMatrix* localMatrix) const; 4528fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org 4530f10f7bf1fb43ca6346dc220a076773b1f19a367commit-bot@chromium.org SK_TO_STRING_VIRT() 454c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org SK_DEFINE_FLATTENABLE_TYPE(SkShader) 455c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org 4568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected: 4578b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.org SkShader(SkReadBuffer& ); 4588b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.org virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; 45987fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org 460ce56d965069c1649afe14319cb239e6ad670682acommit-bot@chromium.org bool computeTotalInverse(const ContextRec&, SkMatrix* totalInverse) const; 461ce56d965069c1649afe14319cb239e6ad670682acommit-bot@chromium.org 462ce56d965069c1649afe14319cb239e6ad670682acommit-bot@chromium.org /** 463ce56d965069c1649afe14319cb239e6ad670682acommit-bot@chromium.org * Your subclass must also override contextSize() if it overrides onCreateContext(). 464ce56d965069c1649afe14319cb239e6ad670682acommit-bot@chromium.org * Base class impl returns NULL. 465ce56d965069c1649afe14319cb239e6ad670682acommit-bot@chromium.org */ 466ce56d965069c1649afe14319cb239e6ad670682acommit-bot@chromium.org virtual Context* onCreateContext(const ContextRec&, void* storage) const; 46787fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org 468ce56d965069c1649afe14319cb239e6ad670682acommit-bot@chromium.orgprivate: 469ce56d965069c1649afe14319cb239e6ad670682acommit-bot@chromium.org SkMatrix fLocalMatrix; 4709de5b514d38c5b36066bcdc14fba2f7e5196d372dandov 4718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com typedef SkFlattenable INHERITED; 4728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 4738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 475