gfx/skia/trunk/include/images/SkImageRef.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1
michael@0 2 /*
michael@0 3 * Copyright 2008 The Android Open Source Project
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8
michael@0 9
michael@0 10 #ifndef SkImageRef_DEFINED
michael@0 11 #define SkImageRef_DEFINED
michael@0 12
michael@0 13 #include "SkPixelRef.h"
michael@0 14 #include "SkBitmap.h"
michael@0 15 #include "SkImageDecoder.h"
michael@0 16 #include "SkString.h"
michael@0 17
michael@0 18 class SkImageRefPool;
michael@0 19 class SkStreamRewindable;
michael@0 20
michael@0 21 // define this to enable dumping whenever we add/remove/purge an imageref
michael@0 22 //#define DUMP_IMAGEREF_LIFECYCLE
michael@0 23
michael@0 24 class SkImageRef : public SkPixelRef {
michael@0 25 public:
michael@0 26 /** Create a new imageref from a stream. NOTE: the stream is not copied, but
michael@0 27 since it may be accessed from another thread, the caller must ensure
michael@0 28 that this imageref is the only owner of the stream. i.e. - sole
michael@0 29 ownership of the stream object is transferred to this imageref object.
michael@0 30
michael@0 31 @param stream The stream containing the encoded image data. This may be
michael@0 32 retained (by calling ref()), so the caller should not
michael@0 33 explicitly delete it.
michael@0 34 @param config The preferred config of the decoded bitmap.
michael@0 35 @param sampleSize Requested sampleSize for decoding. Defaults to 1.
michael@0 36 */
michael@0 37 SkImageRef(const SkImageInfo&, SkStreamRewindable*, int sampleSize = 1,
michael@0 38 SkBaseMutex* mutex = NULL);
michael@0 39 virtual ~SkImageRef();
michael@0 40
michael@0 41 /** this value is passed onto the decoder. Default is true
michael@0 42 */
michael@0 43 void setDitherImage(bool dither) { fDoDither = dither; }
michael@0 44
michael@0 45 /** Return true if the image can be decoded. If so, and bitmap is non-null,
michael@0 46 call its setConfig() with the corresponding values, but explicitly will
michael@0 47 not set its pixels or colortable. Use SkPixelRef::lockPixels() for that.
michael@0 48
michael@0 49 If there has been an error decoding the bitmap, this will return false
michael@0 50 and ignore the bitmap parameter.
michael@0 51 */
michael@0 52 bool getInfo(SkBitmap* bm);
michael@0 53
michael@0 54 /** Return true if the image can be decoded and is opaque. Calling this
michael@0 55 method will decode and set the pixels in the specified bitmap and
michael@0 56 sets the isOpaque flag.
michael@0 57 */
michael@0 58 bool isOpaque(SkBitmap* bm);
michael@0 59
michael@0 60 SkImageDecoderFactory* getDecoderFactory() const { return fFactory; }
michael@0 61 // returns the factory parameter
michael@0 62 SkImageDecoderFactory* setDecoderFactory(SkImageDecoderFactory*);
michael@0 63
michael@0 64 protected:
michael@0 65 /** Override if you want to install a custom allocator.
michael@0 66 When this is called we will have already acquired the mutex!
michael@0 67 */
michael@0 68 virtual bool onDecode(SkImageDecoder* codec, SkStreamRewindable*, SkBitmap*,
michael@0 69 SkBitmap::Config, SkImageDecoder::Mode);
michael@0 70
michael@0 71 /* Overrides from SkPixelRef
michael@0 72 When these are called, we will have already acquired the mutex!
michael@0 73 */
michael@0 74
michael@0 75 virtual bool onNewLockPixels(LockRec*) SK_OVERRIDE;
michael@0 76 // override this in your subclass to clean up when we're unlocking pixels
michael@0 77 virtual void onUnlockPixels() SK_OVERRIDE {}
michael@0 78
michael@0 79 SkImageRef(SkReadBuffer&, SkBaseMutex* mutex = NULL);
michael@0 80 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
michael@0 81
michael@0 82 SkBitmap fBitmap;
michael@0 83
michael@0 84 private:
michael@0 85 SkStreamRewindable* setStream(SkStreamRewindable*);
michael@0 86 // called with mutex already held. returns true if the bitmap is in the
michael@0 87 // requested state (or further, i.e. has pixels)
michael@0 88 bool prepareBitmap(SkImageDecoder::Mode);
michael@0 89
michael@0 90 SkImageDecoderFactory* fFactory; // may be null
michael@0 91 SkStreamRewindable* fStream;
michael@0 92 int fSampleSize;
michael@0 93 bool fDoDither;
michael@0 94 bool fErrorInDecoding;
michael@0 95
michael@0 96 friend class SkImageRefPool;
michael@0 97
michael@0 98 SkImageRef* fPrev, *fNext;
michael@0 99 size_t ramUsed() const;
michael@0 100
michael@0 101 typedef SkPixelRef INHERITED;
michael@0 102 };
michael@0 103
michael@0 104 #endif

mercurial