Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Side by Side Diff: src/core/SkBitmapProcShader.h

Issue 207683004: Extract most of the mutable state of SkShader into a separate Context object. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Remove SkBitmapProcState copy constructor and use pointer instead; nits. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #ifndef SkBitmapProcShader_DEFINED 10 #ifndef SkBitmapProcShader_DEFINED
11 #define SkBitmapProcShader_DEFINED 11 #define SkBitmapProcShader_DEFINED
12 12
13 #include "SkShader.h" 13 #include "SkShader.h"
14 #include "SkBitmapProcState.h" 14 #include "SkBitmapProcState.h"
15 #include "SkSmallAllocator.h" 15 #include "SkSmallAllocator.h"
16 16
17 class SkBitmapProcShader : public SkShader { 17 class SkBitmapProcShader : public SkShader {
18 public: 18 public:
19 SkBitmapProcShader(const SkBitmap& src, TileMode tx, TileMode ty); 19 SkBitmapProcShader(const SkBitmap& src, TileMode tx, TileMode ty);
20 20
21 // overrides from SkShader 21 // overrides from SkShader
22 virtual bool isOpaque() const SK_OVERRIDE; 22 virtual bool isOpaque() const SK_OVERRIDE;
23 virtual bool setContext(const SkBitmap&, const SkPaint&, const SkMatrix&) SK _OVERRIDE;
24 virtual void endContext() SK_OVERRIDE;
25 virtual uint32_t getFlags() SK_OVERRIDE { return fFlags; }
26 virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) SK_OVERRID E;
27 virtual ShadeProc asAShadeProc(void** ctx) SK_OVERRIDE;
28 virtual void shadeSpan16(int x, int y, uint16_t dstC[], int count) SK_OVERRI DE;
29 virtual BitmapType asABitmap(SkBitmap*, SkMatrix*, TileMode*) const SK_OVERR IDE; 23 virtual BitmapType asABitmap(SkBitmap*, SkMatrix*, TileMode*) const SK_OVERR IDE;
30 24
25 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) con st SK_OVERRIDE;
31 virtual size_t contextSize() const SK_OVERRIDE;
32
31 static bool CanDo(const SkBitmap&, TileMode tx, TileMode ty); 33 static bool CanDo(const SkBitmap&, TileMode tx, TileMode ty);
32 34
33 SK_DEVELOPER_TO_STRING() 35 SK_DEVELOPER_TO_STRING()
34 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBitmapProcShader) 36 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBitmapProcShader)
35 37
36 #if SK_SUPPORT_GPU 38 #if SK_SUPPORT_GPU
37 GrEffectRef* asNewEffect(GrContext*, const SkPaint&) const SK_OVERRIDE; 39 GrEffectRef* asNewEffect(GrContext*, const SkPaint&) const SK_OVERRIDE;
38 #endif 40 #endif
39 41
42 class BitmapProcShaderContext : public SkShader::Context {
43 public:
44 // The context takes ownership of the state.
scroggo 2014/04/01 18:02:41 This could use some elaboration - it will call the
Dominik Grewe 2014/04/02 18:00:48 I've extended the comment for now. If we passed a
scroggo 2014/04/02 20:16:52 I think so. We might have some examples of such a
Dominik Grewe 2014/04/03 12:12:59 On the other hand, we shouldn't create any context
scroggo 2014/04/03 15:35:54 I think that makes a lot of sense.
45 BitmapProcShaderContext(const SkBitmapProcShader& shader,
46 const SkBitmap& device,
47 const SkPaint& paint,
48 const SkMatrix& matrix,
49 SkBitmapProcState* state);
50 virtual ~BitmapProcShaderContext();
51
52 virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) SK_OVE RRIDE;
53 virtual ShadeProc asAShadeProc(void** ctx) SK_OVERRIDE;
54 virtual void shadeSpan16(int x, int y, uint16_t dstC[], int count) SK_OV ERRIDE;
55
56 virtual uint32_t getFlags() const SK_OVERRIDE { return fFlags; }
57 private:
58 SkBitmapProcState* fState;
59 uint32_t fFlags;
60
61 typedef SkShader::Context INHERITED;
62 };
63
40 protected: 64 protected:
41 SkBitmapProcShader(SkReadBuffer& ); 65 SkBitmapProcShader(SkReadBuffer& );
42 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; 66 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
43 67
44 SkBitmap fRawBitmap; // experimental for RLE encoding 68 SkBitmap fRawBitmap; // experimental for RLE encoding
45 SkBitmapProcState fState; 69 uint8_t fTileModeX, fTileModeY;
46 uint32_t fFlags;
47 70
48 private: 71 private:
72 bool validInternal(const SkBitmap& device, const SkPaint& paint,
73 const SkMatrix& matrix, SkMatrix* totalInverse,
74 SkBitmapProcState* state) const;
75
49 typedef SkShader INHERITED; 76 typedef SkShader INHERITED;
50 }; 77 };
51 78
52 // Commonly used allocator. It currently is only used to allocate up to 2 object s. The total 79 // Commonly used allocator. It currently is only used to allocate up to 3 object s. The total
53 // bytes requested is calculated using one of our large shaders plus the size of an Sk3DBlitter 80 // bytes requested is calculated using one of our large shaders, its context (co ntext size
54 // in SkDraw.cpp 81 // is multiplied by 3 because contexts can reference other contexts) plus the si ze of
55 typedef SkSmallAllocator<2, sizeof(SkBitmapProcShader) + sizeof(void*) * 2> SkTB litterAllocator; 82 // an Sk3DBlitter in SkDraw.cpp
83 typedef SkSmallAllocator<3, sizeof(SkBitmapProcShader) +
scroggo 2014/04/01 18:02:41 Won't this need to be 4 to account for the SkBitma
scroggo 2014/04/02 16:03:14 My mistake; you put the SkBitmapProcState in with
Dominik Grewe 2014/04/02 18:00:48 We don't have access to the SkSmallAllocator when
scroggo 2014/04/02 20:16:52 Ah, of course. Nvm.
84 3 * sizeof(SkBitmapProcShader::BitmapProcShaderConte xt) +
85 sizeof(SkBitmapProcState) +
86 sizeof(void*) * 2> SkTBlitterAllocator;
56 87
57 // If alloc is non-NULL, it will be used to allocate the returned SkShader, and MUST outlive 88 // If alloc is non-NULL, it will be used to allocate the returned SkShader, and MUST outlive
58 // the SkShader. 89 // the SkShader.
59 SkShader* CreateBitmapShader(const SkBitmap& src, SkShader::TileMode, SkShader:: TileMode, 90 SkShader* CreateBitmapShader(const SkBitmap& src, SkShader::TileMode, SkShader:: TileMode,
60 SkTBlitterAllocator* alloc); 91 SkTBlitterAllocator* alloc);
61 92
62 #endif 93 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698