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

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

Issue 68973005: Expand pixelref to return SkImageInfo and rowbytes (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2008 The Android Open Source Project 3 * Copyright 2008 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 SkPixelRef_DEFINED 10 #ifndef SkPixelRef_DEFINED
11 #define SkPixelRef_DEFINED 11 #define SkPixelRef_DEFINED
12 12
13 #include "SkBitmap.h" 13 #include "SkBitmap.h"
14 #include "SkRefCnt.h" 14 #include "SkRefCnt.h"
15 #include "SkString.h" 15 #include "SkString.h"
16 #include "SkFlattenable.h" 16 #include "SkFlattenable.h"
17 #include "SkImageInfo.h"
17 #include "SkTDArray.h" 18 #include "SkTDArray.h"
18 19
19 #ifdef SK_DEBUG 20 #ifdef SK_DEBUG
20 /** 21 /**
21 * Defining SK_IGNORE_PIXELREF_SETPRELOCKED will force all pixelref 22 * Defining SK_IGNORE_PIXELREF_SETPRELOCKED will force all pixelref
22 * subclasses to correctly handle lock/unlock pixels. For performance 23 * subclasses to correctly handle lock/unlock pixels. For performance
23 * reasons, simple malloc-based subclasses call setPreLocked() to skip 24 * reasons, simple malloc-based subclasses call setPreLocked() to skip
24 * the overhead of implementing these calls. 25 * the overhead of implementing these calls.
25 * 26 *
26 * This build-flag disables that optimization, to add in debugging our 27 * This build-flag disables that optimization, to add in debugging our
(...skipping 18 matching lines...) Expand all
45 46
46 This class can be shared/accessed between multiple threads. 47 This class can be shared/accessed between multiple threads.
47 */ 48 */
48 class SK_API SkPixelRef : public SkFlattenable { 49 class SK_API SkPixelRef : public SkFlattenable {
49 public: 50 public:
50 SK_DECLARE_INST_COUNT(SkPixelRef) 51 SK_DECLARE_INST_COUNT(SkPixelRef)
51 52
52 explicit SkPixelRef(SkBaseMutex* mutex = NULL); 53 explicit SkPixelRef(SkBaseMutex* mutex = NULL);
53 virtual ~SkPixelRef(); 54 virtual ~SkPixelRef();
54 55
56 /**
57 * Return the data's rowbytes. Will be 0 if the the lockCount is 0.
58 */
59 size_t rowBytes() const { return fRowBytes; }
60
55 /** Return the pixel memory returned from lockPixels, or null if the 61 /** Return the pixel memory returned from lockPixels, or null if the
56 lockCount is 0. 62 lockCount is 0.
57 */ 63 */
58 void* pixels() const { return fPixels; } 64 void* pixels() const { return fPixels; }
59 65
60 /** Return the current colorTable (if any) if pixels are locked, or null. 66 /** Return the current colorTable (if any) if pixels are locked, or null.
61 */ 67 */
62 SkColorTable* colorTable() const { return fColorTable; } 68 SkColorTable* colorTable() const { return fColorTable; }
63 69
64 /** 70 /**
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 virtual void onChange() = 0; 230 virtual void onChange() = 0;
225 }; 231 };
226 232
227 // Takes ownership of listener. 233 // Takes ownership of listener.
228 void addGenIDChangeListener(GenIDChangeListener* listener); 234 void addGenIDChangeListener(GenIDChangeListener* listener);
229 235
230 protected: 236 protected:
231 /** Called when the lockCount goes from 0 to 1. The caller will have already 237 /** Called when the lockCount goes from 0 to 1. The caller will have already
232 acquire a mutex for thread safety, so this method need not do that. 238 acquire a mutex for thread safety, so this method need not do that.
233 */ 239 */
234 virtual void* onLockPixels(SkColorTable**) = 0; 240 virtual void* onLockPixels(SkImageInfo*, size_t* rowBytes, SkColorTable**) = 0;
scroggo 2013/11/19 18:17:09 Comments explaining the parameters would be nice.
235 /** Called when the lock count goes from 1 to 0. The caller will have 241 /** Called when the lock count goes from 1 to 0. The caller will have
236 already acquire a mutex for thread safety, so this method need not do 242 already acquire a mutex for thread safety, so this method need not do
237 that. 243 that.
238 */ 244 */
239 virtual void onUnlockPixels() = 0; 245 virtual void onUnlockPixels() = 0;
240 246
241 /** Default impl returns true */ 247 /** Default impl returns true */
242 virtual bool onLockPixelsAreWritable() const; 248 virtual bool onLockPixelsAreWritable() const;
243 249
244 // returns false; 250 // returns false;
(...skipping 17 matching lines...) Expand all
262 */ 268 */
263 SkBaseMutex* mutex() const { return fMutex; } 269 SkBaseMutex* mutex() const { return fMutex; }
264 270
265 // serialization 271 // serialization
266 SkPixelRef(SkFlattenableReadBuffer&, SkBaseMutex*); 272 SkPixelRef(SkFlattenableReadBuffer&, SkBaseMutex*);
267 virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE; 273 virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
268 274
269 // only call from constructor. Flags this to always be locked, removing 275 // only call from constructor. Flags this to always be locked, removing
270 // the need to grab the mutex and call onLockPixels/onUnlockPixels. 276 // the need to grab the mutex and call onLockPixels/onUnlockPixels.
271 // Performance tweak to avoid those calls (esp. in multi-thread use case). 277 // Performance tweak to avoid those calls (esp. in multi-thread use case).
272 void setPreLocked(void* pixels, SkColorTable* ctable); 278 void setPreLocked(void* pixels, size_t rowBytes, SkColorTable* ctable);
273 279
274 private: 280 private:
275 SkBaseMutex* fMutex; // must remain in scope for the life of this object 281 SkBaseMutex* fMutex; // must remain in scope for the life of this object
276 void* fPixels; 282 void* fPixels;
277 SkColorTable* fColorTable; // we do not track ownership, subclass does 283 SkColorTable* fColorTable; // we do not track ownership, subclass does
284 size_t fRowBytes;
278 int fLockCount; 285 int fLockCount;
279 286
280 mutable uint32_t fGenerationID; 287 mutable uint32_t fGenerationID;
281 mutable bool fUniqueGenerationID; 288 mutable bool fUniqueGenerationID;
282 289
283 SkTDArray<GenIDChangeListener*> fGenIDChangeListeners; // pointers are owne d 290 SkTDArray<GenIDChangeListener*> fGenIDChangeListeners; // pointers are owne d
284 291
285 SkString fURI; 292 SkString fURI;
286 293
287 // can go from false to true, but never from true to false 294 // can go from false to true, but never from true to false
288 bool fIsImmutable; 295 bool fIsImmutable;
289 // only ever set in constructor, const after that 296 // only ever set in constructor, const after that
290 bool fPreLocked; 297 bool fPreLocked;
291 298
292 void needsNewGenID(); 299 void needsNewGenID();
293 void callGenIDChangeListeners(); 300 void callGenIDChangeListeners();
294 301
295 void setMutex(SkBaseMutex* mutex); 302 void setMutex(SkBaseMutex* mutex);
296 303
297 // When copying a bitmap to another with the same shape and config, we can s afely 304 // When copying a bitmap to another with the same shape and config, we can s afely
298 // clone the pixelref generation ID too, which makes them equivalent under c aching. 305 // clone the pixelref generation ID too, which makes them equivalent under c aching.
299 friend class SkBitmap; // only for cloneGenID 306 friend class SkBitmap; // only for cloneGenID
300 void cloneGenID(const SkPixelRef&); 307 void cloneGenID(const SkPixelRef&);
301 308
302 typedef SkFlattenable INHERITED; 309 typedef SkFlattenable INHERITED;
303 }; 310 };
304 311
305 #endif 312 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698