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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial