blob: d293c50303f505029130ed5accee0b6080ec54ad [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:
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +000019 SkBitmapProcShader(const SkBitmap& src, TileMode tx, TileMode ty,
20 const SkMatrix* localMatrix = NULL);
reed@android.com8a1c16f2008-12-17 15:59:43 +000021
22 // overrides from SkShader
junov@chromium.orgb6e16192011-12-09 15:48:03 +000023 virtual bool isOpaque() const SK_OVERRIDE;
robertphillips@google.com76f9e932013-01-15 20:17:47 +000024 virtual BitmapType asABitmap(SkBitmap*, SkMatrix*, TileMode*) const SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000025
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000026 virtual size_t contextSize() const SK_OVERRIDE;
27
reed@android.com8a1c16f2008-12-17 15:59:43 +000028 static bool CanDo(const SkBitmap&, TileMode tx, TileMode ty);
skia.committer@gmail.comff21c2e2013-01-16 07:05:56 +000029
commit-bot@chromium.org0f10f7b2014-03-13 18:02:17 +000030 SK_TO_STRING_OVERRIDE()
djsollen@google.comba28d032012-03-26 17:57:35 +000031 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBitmapProcShader)
reed@android.com8a1c16f2008-12-17 15:59:43 +000032
dandov9de5b512014-06-10 14:38:28 -070033
bsalomon97b9ab72014-07-08 06:52:35 -070034 bool asNewEffect(GrContext*, const SkPaint&, const SkMatrix*, GrColor*, GrEffect**)
dandov9de5b512014-06-10 14:38:28 -070035 const SK_OVERRIDE;
bsalomon@google.come197cbf2013-01-14 16:46:26 +000036
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000037 class BitmapProcShaderContext : public SkShader::Context {
38 public:
39 // The context takes ownership of the state. It will call its destructor
40 // but will NOT free the memory.
commit-bot@chromium.orge901b6d2014-05-01 19:31:31 +000041 BitmapProcShaderContext(const SkBitmapProcShader&, const ContextRec&, SkBitmapProcState*);
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000042 virtual ~BitmapProcShaderContext();
43
44 virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) SK_OVERRIDE;
45 virtual ShadeProc asAShadeProc(void** ctx) SK_OVERRIDE;
46 virtual void shadeSpan16(int x, int y, uint16_t dstC[], int count) SK_OVERRIDE;
47
48 virtual uint32_t getFlags() const SK_OVERRIDE { return fFlags; }
49
50 private:
51 SkBitmapProcState* fState;
52 uint32_t fFlags;
53
54 typedef SkShader::Context INHERITED;
55 };
56
reed@android.com8a1c16f2008-12-17 15:59:43 +000057protected:
reed9fa60da2014-08-21 07:59:51 -070058#ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +000059 SkBitmapProcShader(SkReadBuffer& );
reed9fa60da2014-08-21 07:59:51 -070060#endif
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +000061 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
commit-bot@chromium.orgce56d962014-05-05 18:39:18 +000062 virtual Context* onCreateContext(const ContextRec&, void* storage) const SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000063
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000064 SkBitmap fRawBitmap; // experimental for RLE encoding
65 uint8_t fTileModeX, fTileModeY;
reed@android.com8a1c16f2008-12-17 15:59:43 +000066
reed@google.com7c2f27d2011-03-07 19:29:00 +000067private:
reed@android.com8a1c16f2008-12-17 15:59:43 +000068 typedef SkShader INHERITED;
69};
70
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000071// Commonly used allocator. It currently is only used to allocate up to 3 objects. The total
72// bytes requested is calculated using one of our large shaders, its context size plus the size of
73// an Sk3DBlitter in SkDraw.cpp
74// Note that some contexts may contain other contexts (e.g. for compose shaders), but we've not
75// yet found a situation where the size below isn't big enough.
reedcc0e3112014-09-10 10:20:24 -070076typedef SkSmallAllocator<3, 1024> SkTBlitterAllocator;
commit-bot@chromium.orga5572e52014-03-07 03:24:41 +000077
78// If alloc is non-NULL, it will be used to allocate the returned SkShader, and MUST outlive
79// the SkShader.
80SkShader* CreateBitmapShader(const SkBitmap& src, SkShader::TileMode, SkShader::TileMode,
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +000081 const SkMatrix* localMatrix, SkTBlitterAllocator* alloc);
commit-bot@chromium.orga5572e52014-03-07 03:24:41 +000082
reed@android.com8a1c16f2008-12-17 15:59:43 +000083#endif