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 1959f23a27ed9961fd4575864e590eda328452895e7reed // Notification from blitter::blitMask in case we need to see the non-alpha channels 1969f23a27ed9961fd4575864e590eda328452895e7reed virtual void set3DMask(const SkMask*) {} 1979f23a27ed9961fd4575864e590eda328452895e7reed 19887fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org protected: 19987fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org // Reference to shader, so we don't have to dupe information. 20087fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org const SkShader& fShader; 20187fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org 20287fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org enum MatrixClass { 20387fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org kLinear_MatrixClass, // no perspective 20487fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org kFixedStepInX_MatrixClass, // fast perspective, need to call fixedStepInX() each 20587fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org // scanline 20687fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org kPerspective_MatrixClass // slow perspective, need to mappoints each pixel 20787fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org }; 20887fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org static MatrixClass ComputeMatrixClass(const SkMatrix&); 20987fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org 21080116dcf1e1baf9817ae42d0aca51f7eabaa2880commit-bot@chromium.org uint8_t getPaintAlpha() const { return fPaintAlpha; } 21180116dcf1e1baf9817ae42d0aca51f7eabaa2880commit-bot@chromium.org const SkMatrix& getTotalInverse() const { return fTotalInverse; } 21280116dcf1e1baf9817ae42d0aca51f7eabaa2880commit-bot@chromium.org MatrixClass getInverseClass() const { return (MatrixClass)fTotalInverseClass; } 21380116dcf1e1baf9817ae42d0aca51f7eabaa2880commit-bot@chromium.org const SkMatrix& getCTM() const { return fCTM; } 21487fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org private: 21580116dcf1e1baf9817ae42d0aca51f7eabaa2880commit-bot@chromium.org SkMatrix fCTM; 21680116dcf1e1baf9817ae42d0aca51f7eabaa2880commit-bot@chromium.org SkMatrix fTotalInverse; 21780116dcf1e1baf9817ae42d0aca51f7eabaa2880commit-bot@chromium.org uint8_t fPaintAlpha; 21880116dcf1e1baf9817ae42d0aca51f7eabaa2880commit-bot@chromium.org uint8_t fTotalInverseClass; 21987fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org 22087fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org typedef SkNoncopyable INHERITED; 22187fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org }; 2223bafe74a29c37761082980ed4ee9b831256bd27ereed@google.com 223ad91799832b9ba2a3de30c0f57968148b4be17afreed@google.com /** 22487fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org * Create the actual object that does the shading. 22587fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org * Size of storage must be >= contextSize. 226ad91799832b9ba2a3de30c0f57968148b4be17afreed@google.com */ 227ce56d965069c1649afe14319cb239e6ad670682acommit-bot@chromium.org Context* createContext(const ContextRec&, void* storage) const; 2288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 229ad91799832b9ba2a3de30c0f57968148b4be17afreed@google.com /** 23087fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org * Return the size of a Context returned by createContext. 231f3e505984d08fb96e753be2b561f479dc3a4c544commit-bot@chromium.org * 232f3e505984d08fb96e753be2b561f479dc3a4c544commit-bot@chromium.org * Override this if your subclass overrides createContext, to return the correct size of 233f3e505984d08fb96e753be2b561f479dc3a4c544commit-bot@chromium.org * your subclass' context. 234ad91799832b9ba2a3de30c0f57968148b4be17afreed@google.com */ 235f3e505984d08fb96e753be2b561f479dc3a4c544commit-bot@chromium.org virtual size_t contextSize() const; 2368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 237ad91799832b9ba2a3de30c0f57968148b4be17afreed@google.com /** 238ad91799832b9ba2a3de30c0f57968148b4be17afreed@google.com * Helper to check the flags to know if it is legal to call shadeSpan16() 239ad91799832b9ba2a3de30c0f57968148b4be17afreed@google.com */ 2408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static bool CanCallShadeSpan16(uint32_t flags) { 2418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return (flags & kHasSpan16_Flag) != 0; 2428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 244ad91799832b9ba2a3de30c0f57968148b4be17afreed@google.com /** 245f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com Gives method bitmap should be read to implement a shader. 246f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com Also determines number and interpretation of "extra" parameters returned 247f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com by asABitmap 248f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com */ 249f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com enum BitmapType { 250f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com kNone_BitmapType, //<! Shader is not represented as a bitmap 2517c2f27d788fff9dbf66a6d52753e47f786a313c0reed@google.com kDefault_BitmapType,//<! Access bitmap using local coords transformed 252f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // by matrix. No extras 2537c2f27d788fff9dbf66a6d52753e47f786a313c0reed@google.com kRadial_BitmapType, //<! Access bitmap by transforming local coordinates 2547c2f27d788fff9dbf66a6d52753e47f786a313c0reed@google.com // by the matrix and taking the distance of result 2557c2f27d788fff9dbf66a6d52753e47f786a313c0reed@google.com // from (0,0) as bitmap column. Bitmap is 1 pixel 256f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // tall. No extras 2577c2f27d788fff9dbf66a6d52753e47f786a313c0reed@google.com kSweep_BitmapType, //<! Access bitmap by transforming local coordinates 258f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // by the matrix and taking the angle of result 259f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // to (0,0) as bitmap x coord, where angle = 0 is 2607c2f27d788fff9dbf66a6d52753e47f786a313c0reed@google.com // bitmap left edge of bitmap = 2pi is the 261f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // right edge. Bitmap is 1 pixel tall. No extras 262d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org kTwoPointRadial_BitmapType, 2637c2f27d788fff9dbf66a6d52753e47f786a313c0reed@google.com //<! Matrix transforms to space where (0,0) is 264f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // the center of the starting circle. The second 2657c2f27d788fff9dbf66a6d52753e47f786a313c0reed@google.com // circle will be centered (x, 0) where x may be 2667c2f27d788fff9dbf66a6d52753e47f786a313c0reed@google.com // 0. The post-matrix space is normalized such 267f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // that 1 is the second radius - first radius. 268f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // Three extra parameters are returned: 2697c2f27d788fff9dbf66a6d52753e47f786a313c0reed@google.com // 0: x-offset of second circle center 270f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // to first. 2717c2f27d788fff9dbf66a6d52753e47f786a313c0reed@google.com // 1: radius of first circle in post-matrix 272f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // space 273f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // 2: the second radius minus the first radius 2747c2f27d788fff9dbf66a6d52753e47f786a313c0reed@google.com // in pre-transformed space. 2753e33258cd15faae4a2906ddcc586e4008ee20e68rileya@google.com kTwoPointConical_BitmapType, 2763e33258cd15faae4a2906ddcc586e4008ee20e68rileya@google.com //<! Matrix transforms to space where (0,0) is 2773e33258cd15faae4a2906ddcc586e4008ee20e68rileya@google.com // the center of the starting circle. The second 2783e33258cd15faae4a2906ddcc586e4008ee20e68rileya@google.com // circle will be centered (x, 0) where x may be 2793e33258cd15faae4a2906ddcc586e4008ee20e68rileya@google.com // 0. 2803e33258cd15faae4a2906ddcc586e4008ee20e68rileya@google.com // Three extra parameters are returned: 2813e33258cd15faae4a2906ddcc586e4008ee20e68rileya@google.com // 0: x-offset of second circle center 2823e33258cd15faae4a2906ddcc586e4008ee20e68rileya@google.com // to first. 2833e33258cd15faae4a2906ddcc586e4008ee20e68rileya@google.com // 1: radius of first circle 2843e33258cd15faae4a2906ddcc586e4008ee20e68rileya@google.com // 2: the second radius minus the first radius 28522e57f991628451c02f970beea379ad632bb6a10rileya@google.com kLinear_BitmapType, //<! Access bitmap using local coords transformed 28622e57f991628451c02f970beea379ad632bb6a10rileya@google.com // by matrix. No extras 287d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org 28822e57f991628451c02f970beea379ad632bb6a10rileya@google.com kLast_BitmapType = kLinear_BitmapType 289f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com }; 2908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Optional methods for shaders that can pretend to be a bitmap/texture 2917c2f27d788fff9dbf66a6d52753e47f786a313c0reed@google.com to play along with opengl. Default just returns kNone_BitmapType and 292f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com ignores the out parameters. 293f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com 294f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com @param outTexture if non-NULL will be the bitmap representing the shader 295f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com after return. 296f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com @param outMatrix if non-NULL will be the matrix to apply to vertices 297f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com to access the bitmap after return. 298f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com @param xy if non-NULL will be the tile modes that should be 299f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com used to access the bitmap after return. 300f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com @param twoPointRadialParams Two extra return values needed for two point 301f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com radial bitmaps. The first is the x-offset of 302f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com the second point and the second is the radius 303f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com about the first point. 3048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 305f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com virtual BitmapType asABitmap(SkBitmap* outTexture, SkMatrix* outMatrix, 30691f319c5dc4493384f0a52aaeef3dcc311ef6ed0rileya@google.com TileMode xy[2]) const; 3078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 308d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org /** 309d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * If the shader subclass can be represented as a gradient, asAGradient 310d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * returns the matching GradientType enum (or kNone_GradientType if it 311d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * cannot). Also, if info is not null, asAGradient populates info with 312d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * the relevant (see below) parameters for the gradient. fColorCount 313d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * is both an input and output parameter. On input, it indicates how 314d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * many entries in fColors and fColorOffsets can be used, if they are 315d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * non-NULL. After asAGradient has run, fColorCount indicates how 316d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * many color-offset pairs there are in the gradient. If there is 317d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * insufficient space to store all of the color-offset pairs, fColors 318d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * and fColorOffsets will not be altered. fColorOffsets specifies 319d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * where on the range of 0 to 1 to transition to the given color. 320d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * The meaning of fPoint and fRadius is dependant on the type of gradient. 321d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * 322d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * None: 323d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * info is ignored. 324d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * Color: 325d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * fColorOffsets[0] is meaningless. 326d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * Linear: 327d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * fPoint[0] and fPoint[1] are the end-points of the gradient 328d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * Radial: 329d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * fPoint[0] and fRadius[0] are the center and radius 330d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * Radial2: 331d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * fPoint[0] and fRadius[0] are the center and radius of the 1st circle 332d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * fPoint[1] and fRadius[1] are the center and radius of the 2nd circle 333d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * Sweep: 334d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org * fPoint[0] is the center of the sweep. 335d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org */ 336d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org 337d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org enum GradientType { 338d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org kNone_GradientType, 339d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org kColor_GradientType, 340d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org kLinear_GradientType, 341d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org kRadial_GradientType, 342d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org kRadial2_GradientType, 343d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org kSweep_GradientType, 34483226976b532141b26ff3a40f381a5d08ce3259dreed@google.com kConical_GradientType, 34583226976b532141b26ff3a40f381a5d08ce3259dreed@google.com kLast_GradientType = kConical_GradientType 346d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org }; 347d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org 348d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org struct GradientInfo { 349d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org int fColorCount; //!< In-out parameter, specifies passed size 350d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org // of fColors/fColorOffsets on input, and 351d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org // actual number of colors/offsets on 352d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org // output. 353d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org SkColor* fColors; //!< The colors in the gradient. 354d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org SkScalar* fColorOffsets; //!< The unit offset for color transitions. 355d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org SkPoint fPoint[2]; //!< Type specific, see above. 356d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org SkScalar fRadius[2]; //!< Type specific, see above. 357d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org TileMode fTileMode; //!< The tile mode used. 3583d3a860d0ba878adb905512a45c500a67532b0a3reed@google.com uint32_t fGradientFlags; //!< see SkGradientShader::Flags 359d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org }; 360d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org 361d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org virtual GradientType asAGradient(GradientInfo* info) const; 362d3ae77965e94e0efda496f5461cbec4533cb5b16vandebo@chromium.org 36303c1c359b336ad20d23ab07004cdafafd14c90a5rileya@google.com /** 364795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org * If the shader subclass is composed of two shaders, return true, and if rec is not NULL, 365795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org * fill it out with info about the shader. 3663055879cbf88095a46343736f3f4417761b8afe7commit-bot@chromium.org * 3673055879cbf88095a46343736f3f4417761b8afe7commit-bot@chromium.org * These are bare pointers; the ownership and reference count are unchanged. 368795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org */ 369795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org 370795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org struct ComposeRec { 371795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org const SkShader* fShaderA; 372795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org const SkShader* fShaderB; 373795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org const SkXfermode* fMode; 374795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org }; 375795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org 376795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org virtual bool asACompose(ComposeRec* rec) const { return false; } 377795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org 378795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org 379795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org /** 3809de5b514d38c5b36066bcdc14fba2f7e5196d372dandov * Returns true if the shader subclass succeeds in setting the grEffect and the grColor output 3819de5b514d38c5b36066bcdc14fba2f7e5196d372dandov * parameters to a value, returns false if it fails or if there is not an implementation of 3829de5b514d38c5b36066bcdc14fba2f7e5196d372dandov * this method in the shader subclass. 38391a798f121a2238639f8e2d08cc776d4f0236cebcommit-bot@chromium.org * The incoming color to the effect has r=g=b=a all extracted from the SkPaint's alpha. 38491a798f121a2238639f8e2d08cc776d4f0236cebcommit-bot@chromium.org * The output color should be the computed SkShader premul color modulated by the incoming 38591a798f121a2238639f8e2d08cc776d4f0236cebcommit-bot@chromium.org * color. The GrContext may be used by the effect to create textures. The GPU device does not 38687fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org * call createContext. Instead we pass the SkPaint here in case the shader needs paint info. 38703c1c359b336ad20d23ab07004cdafafd14c90a5rileya@google.com */ 3889de5b514d38c5b36066bcdc14fba2f7e5196d372dandov virtual bool asNewEffect(GrContext* context, const SkPaint& paint, 3899de5b514d38c5b36066bcdc14fba2f7e5196d372dandov const SkMatrix* localMatrixOrNull, GrColor* grColor, 3909de5b514d38c5b36066bcdc14fba2f7e5196d372dandov GrEffectRef** grEffect) const; 39103c1c359b336ad20d23ab07004cdafafd14c90a5rileya@google.com 392795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK 393795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org /** 394795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org * If the shader is a custom shader which has data the caller might want, call this function 395795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org * to get that data. 396795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org */ 397795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org virtual bool asACustomShader(void** customData) const { return false; } 398f51de259ada8dacd44eca41945b49a8dba1606aeJohn Reck 399f51de259ada8dacd44eca41945b49a8dba1606aeJohn Reck uint32_t getGenerationID() const { return fGenerationID; } 400f51de259ada8dacd44eca41945b49a8dba1606aeJohn Reck void setGenerationID(uint32_t generationID) { fGenerationID = generationID; } 401795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org#endif 402795905562d1bd8bbedcf47f6a00efb220ec8bbe0commit-bot@chromium.org 4038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ////////////////////////////////////////////////////////////////////////// 4048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // Factory methods for stock shaders 4058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 406ce56d965069c1649afe14319cb239e6ad670682acommit-bot@chromium.org /** 407ce56d965069c1649afe14319cb239e6ad670682acommit-bot@chromium.org * Call this to create a new "empty" shader, that will not draw anything. 408ce56d965069c1649afe14319cb239e6ad670682acommit-bot@chromium.org */ 409ce56d965069c1649afe14319cb239e6ad670682acommit-bot@chromium.org static SkShader* CreateEmptyShader(); 410ce56d965069c1649afe14319cb239e6ad670682acommit-bot@chromium.org 4118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Call this to create a new shader that will draw with the specified bitmap. 41299c114e0ac732ba01705e24d12f5e4dd7e144abdreed@google.com * 41399c114e0ac732ba01705e24d12f5e4dd7e144abdreed@google.com * If the bitmap cannot be used (e.g. has no pixels, or its dimensions 41499c114e0ac732ba01705e24d12f5e4dd7e144abdreed@google.com * exceed implementation limits (currently at 64K - 1)) then SkEmptyShader 41599c114e0ac732ba01705e24d12f5e4dd7e144abdreed@google.com * may be returned. 41699c114e0ac732ba01705e24d12f5e4dd7e144abdreed@google.com * 41791246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org * If the src is kA8_Config then that mask will be colorized using the color on 41891246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org * the paint. 41991246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org * 42099c114e0ac732ba01705e24d12f5e4dd7e144abdreed@google.com * @param src The bitmap to use inside the shader 42199c114e0ac732ba01705e24d12f5e4dd7e144abdreed@google.com * @param tmx The tiling mode to use when sampling the bitmap in the x-direction. 42299c114e0ac732ba01705e24d12f5e4dd7e144abdreed@google.com * @param tmy The tiling mode to use when sampling the bitmap in the y-direction. 42399c114e0ac732ba01705e24d12f5e4dd7e144abdreed@google.com * @return Returns a new shader object. Note: this function never returns null. 4248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static SkShader* CreateBitmapShader(const SkBitmap& src, 4269c9005a347e9996f357bd79591bd34f74f8bbc66commit-bot@chromium.org TileMode tmx, TileMode tmy, 4279c9005a347e9996f357bd79591bd34f74f8bbc66commit-bot@chromium.org const SkMatrix* localMatrix = NULL); 4288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 429c5d9bb0f677069f62ec76373b9730e70e7352455commit-bot@chromium.org /** Call this to create a new shader that will draw with the specified picture. 430c5d9bb0f677069f62ec76373b9730e70e7352455commit-bot@chromium.org * 431c5d9bb0f677069f62ec76373b9730e70e7352455commit-bot@chromium.org * @param src The picture to use inside the shader (if not NULL, its ref count 432855e88edfafe4b3892e99f932c38fa7433b2fcbecommit-bot@chromium.org * is incremented). The SkPicture must not be changed after 433855e88edfafe4b3892e99f932c38fa7433b2fcbecommit-bot@chromium.org * successfully creating a picture shader. 434855e88edfafe4b3892e99f932c38fa7433b2fcbecommit-bot@chromium.org * FIXME: src cannot be const due to SkCanvas::drawPicture 435c5d9bb0f677069f62ec76373b9730e70e7352455commit-bot@chromium.org * @param tmx The tiling mode to use when sampling the bitmap in the x-direction. 436c5d9bb0f677069f62ec76373b9730e70e7352455commit-bot@chromium.org * @param tmy The tiling mode to use when sampling the bitmap in the y-direction. 437c5d9bb0f677069f62ec76373b9730e70e7352455commit-bot@chromium.org * @return Returns a new shader object. Note: this function never returns null. 438c5d9bb0f677069f62ec76373b9730e70e7352455commit-bot@chromium.org */ 4395aacfe9ffcf1849727dca6761b4a221bd4315f26commit-bot@chromium.org static SkShader* CreatePictureShader(SkPicture* src, TileMode tmx, TileMode tmy, 4405aacfe9ffcf1849727dca6761b4a221bd4315f26commit-bot@chromium.org const SkMatrix* localMatrix = NULL); 441c5d9bb0f677069f62ec76373b9730e70e7352455commit-bot@chromium.org 4428fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org /** 4438fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org * Return a shader that will apply the specified localMatrix to the proxy shader. 4448fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org * The specified matrix will be applied before any matrix associated with the proxy. 4458fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org * 4468fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org * Note: ownership of the proxy is not transferred (though a ref is taken). 4478fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org */ 4488fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org static SkShader* CreateLocalMatrixShader(SkShader* proxy, const SkMatrix& localMatrix); 4498fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org 4508fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org /** 4518fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org * If this shader can be represented by another shader + a localMatrix, return that shader 4528fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org * and, if not NULL, the localMatrix. If not, return NULL and ignore the localMatrix parameter. 4538fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org * 4548fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org * Note: the returned shader (if not NULL) will have been ref'd, and it is the responsibility 4558fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org * of the caller to balance that with unref() when they are done. 4568fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org */ 4578fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org virtual SkShader* refAsALocalMatrixShader(SkMatrix* localMatrix) const; 4588fae213590981b8ca37839a4e3cae1dae4e611fdcommit-bot@chromium.org 4590f10f7bf1fb43ca6346dc220a076773b1f19a367commit-bot@chromium.org SK_TO_STRING_VIRT() 460c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org SK_DEFINE_FLATTENABLE_TYPE(SkShader) 461c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org 4628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected: 4638b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.org SkShader(SkReadBuffer& ); 4648b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.org virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; 46587fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org 466ce56d965069c1649afe14319cb239e6ad670682acommit-bot@chromium.org bool computeTotalInverse(const ContextRec&, SkMatrix* totalInverse) const; 467ce56d965069c1649afe14319cb239e6ad670682acommit-bot@chromium.org 468ce56d965069c1649afe14319cb239e6ad670682acommit-bot@chromium.org /** 469ce56d965069c1649afe14319cb239e6ad670682acommit-bot@chromium.org * Your subclass must also override contextSize() if it overrides onCreateContext(). 470ce56d965069c1649afe14319cb239e6ad670682acommit-bot@chromium.org * Base class impl returns NULL. 471ce56d965069c1649afe14319cb239e6ad670682acommit-bot@chromium.org */ 472ce56d965069c1649afe14319cb239e6ad670682acommit-bot@chromium.org virtual Context* onCreateContext(const ContextRec&, void* storage) const; 47387fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org 474ce56d965069c1649afe14319cb239e6ad670682acommit-bot@chromium.orgprivate: 475ce56d965069c1649afe14319cb239e6ad670682acommit-bot@chromium.org SkMatrix fLocalMatrix; 4769de5b514d38c5b36066bcdc14fba2f7e5196d372dandov 4778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com typedef SkFlattenable INHERITED; 478f51de259ada8dacd44eca41945b49a8dba1606aeJohn Reck 479f51de259ada8dacd44eca41945b49a8dba1606aeJohn Reck#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK 480f51de259ada8dacd44eca41945b49a8dba1606aeJohn Reck uint32_t fGenerationID; 481f51de259ada8dacd44eca41945b49a8dba1606aeJohn Reck#endif 4828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 4838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 485