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

Side by Side Diff: src/lazy/SkDiscardablePixelRef.h

Issue 111713002: Sk_API for SkImageGenerator and SkInstallDiscardablePixelRef (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase 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 | « src/images/SkDecodingImageGenerator.cpp ('k') | src/lazy/SkDiscardablePixelRef.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 2013 Google Inc. 2 * Copyright 2013 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 SkDiscardablePixelRef_DEFINED 8 #ifndef SkDiscardablePixelRef_DEFINED
9 #define SkDiscardablePixelRef_DEFINED 9 #define SkDiscardablePixelRef_DEFINED
10 10
11 #include "SkDiscardableMemory.h" 11 #include "SkDiscardableMemory.h"
12 #include "SkPixelRef.h"
13 #include "SkImageGenerator.h" 12 #include "SkImageGenerator.h"
14 #include "SkImageInfo.h" 13 #include "SkImageInfo.h"
15 14 #include "SkPixelRef.h"
16 /**
17 * An interface that allows a purgable PixelRef to re-decode an image.
18 */
19
20 typedef SkDiscardableMemory* (*SkDiscardableMemoryFactory)(size_t bytes);
21
22 15
23 class SkDiscardablePixelRef : public SkPixelRef { 16 class SkDiscardablePixelRef : public SkPixelRef {
24 public: 17 public:
25 /**
26 * Takes ownership of SkImageGenerator. If this method fails for
27 * whatever reason, it will return false and immediatetely delete
28 * the generator. If it succeeds, it will modify destination
29 * bitmap.
30 *
31 * If Install fails or when the SkDiscardablePixelRef that is
32 * installed into destination is destroyed, it will call
33 * SkDELETE() on the generator. Therefore, generator should be
34 * allocated with SkNEW() or SkNEW_ARGS().
35 *
36 * @param destination Upon success, this bitmap will be
37 * configured and have a pixelref installed.
38 *
39 * @param factory If not NULL, this object will be used as a
40 * source of discardable memory when decoding. If NULL, then
41 * SkDiscardableMemory::Create() will be called.
42 *
43 * @return true iff successful.
44 */
45 static bool Install(SkImageGenerator* generator,
46 SkBitmap* destination,
47 SkDiscardableMemory::Factory* factory = NULL);
48
49 SK_DECLARE_UNFLATTENABLE_OBJECT() 18 SK_DECLARE_UNFLATTENABLE_OBJECT()
50 19
51 protected: 20 protected:
52 ~SkDiscardablePixelRef(); 21 ~SkDiscardablePixelRef();
53 virtual void* onLockPixels(SkColorTable**) SK_OVERRIDE; 22 virtual void* onLockPixels(SkColorTable**) SK_OVERRIDE;
54 virtual void onUnlockPixels() SK_OVERRIDE; 23 virtual void onUnlockPixels() SK_OVERRIDE;
55 virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; } 24 virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; }
56 25
57 virtual SkData* onRefEncodedData() SK_OVERRIDE { 26 virtual SkData* onRefEncodedData() SK_OVERRIDE {
58 return fGenerator->refEncodedData(); 27 return fGenerator->refEncodedData();
59 } 28 }
60 29
61 private: 30 private:
62 SkImageGenerator* const fGenerator; 31 SkImageGenerator* const fGenerator;
63 SkDiscardableMemory::Factory* const fDMFactory; 32 SkDiscardableMemory::Factory* const fDMFactory;
64 const SkImageInfo fInfo; 33 const SkImageInfo fInfo;
65 const size_t fSize; // size of memory to be allocated 34 const size_t fSize; // size of memory to be allocated
66 const size_t fRowBytes; 35 const size_t fRowBytes;
67 // These const members should not change over the life of the 36 // These const members should not change over the life of the
68 // PixelRef, since the SkBitmap doesn't expect them to change. 37 // PixelRef, since the SkBitmap doesn't expect them to change.
69 38
70 SkDiscardableMemory* fDiscardableMemory; 39 SkDiscardableMemory* fDiscardableMemory;
71 40
72 /* Takes ownership of SkImageGenerator. */ 41 /* Takes ownership of SkImageGenerator. */
73 SkDiscardablePixelRef(SkImageGenerator* generator, 42 SkDiscardablePixelRef(SkImageGenerator* generator,
74 const SkImageInfo& info, 43 const SkImageInfo& info,
75 size_t size, 44 size_t size,
76 size_t rowBytes, 45 size_t rowBytes,
77 SkDiscardableMemory::Factory* factory); 46 SkDiscardableMemory::Factory* factory);
47 friend bool SkInstallDiscardablePixelRef(SkImageGenerator*,
48 SkBitmap*,
49 SkDiscardableMemory::Factory*);
50 typedef SkPixelRef INHERITED;
78 }; 51 };
79 #endif // SkDiscardablePixelRef_DEFINED 52 #endif // SkDiscardablePixelRef_DEFINED
OLDNEW
« no previous file with comments | « src/images/SkDecodingImageGenerator.cpp ('k') | src/lazy/SkDiscardablePixelRef.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698