gfx/skia/trunk/include/core/SkImageGenerator.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/include/core/SkImageGenerator.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,101 @@
     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 SkImageGenerator_DEFINED
    1.12 +#define SkImageGenerator_DEFINED
    1.13 +
    1.14 +#include "SkDiscardableMemory.h"
    1.15 +#include "SkImageInfo.h"
    1.16 +
    1.17 +class SkBitmap;
    1.18 +class SkData;
    1.19 +class SkImageGenerator;
    1.20 +
    1.21 +/**
    1.22 + *  Takes ownership of SkImageGenerator.  If this method fails for
    1.23 + *  whatever reason, it will return false and immediatetely delete
    1.24 + *  the generator.  If it succeeds, it will modify destination
    1.25 + *  bitmap.
    1.26 + *
    1.27 + *  If generator is NULL, will safely return false.
    1.28 + *
    1.29 + *  If this fails or when the SkDiscardablePixelRef that is
    1.30 + *  installed into destination is destroyed, it will call
    1.31 + *  SkDELETE() on the generator.  Therefore, generator should be
    1.32 + *  allocated with SkNEW() or SkNEW_ARGS().
    1.33 + *
    1.34 + *  @param destination Upon success, this bitmap will be
    1.35 + *  configured and have a pixelref installed.
    1.36 + *
    1.37 + *  @param factory If not NULL, this object will be used as a
    1.38 + *  source of discardable memory when decoding.  If NULL, then
    1.39 + *  SkDiscardableMemory::Create() will be called.
    1.40 + *
    1.41 + *  @return true iff successful.
    1.42 + */
    1.43 +SK_API bool SkInstallDiscardablePixelRef(SkImageGenerator* generator,
    1.44 +                                         SkBitmap* destination,
    1.45 +                                         SkDiscardableMemory::Factory* factory = NULL);
    1.46 +
    1.47 +
    1.48 +/**
    1.49 + *  An interface that allows a purgeable PixelRef (such as a
    1.50 + *  SkDiscardablePixelRef) to decode and re-decode an image as needed.
    1.51 + */
    1.52 +class SK_API SkImageGenerator {
    1.53 +public:
    1.54 +    /**
    1.55 +     *  The PixelRef which takes ownership of this SkImageGenerator
    1.56 +     *  will call the image generator's destructor.
    1.57 +     */
    1.58 +    virtual ~SkImageGenerator() { }
    1.59 +
    1.60 +    /**
    1.61 +     *  Return a ref to the encoded (i.e. compressed) representation,
    1.62 +     *  of this data.
    1.63 +     *
    1.64 +     *  If non-NULL is returned, the caller is responsible for calling
    1.65 +     *  unref() on the data when it is finished.
    1.66 +     */
    1.67 +    virtual SkData* refEncodedData() { return NULL; }
    1.68 +
    1.69 +    /**
    1.70 +     *  Return some information about the image, allowing the owner of
    1.71 +     *  this object to allocate pixels.
    1.72 +     *
    1.73 +     *  Repeated calls to this function should give the same results,
    1.74 +     *  allowing the PixelRef to be immutable.
    1.75 +     *
    1.76 +     *  @return false if anything goes wrong.
    1.77 +     */
    1.78 +    virtual bool getInfo(SkImageInfo* info) = 0;
    1.79 +
    1.80 +    /**
    1.81 +     *  Decode into the given pixels, a block of memory of size at
    1.82 +     *  least (info.fHeight - 1) * rowBytes + (info.fWidth *
    1.83 +     *  bytesPerPixel)
    1.84 +     *
    1.85 +     *  Repeated calls to this function should give the same results,
    1.86 +     *  allowing the PixelRef to be immutable.
    1.87 +     *
    1.88 +     *  @param info A description of the format (config, size)
    1.89 +     *         expected by the caller.  This can simply be identical
    1.90 +     *         to the info returned by getInfo().
    1.91 +     *
    1.92 +     *         This contract also allows the caller to specify
    1.93 +     *         different output-configs, which the implementation can
    1.94 +     *         decide to support or not.
    1.95 +     *
    1.96 +     *  @return false if anything goes wrong or if the image info is
    1.97 +     *          unsupported.
    1.98 +     */
    1.99 +    virtual bool getPixels(const SkImageInfo& info,
   1.100 +                           void* pixels,
   1.101 +                           size_t rowBytes) = 0;
   1.102 +};
   1.103 +
   1.104 +#endif  // SkImageGenerator_DEFINED

mercurial