Skia
2DGraphicsLibrary
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkMallocPixelRef.h
1 /*
2  * Copyright 2008 The Android Open Source Project
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 
9 #ifndef SkMallocPixelRef_DEFINED
10 #define SkMallocPixelRef_DEFINED
11 
12 #include "SkPixelRef.h"
13 
17 class SK_API SkMallocPixelRef : public SkPixelRef {
18 public:
29  static SkMallocPixelRef* NewDirect(const SkImageInfo&, void* addr,
30  size_t rowBytes, SkColorTable*);
31 
42  static SkMallocPixelRef* NewAllocate(const SkImageInfo& info,
43  size_t rowBytes, SkColorTable*);
44 
48  static SkMallocPixelRef* NewZeroed(const SkImageInfo& info,
49  size_t rowBytes, SkColorTable*);
50 
65  typedef void (*ReleaseProc)(void* addr, void* context);
66  static SkMallocPixelRef* NewWithProc(const SkImageInfo& info,
67  size_t rowBytes, SkColorTable*,
68  void* addr, ReleaseProc proc,
69  void* context);
70 
81  static SkMallocPixelRef* NewWithData(const SkImageInfo& info,
82  size_t rowBytes,
83  SkColorTable* ctable,
84  SkData* data);
85 
86  void* getAddr() const { return fStorage; }
87 
88  class PRFactory : public SkPixelRefFactory {
89  public:
90  SkPixelRef* create(const SkImageInfo&, size_t rowBytes, SkColorTable*) override;
91  };
92 
94  public:
95  SkPixelRef* create(const SkImageInfo&, size_t rowBytes, SkColorTable*) override;
96  };
97 
98 protected:
99  // The ownPixels version of this constructor is deprecated.
100  SkMallocPixelRef(const SkImageInfo&, void* addr, size_t rb, SkColorTable*,
101  bool ownPixels);
102  virtual ~SkMallocPixelRef();
103 
104  bool onNewLockPixels(LockRec*) override;
105  void onUnlockPixels() override;
106  size_t getAllocatedSizeInBytes() const override;
107 
108 private:
109  // Uses alloc to implement NewAllocate or NewZeroed.
110  static SkMallocPixelRef* NewUsing(void*(*alloc)(size_t),
111  const SkImageInfo&,
112  size_t rowBytes,
113  SkColorTable*);
114 
115  void* fStorage;
116  SkColorTable* fCTable;
117  size_t fRB;
118  ReleaseProc fReleaseProc;
119  void* fReleaseProcContext;
120 
121  SkMallocPixelRef(const SkImageInfo&, void* addr, size_t rb, SkColorTable*,
122  ReleaseProc proc, void* context);
123 
124  typedef SkPixelRef INHERITED;
125 };
126 
127 
128 #endif
Describe an image's dimensions and pixel type.
Definition: SkImageInfo.h:181
SkColorTable holds an array SkPMColors (premultiplied 32-bit colors) used by 8-bit bitmaps...
Definition: SkColorTable.h:25
virtual size_t getAllocatedSizeInBytes() const
Returns the size (in bytes) of the internally allocated memory.
Definition: SkMallocPixelRef.h:88
SkData holds an immutable data buffer.
Definition: SkData.h:22
This class is the smart container for pixel memory, and is used with SkBitmap.
Definition: SkPixelRef.h:38
virtual bool onNewLockPixels(LockRec *)=0
On success, returns true and fills out the LockRec for the pixels.
To access the actual pixels of a pixelref, it must be "locked".
Definition: SkPixelRef.h:62
Definition: SkMallocPixelRef.h:93
Definition: SkPixelRef.h:394
virtual void onUnlockPixels()=0
Balancing the previous successful call to onNewLockPixels.
We explicitly use the same allocator for our pixels that SkMask does, so that we can freely assign me...
Definition: SkMallocPixelRef.h:17