diff options
author | 2015-08-13 13:32:39 -0700 | |
---|---|---|
committer | 2015-08-13 13:32:39 -0700 | |
commit | 8f34372f7e97482e5e61ab298b7edaa008ba2f4c (patch) | |
tree | 48581497c1bcfb3420c6aba6c6fe27d344f96855 /src/core/SkImageCacherator.h | |
parent | 5a16cf654548190841b5af27af04e7995582ad7b (diff) |
Extend SkImageGenerator to support natively generated GrTextures. As part of this, added uniqueID() to the generator, and made it be in the same namespace is bitmaps, pixelrefs, images.
To do this, create SkImageCacherator, which wraps a generator and provides an
interface to get a cached answer for either the raster or texture output of
the generator.
BUG=skia:
Review URL: https://codereview.chromium.org/1291803002
Diffstat (limited to 'src/core/SkImageCacherator.h')
-rw-r--r-- | src/core/SkImageCacherator.h | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/core/SkImageCacherator.h b/src/core/SkImageCacherator.h new file mode 100644 index 0000000000..86dbd8874f --- /dev/null +++ b/src/core/SkImageCacherator.h @@ -0,0 +1,51 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkImageCacherator_DEFINED +#define SkImageCacherator_DEFINED + +#include "SkImageGenerator.h" + +class GrContext; +class SkBitmap; + +/* + * Internal class to manage caching the output of an ImageGenerator. + */ +class SkImageCacherator { +public: + // Takes ownership of the generator + SkImageCacherator(SkImageGenerator* gen); + ~SkImageCacherator(); + + const SkImageInfo& info() const { return fGenerator->getInfo(); } + SkImageGenerator* generator() const { return fGenerator; } + + /** + * On success (true), bitmap will point to the pixels for this generator. If this returns + * false, the bitmap will be reset to empty. + * + * The cached bitmap is valid until it goes out of scope. + */ + bool lockAsBitmap(SkBitmap*); + + /** + * Returns a ref() on the texture produced by this generator. The caller must call unref() + * when it is done. Will return NULL on failure. + * + * The cached texture is valid until it is unref'd. + */ + GrTexture* lockAsTexture(GrContext*, SkImageUsageType); + +private: + bool tryLockAsBitmap(SkBitmap*); + GrTexture* tryLockAsTexture(GrContext*, SkImageUsageType); + + SkImageGenerator* fGenerator; +}; + +#endif |