1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/*
3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project
4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com *
5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be
6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file.
7ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com */
8ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkBitmapProcShader_DEFINED
118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkBitmapProcShader_DEFINED
128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkShader.h"
148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkBitmapProcState.h"
15a5572e5bb2a2bbeeb59de0741c2527869d365a0ccommit-bot@chromium.org#include "SkSmallAllocator.h"
168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkBitmapProcShader : public SkShader {
188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
199c9005a347e9996f357bd79591bd34f74f8bbc66commit-bot@chromium.org    SkBitmapProcShader(const SkBitmap& src, TileMode tx, TileMode ty,
209c9005a347e9996f357bd79591bd34f74f8bbc66commit-bot@chromium.org                       const SkMatrix* localMatrix = NULL);
218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // overrides from SkShader
23b6e161937bc890f0aa12ac5e27415d4d260ea6e0junov@chromium.org    virtual bool isOpaque() const SK_OVERRIDE;
2476f9e938df0b5826fd4c80b854ceafaf385cfbe1robertphillips@google.com    virtual BitmapType asABitmap(SkBitmap*, SkMatrix*, TileMode*) const SK_OVERRIDE;
258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2687fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org    virtual size_t contextSize() const SK_OVERRIDE;
2787fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org
288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    static bool CanDo(const SkBitmap&, TileMode tx, TileMode ty);
29ff21c2e0ae23da0f4742b47d4d37969a2a18bd99skia.committer@gmail.com
300f10f7bf1fb43ca6346dc220a076773b1f19a367commit-bot@chromium.org    SK_TO_STRING_OVERRIDE()
31ba28d03e94dc221d6a803bf2a84a420b9159255cdjsollen@google.com    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBitmapProcShader)
328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
339de5b514d38c5b36066bcdc14fba2f7e5196d372dandov
34b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt    bool asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix*, GrColor*,
35b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt                             GrFragmentProcessor**)
369de5b514d38c5b36066bcdc14fba2f7e5196d372dandov            const SK_OVERRIDE;
37e197cbf9a3e66bab926bc5e51962752dad5221a0bsalomon@google.com
3887fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org    class BitmapProcShaderContext : public SkShader::Context {
3987fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org    public:
4087fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org        // The context takes ownership of the state. It will call its destructor
4187fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org        // but will NOT free the memory.
42e901b6de3ef8dea842008a08fc81e92fb1478d61commit-bot@chromium.org        BitmapProcShaderContext(const SkBitmapProcShader&, const ContextRec&, SkBitmapProcState*);
4387fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org        virtual ~BitmapProcShaderContext();
4487fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org
4587fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org        virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) SK_OVERRIDE;
4687fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org        virtual ShadeProc asAShadeProc(void** ctx) SK_OVERRIDE;
4787fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org        virtual void shadeSpan16(int x, int y, uint16_t dstC[], int count) SK_OVERRIDE;
4887fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org
4987fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org        virtual uint32_t getFlags() const SK_OVERRIDE { return fFlags; }
5087fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org
5187fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org    private:
5287fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org        SkBitmapProcState*  fState;
5387fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org        uint32_t            fFlags;
5487fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org
5587fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org        typedef SkShader::Context INHERITED;
5687fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org    };
5787fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org
588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected:
599fa60daad4d5f54c0dbe3dbcc7608a8f6d721187reed#ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
608b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.org    SkBitmapProcShader(SkReadBuffer& );
619fa60daad4d5f54c0dbe3dbcc7608a8f6d721187reed#endif
628b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.org    virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
63ce56d965069c1649afe14319cb239e6ad670682acommit-bot@chromium.org    virtual Context* onCreateContext(const ContextRec&, void* storage) const SK_OVERRIDE;
648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6587fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org    SkBitmap    fRawBitmap;   // experimental for RLE encoding
6687fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org    uint8_t     fTileModeX, fTileModeY;
678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
687c2f27d788fff9dbf66a6d52753e47f786a313c0reed@google.comprivate:
698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    typedef SkShader INHERITED;
708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7287fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org// Commonly used allocator. It currently is only used to allocate up to 3 objects. The total
7387fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org// bytes requested is calculated using one of our large shaders, its context size plus the size of
7487fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org// an Sk3DBlitter in SkDraw.cpp
7587fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org// Note that some contexts may contain other contexts (e.g. for compose shaders), but we've not
7687fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org// yet found a situation where the size below isn't big enough.
77cc0e3110bde60201882a2c512a5cdd73c838f351reedtypedef SkSmallAllocator<3, 1024> SkTBlitterAllocator;
78a5572e5bb2a2bbeeb59de0741c2527869d365a0ccommit-bot@chromium.org
79a5572e5bb2a2bbeeb59de0741c2527869d365a0ccommit-bot@chromium.org// If alloc is non-NULL, it will be used to allocate the returned SkShader, and MUST outlive
80a5572e5bb2a2bbeeb59de0741c2527869d365a0ccommit-bot@chromium.org// the SkShader.
81a5572e5bb2a2bbeeb59de0741c2527869d365a0ccommit-bot@chromium.orgSkShader* CreateBitmapShader(const SkBitmap& src, SkShader::TileMode, SkShader::TileMode,
829c9005a347e9996f357bd79591bd34f74f8bbc66commit-bot@chromium.org                             const SkMatrix* localMatrix, SkTBlitterAllocator* alloc);
83a5572e5bb2a2bbeeb59de0741c2527869d365a0ccommit-bot@chromium.org
848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
85