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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/include/images/SkImageRef.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,104 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2008 The Android Open Source Project
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +
    1.12 +
    1.13 +#ifndef SkImageRef_DEFINED
    1.14 +#define SkImageRef_DEFINED
    1.15 +
    1.16 +#include "SkPixelRef.h"
    1.17 +#include "SkBitmap.h"
    1.18 +#include "SkImageDecoder.h"
    1.19 +#include "SkString.h"
    1.20 +
    1.21 +class SkImageRefPool;
    1.22 +class SkStreamRewindable;
    1.23 +
    1.24 +// define this to enable dumping whenever we add/remove/purge an imageref
    1.25 +//#define DUMP_IMAGEREF_LIFECYCLE
    1.26 +
    1.27 +class SkImageRef : public SkPixelRef {
    1.28 +public:
    1.29 +    /** Create a new imageref from a stream. NOTE: the stream is not copied, but
    1.30 +        since it may be accessed from another thread, the caller must ensure
    1.31 +        that this imageref is the only owner of the stream. i.e. - sole
    1.32 +        ownership of the stream object is transferred to this imageref object.
    1.33 +
    1.34 +        @param stream The stream containing the encoded image data. This may be
    1.35 +                      retained (by calling ref()), so the caller should not
    1.36 +                      explicitly delete it.
    1.37 +        @param config The preferred config of the decoded bitmap.
    1.38 +        @param sampleSize Requested sampleSize for decoding. Defaults to 1.
    1.39 +    */
    1.40 +    SkImageRef(const SkImageInfo&, SkStreamRewindable*, int sampleSize = 1,
    1.41 +               SkBaseMutex* mutex = NULL);
    1.42 +    virtual ~SkImageRef();
    1.43 +
    1.44 +    /** this value is passed onto the decoder. Default is true
    1.45 +     */
    1.46 +    void setDitherImage(bool dither) { fDoDither = dither; }
    1.47 +
    1.48 +    /** Return true if the image can be decoded. If so, and bitmap is non-null,
    1.49 +        call its setConfig() with the corresponding values, but explicitly will
    1.50 +        not set its pixels or colortable. Use SkPixelRef::lockPixels() for that.
    1.51 +
    1.52 +        If there has been an error decoding the bitmap, this will return false
    1.53 +        and ignore the bitmap parameter.
    1.54 +    */
    1.55 +    bool getInfo(SkBitmap* bm);
    1.56 +
    1.57 +    /** Return true if the image can be decoded and is opaque. Calling this
    1.58 +        method will decode and set the pixels in the specified bitmap and
    1.59 +        sets the isOpaque flag.
    1.60 +     */
    1.61 +    bool isOpaque(SkBitmap* bm);
    1.62 +
    1.63 +    SkImageDecoderFactory* getDecoderFactory() const { return fFactory; }
    1.64 +    // returns the factory parameter
    1.65 +    SkImageDecoderFactory* setDecoderFactory(SkImageDecoderFactory*);
    1.66 +
    1.67 +protected:
    1.68 +    /** Override if you want to install a custom allocator.
    1.69 +        When this is called we will have already acquired the mutex!
    1.70 +    */
    1.71 +    virtual bool onDecode(SkImageDecoder* codec, SkStreamRewindable*, SkBitmap*,
    1.72 +                          SkBitmap::Config, SkImageDecoder::Mode);
    1.73 +
    1.74 +    /*  Overrides from SkPixelRef
    1.75 +        When these are called, we will have already acquired the mutex!
    1.76 +     */
    1.77 +
    1.78 +    virtual bool onNewLockPixels(LockRec*) SK_OVERRIDE;
    1.79 +    // override this in your subclass to clean up when we're unlocking pixels
    1.80 +    virtual void onUnlockPixels() SK_OVERRIDE {}
    1.81 +
    1.82 +    SkImageRef(SkReadBuffer&, SkBaseMutex* mutex = NULL);
    1.83 +    virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
    1.84 +
    1.85 +    SkBitmap fBitmap;
    1.86 +
    1.87 +private:
    1.88 +    SkStreamRewindable* setStream(SkStreamRewindable*);
    1.89 +    // called with mutex already held. returns true if the bitmap is in the
    1.90 +    // requested state (or further, i.e. has pixels)
    1.91 +    bool prepareBitmap(SkImageDecoder::Mode);
    1.92 +
    1.93 +    SkImageDecoderFactory*  fFactory;    // may be null
    1.94 +    SkStreamRewindable*     fStream;
    1.95 +    int                     fSampleSize;
    1.96 +    bool                    fDoDither;
    1.97 +    bool                    fErrorInDecoding;
    1.98 +
    1.99 +    friend class SkImageRefPool;
   1.100 +
   1.101 +    SkImageRef*  fPrev, *fNext;
   1.102 +    size_t ramUsed() const;
   1.103 +
   1.104 +    typedef SkPixelRef INHERITED;
   1.105 +};
   1.106 +
   1.107 +#endif

mercurial