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

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

Issue 54203006: Break up SkLazyPixelRef functionally into class hierarchy. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: changes for reed and scroggo 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
(Empty)
1 /*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef SkLazyCachingPixelRef_DEFINED
9 #define SkLazyCachingPixelRef_DEFINED
10
11 #include "SkBitmapFactory.h"
12 #include "SkCachingPixelRef.h"
13
14 class SkData;
15
16 /**
17 * PixelRef which defers decoding until SkBitmap::lockPixels() is
18 * called. Makes use of a supplied decode procedure. Will decode at
19 * the procedure's preferred size.
20 */
21 class SkLazyCachingPixelRef : public SkCachingPixelRef {
22 public:
23 /**
24 * @param data Encoded data representing the pixels. NULL is
25 * equivalent to an empty data, and will be passed to
26 * DecodeProc with length zero.
27 *
28 * @param procedure Called to decode the pixels when
29 * needed. If NULL, use SkImageDecoder::DecodeMemoryToTarget.
30 *
31 * @param cache If NULL, use the default global cache.
32 */
33 SkLazyCachingPixelRef(SkData* data,
34 SkBitmapFactory::DecodeProc procedure,
35 SkScaledImageCache* cache = NULL);
reed1 2013/11/01 21:41:10 See other comment/question about the need to speci
36
37 virtual ~SkLazyCachingPixelRef();
38
39 virtual SkData* onRefEncodedData() SK_OVERRIDE { return SkSafeRef(fData); }
40
41 /**
42 * A simplified version of SkBitmapFactory. Installs a new
43 * SkLazyCachingPixelRef into the provided bitmap. Will
44 * immediately call onDecodeInfo() to configure the bitmap, but
45 * will defer decoding until the first time the bitmap's pixels
46 * are locked.
47 *
48 * @param data Encoded data representing the pixels. NULL is
49 * equivalent to an empty data, and will be passed to
50 * DecodeProc with length zero.
51 *
52 * @param procedure Called to decode the pixels when
53 * needed. If NULL, use SkImageDecoder::DecodeMemoryToTarget.
54 *
55 * @param destination Bitmap that will be modified on success.
56 *
57 * @param cache If NULL, use the default global cache.
58 *
59 * @returns true on success.
60 */
61 static bool Install(SkBitmapFactory::DecodeProc procedure,
62 SkData* data,
63 SkBitmap* destination,
64 SkScaledImageCache* cache = NULL);
65
66 // No need to flatten this object. When flattening an SkBitmap,
67 // SkOrderedWriteBuffer will check the encoded data and write that
68 // instead.
69 // Future implementations of SkFlattenableWriteBuffer will need to
70 // special case for onRefEncodedData as well.
71 SK_DECLARE_UNFLATTENABLE_OBJECT()
72
73 protected:
74 /**
75 * Return some information about the pixels, allowing this class
76 * to allocate pixels. @return false if anything goes wrong.
77 *
78 * This implementation calls SkBitmapFactory::DecodeProc with a
79 * NULL target.
80 */
81 virtual bool onDecodeInfo(SkImageInfo* info) SK_OVERRIDE;
82 /**
83 * Decode into the given pixels.
84 * @return false if anything goes wrong.
85 *
86 * This implementation calls SkBitmapFactory::DecodeProc with a
87 * target containing pixels and rowBytes.
88 */
89 virtual bool onDecode(void* pixels, size_t rowBytes) SK_OVERRIDE;
90
91 private:
92 SkData* fData;
93 SkBitmapFactory::DecodeProc fDecodeProc;
94
95 typedef SkCachingPixelRef INHERITED;
96 };
97
98 #endif // SkLazyCachingPixelRef_DEFINED
99
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698