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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/lazy/SkCachingPixelRef.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,69 @@
     1.4 +/*
     1.5 + * Copyright 2013 Google Inc.
     1.6 + *
     1.7 + * Use of this source code is governed by a BSD-style license that can be
     1.8 + * found in the LICENSE file.
     1.9 + */
    1.10 +
    1.11 +#ifndef SkCachingPixelRef_DEFINED
    1.12 +#define SkCachingPixelRef_DEFINED
    1.13 +
    1.14 +#include "SkImageInfo.h"
    1.15 +#include "SkImageGenerator.h"
    1.16 +#include "SkPixelRef.h"
    1.17 +
    1.18 +class SkColorTable;
    1.19 +
    1.20 +/**
    1.21 + *  PixelRef which defers decoding until SkBitmap::lockPixels() is
    1.22 + *  called.  Caches the decoded images in the global
    1.23 + *  SkScaledImageCache.  When the pixels are unlocked, this cache may
    1.24 + *  or be destroyed before the next lock.  If so, onLockPixels will
    1.25 + *  attempt to re-decode.
    1.26 + *
    1.27 + *  Decoding is handled by the SkImageGenerator
    1.28 + */
    1.29 +class SkCachingPixelRef : public SkPixelRef {
    1.30 +public:
    1.31 +    SK_DECLARE_INST_COUNT(SkCachingPixelRef)
    1.32 +    /**
    1.33 +     *  Takes ownership of SkImageGenerator.  If this method fails for
    1.34 +     *  whatever reason, it will return false and immediatetely delete
    1.35 +     *  the generator.  If it succeeds, it will modify destination
    1.36 +     *  bitmap.
    1.37 +     *
    1.38 +     *  If Install fails or when the SkCachingPixelRef that is
    1.39 +     *  installed into destination is destroyed, it will call
    1.40 +     *  SkDELETE() on the generator.  Therefore, generator should be
    1.41 +     *  allocated with SkNEW() or SkNEW_ARGS().
    1.42 +     */
    1.43 +    static bool Install(SkImageGenerator* gen, SkBitmap* dst);
    1.44 +
    1.45 +protected:
    1.46 +    virtual ~SkCachingPixelRef();
    1.47 +    virtual bool onNewLockPixels(LockRec*) SK_OVERRIDE;
    1.48 +    virtual void onUnlockPixels() SK_OVERRIDE;
    1.49 +    virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; }
    1.50 +
    1.51 +    virtual SkData* onRefEncodedData() SK_OVERRIDE {
    1.52 +        return fImageGenerator->refEncodedData();
    1.53 +    }
    1.54 +    // No need to flatten this object. When flattening an SkBitmap,
    1.55 +    // SkWriteBuffer will check the encoded data and write that
    1.56 +    // instead.
    1.57 +    // Future implementations of SkWriteBuffer will need to
    1.58 +    // special case for onRefEncodedData as well.
    1.59 +    SK_DECLARE_UNFLATTENABLE_OBJECT()
    1.60 +
    1.61 +private:
    1.62 +    SkImageGenerator* const fImageGenerator;
    1.63 +    bool                    fErrorInDecoding;
    1.64 +    void*                   fScaledCacheId;
    1.65 +    const size_t            fRowBytes;
    1.66 +
    1.67 +    SkCachingPixelRef(const SkImageInfo&, SkImageGenerator*, size_t rowBytes);
    1.68 +
    1.69 +    typedef SkPixelRef INHERITED;
    1.70 +};
    1.71 +
    1.72 +#endif  // SkCachingPixelRef_DEFINED

mercurial