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

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

Issue 108723003: Revert "Revert "PixelRef now returns (nearly) everything that is currently in SkBitmap. The goal is… (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: fix warnings, update SkImageRef_ashmem Created 7 years 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
« no previous file with comments | « include/core/SkImageInfo.h ('k') | include/core/SkPicture.h » ('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 /* 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 SkMallocPixelRef_DEFINED 10 #ifndef SkMallocPixelRef_DEFINED
11 #define SkMallocPixelRef_DEFINED 11 #define SkMallocPixelRef_DEFINED
12 12
13 #include "SkPixelRef.h" 13 #include "SkPixelRef.h"
14 14
15 /** We explicitly use the same allocator for our pixels that SkMask does, 15 /** We explicitly use the same allocator for our pixels that SkMask does,
16 so that we can freely assign memory allocated by one class to the other. 16 so that we can freely assign memory allocated by one class to the other.
17 */ 17 */
18 class SkMallocPixelRef : public SkPixelRef { 18 class SkMallocPixelRef : public SkPixelRef {
19 public: 19 public:
20 /** Allocate the specified buffer for pixels. The memory is freed when the 20 /**
21 last owner of this pixelref is gone. If addr is NULL, sk_malloc_throw() 21 * Return a new SkMallocPixelRef with the provided pixel storage, rowBytes,
22 is called to allocate it. 22 * and optional colortable. The caller is responsible for managing the
23 * lifetime of the pixel storage buffer, as the pixelref will not try
24 * to delete the storage.
25 *
26 * This pixelref will ref() the specified colortable (if not NULL).
27 *
28 * Returns NULL on failure.
23 */ 29 */
24 SkMallocPixelRef(void* addr, size_t size, SkColorTable* ctable, bool ownPixe ls = true); 30 static SkMallocPixelRef* NewDirect(const SkImageInfo&, void* addr,
25 virtual ~SkMallocPixelRef(); 31 size_t rowBytes, SkColorTable*);
32
33 /**
34 * Return a new SkMallocPixelRef, automatically allocating storage for the
35 * pixels. If rowBytes are 0, an optimal value will be chosen automatically .
36 * If rowBytes is > 0, then it will be respected, or NULL will be returned
37 * if rowBytes is invalid for the specified info.
38 *
39 * This pixelref will ref() the specified colortable (if not NULL).
40 *
41 * Returns NULL on failure.
42 */
43 static SkMallocPixelRef* NewAllocate(const SkImageInfo& info,
44 size_t rowBytes, SkColorTable*);
26 45
27 void* getAddr() const { return fStorage; } 46 void* getAddr() const { return fStorage; }
28 47
29 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMallocPixelRef) 48 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMallocPixelRef)
30 49
31 protected: 50 protected:
32 // overrides from SkPixelRef 51 virtual bool onNewLockPixels(LockRec*) SK_OVERRIDE;
33 virtual void* onLockPixels(SkColorTable**); 52 virtual void onUnlockPixels() SK_OVERRIDE;
34 virtual void onUnlockPixels(); 53 virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
54 virtual size_t getAllocatedSizeInBytes() const SK_OVERRIDE;
35 55
36 SkMallocPixelRef(SkFlattenableReadBuffer& buffer); 56 SkMallocPixelRef(SkFlattenableReadBuffer& buffer);
37 virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE; 57 SkMallocPixelRef(const SkImageInfo&, void* addr, size_t rb, SkColorTable*,
38 58 bool ownsPixels);
39 // Returns the allocation size for the pixels 59 virtual ~SkMallocPixelRef();
40 virtual size_t getAllocatedSizeInBytes() const SK_OVERRIDE { return fSize; }
41 60
42 private: 61 private:
43 void* fStorage; 62 void* fStorage;
44 size_t fSize; 63 SkColorTable* fCTable;
45 SkColorTable* fCTable; 64 size_t fRB;
46 bool fOwnPixels; 65 const bool fOwnPixels;
47 66
48 typedef SkPixelRef INHERITED; 67 typedef SkPixelRef INHERITED;
49 }; 68 };
50 69
51 70
52 #endif 71 #endif
OLDNEW
« no previous file with comments | « include/core/SkImageInfo.h ('k') | include/core/SkPicture.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698