3 * Copyright 2006 The Android Open Source Project
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
10 #ifndef SkBitmapProcShader_DEFINED
11 #define SkBitmapProcShader_DEFINED
14 #include "SkBitmapProcState.h"
15 #include "SkSmallAllocator.h"
17 class SkBitmapProcShader : public SkShader {
19 SkBitmapProcShader(const SkBitmap& src, TileMode tx, TileMode ty,
20 const SkMatrix* localMatrix = NULL);
22 // overrides from SkShader
23 virtual bool isOpaque() const SK_OVERRIDE;
24 virtual BitmapType asABitmap(SkBitmap*, SkMatrix*, TileMode*) const SK_OVERRIDE;
26 virtual size_t contextSize() const SK_OVERRIDE;
28 static bool CanDo(const SkBitmap&, TileMode tx, TileMode ty);
30 SK_TO_STRING_OVERRIDE()
31 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBitmapProcShader)
34 bool asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix*, GrColor*,
35 GrFragmentProcessor**)
38 class BitmapProcShaderContext : public SkShader::Context {
40 // The context takes ownership of the state. It will call its destructor
41 // but will NOT free the memory.
42 BitmapProcShaderContext(const SkBitmapProcShader&, const ContextRec&, SkBitmapProcState*);
43 virtual ~BitmapProcShaderContext();
45 virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) SK_OVERRIDE;
46 virtual ShadeProc asAShadeProc(void** ctx) SK_OVERRIDE;
47 virtual void shadeSpan16(int x, int y, uint16_t dstC[], int count) SK_OVERRIDE;
49 virtual uint32_t getFlags() const SK_OVERRIDE { return fFlags; }
52 SkBitmapProcState* fState;
55 typedef SkShader::Context INHERITED;
59 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
60 SkBitmapProcShader(SkReadBuffer& );
62 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
63 virtual Context* onCreateContext(const ContextRec&, void* storage) const SK_OVERRIDE;
65 SkBitmap fRawBitmap; // experimental for RLE encoding
66 uint8_t fTileModeX, fTileModeY;
69 typedef SkShader INHERITED;
72 // Commonly used allocator. It currently is only used to allocate up to 3 objects. The total
73 // bytes requested is calculated using one of our large shaders, its context size plus the size of
74 // an Sk3DBlitter in SkDraw.cpp
75 // Note that some contexts may contain other contexts (e.g. for compose shaders), but we've not
76 // yet found a situation where the size below isn't big enough.
77 typedef SkSmallAllocator<3, 1024> SkTBlitterAllocator;
79 // If alloc is non-NULL, it will be used to allocate the returned SkShader, and MUST outlive
81 SkShader* CreateBitmapShader(const SkBitmap& src, SkShader::TileMode, SkShader::TileMode,
82 const SkMatrix* localMatrix, SkTBlitterAllocator* alloc);