michael@0: michael@0: /* michael@0: * Copyright 2006 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #ifndef SkBitmapProcShader_DEFINED michael@0: #define SkBitmapProcShader_DEFINED michael@0: michael@0: #include "SkShader.h" michael@0: #include "SkBitmapProcState.h" michael@0: #include "SkSmallAllocator.h" michael@0: michael@0: class SkBitmapProcShader : public SkShader { michael@0: public: michael@0: SkBitmapProcShader(const SkBitmap& src, TileMode tx, TileMode ty); michael@0: michael@0: // overrides from SkShader michael@0: virtual bool isOpaque() const SK_OVERRIDE; michael@0: virtual bool setContext(const SkBitmap&, const SkPaint&, const SkMatrix&) SK_OVERRIDE; michael@0: virtual void endContext() SK_OVERRIDE; michael@0: virtual uint32_t getFlags() SK_OVERRIDE { return fFlags; } michael@0: virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) SK_OVERRIDE; michael@0: virtual ShadeProc asAShadeProc(void** ctx) SK_OVERRIDE; michael@0: virtual void shadeSpan16(int x, int y, uint16_t dstC[], int count) SK_OVERRIDE; michael@0: virtual BitmapType asABitmap(SkBitmap*, SkMatrix*, TileMode*) const SK_OVERRIDE; michael@0: michael@0: static bool CanDo(const SkBitmap&, TileMode tx, TileMode ty); michael@0: michael@0: SK_TO_STRING_OVERRIDE() michael@0: SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBitmapProcShader) michael@0: michael@0: #if SK_SUPPORT_GPU michael@0: GrEffectRef* asNewEffect(GrContext*, const SkPaint&) const SK_OVERRIDE; michael@0: #endif michael@0: michael@0: protected: michael@0: SkBitmapProcShader(SkReadBuffer& ); michael@0: virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; michael@0: michael@0: SkBitmap fRawBitmap; // experimental for RLE encoding michael@0: SkBitmapProcState fState; michael@0: uint32_t fFlags; michael@0: michael@0: private: michael@0: typedef SkShader INHERITED; michael@0: }; michael@0: michael@0: // Commonly used allocator. It currently is only used to allocate up to 2 objects. The total michael@0: // bytes requested is calculated using one of our large shaders plus the size of an Sk3DBlitter michael@0: // in SkDraw.cpp michael@0: typedef SkSmallAllocator<2, sizeof(SkBitmapProcShader) + sizeof(void*) * 2> SkTBlitterAllocator; michael@0: michael@0: // If alloc is non-NULL, it will be used to allocate the returned SkShader, and MUST outlive michael@0: // the SkShader. michael@0: SkShader* CreateBitmapShader(const SkBitmap& src, SkShader::TileMode, SkShader::TileMode, michael@0: SkTBlitterAllocator* alloc); michael@0: michael@0: #endif