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

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

Issue 1161033005: move erase into SkPixmap (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 | « include/core/SkBitmap.h ('k') | src/core/SkBitmap.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
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBy tes) const { 126 bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBy tes) const {
127 return this->readPixels(dstInfo, dstPixels, dstRowBytes, 0, 0); 127 return this->readPixels(dstInfo, dstPixels, dstRowBytes, 0, 0);
128 } 128 }
129 bool readPixels(const SkPixmap& dst, int srcX, int srcY) const { 129 bool readPixels(const SkPixmap& dst, int srcX, int srcY) const {
130 return this->readPixels(dst.info(), dst.writable_addr(), dst.rowBytes(), srcX, srcY); 130 return this->readPixels(dst.info(), dst.writable_addr(), dst.rowBytes(), srcX, srcY);
131 } 131 }
132 bool readPixels(const SkPixmap& dst) const { 132 bool readPixels(const SkPixmap& dst) const {
133 return this->readPixels(dst.info(), dst.writable_addr(), dst.rowBytes(), 0, 0); 133 return this->readPixels(dst.info(), dst.writable_addr(), dst.rowBytes(), 0, 0);
134 } 134 }
135 135
136 /**
137 * Returns true if pixels were written to (e.g. if colorType is kUnknown_Sk ColorType, this
138 * will return false). If subset does not intersect the bounds of this pixm ap, returns false.
139 */
140 bool erase(SkColor, const SkIRect& subset) const;
141
142 bool erase(SkColor color) const { return this->erase(color, this->bounds()); }
143
136 private: 144 private:
137 const void* fPixels; 145 const void* fPixels;
138 SkColorTable* fCTable; 146 SkColorTable* fCTable;
139 size_t fRowBytes; 147 size_t fRowBytes;
140 SkImageInfo fInfo; 148 SkImageInfo fInfo;
141 }; 149 };
142 150
143 //////////////////////////////////////////////////////////////////////////////// ///////////// 151 //////////////////////////////////////////////////////////////////////////////// /////////////
144 152
145 class SkAutoPixmapStorage : public SkPixmap { 153 class SkAutoPixmapStorage : public SkPixmap {
(...skipping 12 matching lines...) Expand all
158 166
159 /** 167 /**
160 * Allocate memory for the pixels needed to match the specified Info and fi ll out the pixmap 168 * 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, 169 * 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. 170 * or if another call to tryAlloc() or alloc() is made.
163 * 171 *
164 * If the memory cannot be allocated, calls sk_throw(). 172 * If the memory cannot be allocated, calls sk_throw().
165 */ 173 */
166 void alloc(const SkImageInfo&); 174 void alloc(const SkImageInfo&);
167 175
176 // We wrap these so we can clear our internal storage
177
178 void reset() {
179 this->freeStorage();
180 this->INHERITED::reset();
181 }
182 void reset(const SkImageInfo& info, const void* addr, size_t rb, SkColorTabl e* ctable = NULL) {
183 this->freeStorage();
184 this->INHERITED::reset(info, addr, rb, ctable);
185 }
186 void reset(const SkImageInfo& info) {
187 this->freeStorage();
188 this->INHERITED::reset(info);
189 }
190 bool SK_WARN_UNUSED_RESULT reset(const SkMask& mask) {
191 this->freeStorage();
192 return this->INHERITED::reset(mask);
193 }
194
168 private: 195 private:
169 void* fStorage; 196 void* fStorage;
197
198 void freeStorage() {
199 sk_free(fStorage);
200 fStorage = NULL;
201 }
202
203 typedef SkPixmap INHERITED;
170 }; 204 };
171 205
172 //////////////////////////////////////////////////////////////////////////////// ///////////// 206 //////////////////////////////////////////////////////////////////////////////// /////////////
173 207
174 class SkAutoPixmapUnlock : ::SkNoncopyable { 208 class SkAutoPixmapUnlock : ::SkNoncopyable {
175 public: 209 public:
176 SkAutoPixmapUnlock() : fUnlockProc(NULL), fIsLocked(false) {} 210 SkAutoPixmapUnlock() : fUnlockProc(NULL), fIsLocked(false) {}
177 SkAutoPixmapUnlock(const SkPixmap& pm, void (*unlock)(void*), void* ctx) 211 SkAutoPixmapUnlock(const SkPixmap& pm, void (*unlock)(void*), void* ctx)
178 : fUnlockProc(unlock), fUnlockContext(ctx), fPixmap(pm), fIsLocked(true) 212 : fUnlockProc(unlock), fUnlockContext(ctx), fPixmap(pm), fIsLocked(true)
179 {} 213 {}
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 private: 245 private:
212 void (*fUnlockProc)(void*); 246 void (*fUnlockProc)(void*);
213 void* fUnlockContext; 247 void* fUnlockContext;
214 SkPixmap fPixmap; 248 SkPixmap fPixmap;
215 bool fIsLocked; 249 bool fIsLocked;
216 250
217 friend class SkBitmap; 251 friend class SkBitmap;
218 }; 252 };
219 253
220 #endif 254 #endif
OLDNEW
« no previous file with comments | « include/core/SkBitmap.h ('k') | src/core/SkBitmap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698