gfx/skia/trunk/src/lazy/SkCachingPixelRef.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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  */
     8 #ifndef SkCachingPixelRef_DEFINED
     9 #define SkCachingPixelRef_DEFINED
    11 #include "SkImageInfo.h"
    12 #include "SkImageGenerator.h"
    13 #include "SkPixelRef.h"
    15 class SkColorTable;
    17 /**
    18  *  PixelRef which defers decoding until SkBitmap::lockPixels() is
    19  *  called.  Caches the decoded images in the global
    20  *  SkScaledImageCache.  When the pixels are unlocked, this cache may
    21  *  or be destroyed before the next lock.  If so, onLockPixels will
    22  *  attempt to re-decode.
    23  *
    24  *  Decoding is handled by the SkImageGenerator
    25  */
    26 class SkCachingPixelRef : public SkPixelRef {
    27 public:
    28     SK_DECLARE_INST_COUNT(SkCachingPixelRef)
    29     /**
    30      *  Takes ownership of SkImageGenerator.  If this method fails for
    31      *  whatever reason, it will return false and immediatetely delete
    32      *  the generator.  If it succeeds, it will modify destination
    33      *  bitmap.
    34      *
    35      *  If Install fails or when the SkCachingPixelRef that is
    36      *  installed into destination is destroyed, it will call
    37      *  SkDELETE() on the generator.  Therefore, generator should be
    38      *  allocated with SkNEW() or SkNEW_ARGS().
    39      */
    40     static bool Install(SkImageGenerator* gen, SkBitmap* dst);
    42 protected:
    43     virtual ~SkCachingPixelRef();
    44     virtual bool onNewLockPixels(LockRec*) SK_OVERRIDE;
    45     virtual void onUnlockPixels() SK_OVERRIDE;
    46     virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; }
    48     virtual SkData* onRefEncodedData() SK_OVERRIDE {
    49         return fImageGenerator->refEncodedData();
    50     }
    51     // No need to flatten this object. When flattening an SkBitmap,
    52     // SkWriteBuffer will check the encoded data and write that
    53     // instead.
    54     // Future implementations of SkWriteBuffer will need to
    55     // special case for onRefEncodedData as well.
    56     SK_DECLARE_UNFLATTENABLE_OBJECT()
    58 private:
    59     SkImageGenerator* const fImageGenerator;
    60     bool                    fErrorInDecoding;
    61     void*                   fScaledCacheId;
    62     const size_t            fRowBytes;
    64     SkCachingPixelRef(const SkImageInfo&, SkImageGenerator*, size_t rowBytes);
    66     typedef SkPixelRef INHERITED;
    67 };
    69 #endif  // SkCachingPixelRef_DEFINED

mercurial