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

Side by Side Diff: include/core/SkPixmap.h

Issue 1162013008: add extractSubset and SkAutoPixmapStorage (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « no previous file | src/core/SkPixmap.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkPixmap_DEFINED 8 #ifndef SkPixmap_DEFINED
9 #define SkPixmap_DEFINED 9 #define SkPixmap_DEFINED
10 10
11 #include "SkImageInfo.h" 11 #include "SkImageInfo.h"
12 12
13 class SkColorTable; 13 class SkColorTable;
14 struct SkMask;
14 15
15 /** 16 /**
16 * Pairs SkImageInfo with actual pixels and rowbytes. This class does not try t o manage the 17 * Pairs SkImageInfo with actual pixels and rowbytes. This class does not try t o manage the
17 * lifetime of the pixel memory (nor the colortable if provided). 18 * lifetime of the pixel memory (nor the colortable if provided).
18 */ 19 */
19 class SkPixmap { 20 class SkPixmap {
20 public: 21 public:
21 SkPixmap() 22 SkPixmap()
22 : fPixels(NULL), fCTable(NULL), fRowBytes(0), fInfo(SkImageInfo::MakeUnk nown(0, 0)) 23 : fPixels(NULL), fCTable(NULL), fRowBytes(0), fInfo(SkImageInfo::MakeUnk nown(0, 0))
23 {} 24 {}
24 25
25 SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes, 26 SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes,
26 SkColorTable* ctable = NULL) 27 SkColorTable* ctable = NULL)
27 : fPixels(addr), fCTable(ctable), fRowBytes(rowBytes), fInfo(info) 28 : fPixels(addr), fCTable(ctable), fRowBytes(rowBytes), fInfo(info)
28 { 29 {
29 if (kIndex_8_SkColorType == info.colorType()) { 30 if (kIndex_8_SkColorType == info.colorType()) {
30 SkASSERT(ctable); 31 SkASSERT(ctable);
31 } else { 32 } else {
32 SkASSERT(NULL == ctable); 33 SkASSERT(NULL == ctable);
33 } 34 }
34 } 35 }
35 36
36 void reset(); 37 void reset();
37 void reset(const SkImageInfo& info, const void* addr, size_t rowBytes, 38 void reset(const SkImageInfo& info, const void* addr, size_t rowBytes,
38 SkColorTable* ctable = NULL); 39 SkColorTable* ctable = NULL);
40 void reset(const SkImageInfo& info) {
41 this->reset(info, NULL, 0, NULL);
42 }
43
44 /**
45 * If supported, set this pixmap to point to the pixels in the specified ma sk and return true.
46 * On failure, return false and set this pixmap to empty.
47 */
48 bool SK_WARN_UNUSED_RESULT reset(const SkMask&);
49
50 /**
51 * Computes the intersection of area and this pixmap. If that intersection is non-empty,
52 * set subset to that intersection and return true.
53 *
54 * On failure, return false and ignore the subset parameter.
55 */
56 bool SK_WARN_UNUSED_RESULT extractSubset(SkPixmap* subset, const SkIRect& ar ea) const;
39 57
40 const SkImageInfo& info() const { return fInfo; } 58 const SkImageInfo& info() const { return fInfo; }
41 size_t rowBytes() const { return fRowBytes; } 59 size_t rowBytes() const { return fRowBytes; }
42 const void* addr() const { return fPixels; } 60 const void* addr() const { return fPixels; }
43 SkColorTable* ctable() const { return fCTable; } 61 SkColorTable* ctable() const { return fCTable; }
44 62
45 int width() const { return fInfo.width(); } 63 int width() const { return fInfo.width(); }
46 int height() const { return fInfo.height(); } 64 int height() const { return fInfo.height(); }
47 SkColorType colorType() const { return fInfo.colorType(); } 65 SkColorType colorType() const { return fInfo.colorType(); }
48 SkAlphaType alphaType() const { return fInfo.alphaType(); } 66 SkAlphaType alphaType() const { return fInfo.alphaType(); }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 135
118 private: 136 private:
119 const void* fPixels; 137 const void* fPixels;
120 SkColorTable* fCTable; 138 SkColorTable* fCTable;
121 size_t fRowBytes; 139 size_t fRowBytes;
122 SkImageInfo fInfo; 140 SkImageInfo fInfo;
123 }; 141 };
124 142
125 //////////////////////////////////////////////////////////////////////////////// ///////////// 143 //////////////////////////////////////////////////////////////////////////////// /////////////
126 144
145 class SkAutoPixmapStorage : public SkPixmap {
146 public:
147 SkAutoPixmapStorage();
148 ~SkAutoPixmapStorage();
149
150 /**
151 * Try to allocate memory for the pixels needed to match the specified Info . On success
152 * return true and fill out the pixmap to point to that memory. The storage will be freed
153 * when this object is destroyed, or if another call to tryAlloc() or alloc () is made.
154 *
155 * On failure, return false and reset() the pixmap to empty.
156 */
157 bool tryAlloc(const SkImageInfo&);
158
159 /**
160 * Allocate memory for the pixels needed to match the specified Info and fi ll out the pixmap
161 * to point to that memory. The storage will be freed when this object is d estroyed,
162 * or if another call to tryAlloc() or alloc() is made.
163 *
164 * If the memory cannot be allocated, calls sk_throw().
165 */
166 void alloc(const SkImageInfo&);
167
168 private:
169 void* fStorage;
170 };
171
172 //////////////////////////////////////////////////////////////////////////////// /////////////
173
127 class SkAutoPixmapUnlock : ::SkNoncopyable { 174 class SkAutoPixmapUnlock : ::SkNoncopyable {
128 public: 175 public:
129 SkAutoPixmapUnlock() : fUnlockProc(NULL), fIsLocked(false) {} 176 SkAutoPixmapUnlock() : fUnlockProc(NULL), fIsLocked(false) {}
130 SkAutoPixmapUnlock(const SkPixmap& pm, void (*unlock)(void*), void* ctx) 177 SkAutoPixmapUnlock(const SkPixmap& pm, void (*unlock)(void*), void* ctx)
131 : fUnlockProc(unlock), fUnlockContext(ctx), fPixmap(pm), fIsLocked(true) 178 : fUnlockProc(unlock), fUnlockContext(ctx), fPixmap(pm), fIsLocked(true)
132 {} 179 {}
133 ~SkAutoPixmapUnlock() { this->unlock(); } 180 ~SkAutoPixmapUnlock() { this->unlock(); }
134 181
135 /** 182 /**
136 * Return the currently locked pixmap. Undefined if it has been unlocked. 183 * Return the currently locked pixmap. Undefined if it has been unlocked.
(...skipping 27 matching lines...) Expand all
164 private: 211 private:
165 void (*fUnlockProc)(void*); 212 void (*fUnlockProc)(void*);
166 void* fUnlockContext; 213 void* fUnlockContext;
167 SkPixmap fPixmap; 214 SkPixmap fPixmap;
168 bool fIsLocked; 215 bool fIsLocked;
169 216
170 friend class SkBitmap; 217 friend class SkBitmap;
171 }; 218 };
172 219
173 #endif 220 #endif
OLDNEW
« no previous file with comments | « no previous file | src/core/SkPixmap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698