blob: e0c78b8e455a75425d32c7bbe76c839948f5fa95 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2006 The Android Open Source Project
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
reed@android.com8a1c16f2008-12-17 15:59:43 +00009
10#ifndef SkBitmapProcShader_DEFINED
11#define SkBitmapProcShader_DEFINED
12
13#include "SkShader.h"
14#include "SkBitmapProcState.h"
commit-bot@chromium.orga5572e52014-03-07 03:24:41 +000015#include "SkSmallAllocator.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000016
17class SkBitmapProcShader : public SkShader {
18public:
19 SkBitmapProcShader(const SkBitmap& src, TileMode tx, TileMode ty);
20
21 // overrides from SkShader
junov@chromium.orgb6e16192011-12-09 15:48:03 +000022 virtual bool isOpaque() const SK_OVERRIDE;
robertphillips@google.com76f9e932013-01-15 20:17:47 +000023 virtual BitmapType asABitmap(SkBitmap*, SkMatrix*, TileMode*) const SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000024
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000025 virtual bool validContext(const SkBitmap& device,
26 const SkPaint& paint,
27 const SkMatrix& matrix,
28 SkMatrix* totalInverse = NULL) const SK_OVERRIDE;
29 virtual SkShader::Context* createContext(const SkBitmap&, const SkPaint&,
30 const SkMatrix&, void* storage) const SK_OVERRIDE;
31 virtual size_t contextSize() const SK_OVERRIDE;
32
reed@android.com8a1c16f2008-12-17 15:59:43 +000033 static bool CanDo(const SkBitmap&, TileMode tx, TileMode ty);
skia.committer@gmail.comff21c2e2013-01-16 07:05:56 +000034
commit-bot@chromium.org0f10f7b2014-03-13 18:02:17 +000035 SK_TO_STRING_OVERRIDE()
djsollen@google.comba28d032012-03-26 17:57:35 +000036 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBitmapProcShader)
reed@android.com8a1c16f2008-12-17 15:59:43 +000037
bsalomon@google.come197cbf2013-01-14 16:46:26 +000038#if SK_SUPPORT_GPU
bsalomon@google.com0ac6af42013-01-16 15:16:18 +000039 GrEffectRef* asNewEffect(GrContext*, const SkPaint&) const SK_OVERRIDE;
bsalomon@google.come197cbf2013-01-14 16:46:26 +000040#endif
41
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000042 class BitmapProcShaderContext : public SkShader::Context {
43 public:
44 // The context takes ownership of the state. It will call its destructor
45 // but will NOT free the memory.
46 BitmapProcShaderContext(const SkBitmapProcShader& shader,
47 const SkBitmap& device,
48 const SkPaint& paint,
49 const SkMatrix& matrix,
50 SkBitmapProcState* state);
51 virtual ~BitmapProcShaderContext();
52
53 virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) SK_OVERRIDE;
54 virtual ShadeProc asAShadeProc(void** ctx) SK_OVERRIDE;
55 virtual void shadeSpan16(int x, int y, uint16_t dstC[], int count) SK_OVERRIDE;
56
57 virtual uint32_t getFlags() const SK_OVERRIDE { return fFlags; }
58
59 private:
60 SkBitmapProcState* fState;
61 uint32_t fFlags;
62
63 typedef SkShader::Context INHERITED;
64 };
65
reed@android.com8a1c16f2008-12-17 15:59:43 +000066protected:
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +000067 SkBitmapProcShader(SkReadBuffer& );
68 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000069
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000070 SkBitmap fRawBitmap; // experimental for RLE encoding
71 uint8_t fTileModeX, fTileModeY;
reed@android.com8a1c16f2008-12-17 15:59:43 +000072
reed@google.com7c2f27d2011-03-07 19:29:00 +000073private:
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000074 bool validInternal(const SkBitmap& device, const SkPaint& paint,
75 const SkMatrix& matrix, SkMatrix* totalInverse,
76 SkBitmapProcState* state) const;
77
reed@android.com8a1c16f2008-12-17 15:59:43 +000078 typedef SkShader INHERITED;
79};
80
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000081// Commonly used allocator. It currently is only used to allocate up to 3 objects. The total
82// bytes requested is calculated using one of our large shaders, its context size plus the size of
83// an Sk3DBlitter in SkDraw.cpp
84// Note that some contexts may contain other contexts (e.g. for compose shaders), but we've not
85// yet found a situation where the size below isn't big enough.
86typedef SkSmallAllocator<3, sizeof(SkBitmapProcShader) +
87 sizeof(SkBitmapProcShader::BitmapProcShaderContext) +
88 sizeof(SkBitmapProcState) +
89 sizeof(void*) * 2> SkTBlitterAllocator;
commit-bot@chromium.orga5572e52014-03-07 03:24:41 +000090
91// If alloc is non-NULL, it will be used to allocate the returned SkShader, and MUST outlive
92// the SkShader.
93SkShader* CreateBitmapShader(const SkBitmap& src, SkShader::TileMode, SkShader::TileMode,
94 SkTBlitterAllocator* alloc);
95
reed@android.com8a1c16f2008-12-17 15:59:43 +000096#endif