| OLD | NEW |
| 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 Loading... |
| 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 | |
| 144 private: | 136 private: |
| 145 const void* fPixels; | 137 const void* fPixels; |
| 146 SkColorTable* fCTable; | 138 SkColorTable* fCTable; |
| 147 size_t fRowBytes; | 139 size_t fRowBytes; |
| 148 SkImageInfo fInfo; | 140 SkImageInfo fInfo; |
| 149 }; | 141 }; |
| 150 | 142 |
| 151 ////////////////////////////////////////////////////////////////////////////////
///////////// | 143 ////////////////////////////////////////////////////////////////////////////////
///////////// |
| 152 | 144 |
| 153 class SkAutoPixmapStorage : public SkPixmap { | 145 class SkAutoPixmapStorage : public SkPixmap { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 166 | 158 |
| 167 /** | 159 /** |
| 168 * Allocate memory for the pixels needed to match the specified Info and fi
ll out the pixmap | 160 * Allocate memory for the pixels needed to match the specified Info and fi
ll out the pixmap |
| 169 * to point to that memory. The storage will be freed when this object is d
estroyed, | 161 * to point to that memory. The storage will be freed when this object is d
estroyed, |
| 170 * or if another call to tryAlloc() or alloc() is made. | 162 * or if another call to tryAlloc() or alloc() is made. |
| 171 * | 163 * |
| 172 * If the memory cannot be allocated, calls sk_throw(). | 164 * If the memory cannot be allocated, calls sk_throw(). |
| 173 */ | 165 */ |
| 174 void alloc(const SkImageInfo&); | 166 void alloc(const SkImageInfo&); |
| 175 | 167 |
| 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 | |
| 195 private: | 168 private: |
| 196 void* fStorage; | 169 void* fStorage; |
| 197 | |
| 198 void freeStorage() { | |
| 199 sk_free(fStorage); | |
| 200 fStorage = NULL; | |
| 201 } | |
| 202 | |
| 203 typedef SkPixmap INHERITED; | |
| 204 }; | 170 }; |
| 205 | 171 |
| 206 ////////////////////////////////////////////////////////////////////////////////
///////////// | 172 ////////////////////////////////////////////////////////////////////////////////
///////////// |
| 207 | 173 |
| 208 class SkAutoPixmapUnlock : ::SkNoncopyable { | 174 class SkAutoPixmapUnlock : ::SkNoncopyable { |
| 209 public: | 175 public: |
| 210 SkAutoPixmapUnlock() : fUnlockProc(NULL), fIsLocked(false) {} | 176 SkAutoPixmapUnlock() : fUnlockProc(NULL), fIsLocked(false) {} |
| 211 SkAutoPixmapUnlock(const SkPixmap& pm, void (*unlock)(void*), void* ctx) | 177 SkAutoPixmapUnlock(const SkPixmap& pm, void (*unlock)(void*), void* ctx) |
| 212 : fUnlockProc(unlock), fUnlockContext(ctx), fPixmap(pm), fIsLocked(true) | 178 : fUnlockProc(unlock), fUnlockContext(ctx), fPixmap(pm), fIsLocked(true) |
| 213 {} | 179 {} |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 private: | 211 private: |
| 246 void (*fUnlockProc)(void*); | 212 void (*fUnlockProc)(void*); |
| 247 void* fUnlockContext; | 213 void* fUnlockContext; |
| 248 SkPixmap fPixmap; | 214 SkPixmap fPixmap; |
| 249 bool fIsLocked; | 215 bool fIsLocked; |
| 250 | 216 |
| 251 friend class SkBitmap; | 217 friend class SkBitmap; |
| 252 }; | 218 }; |
| 253 | 219 |
| 254 #endif | 220 #endif |
| OLD | NEW |