diff options
author | Stan Iliev <stani@google.com> | 2017-06-02 10:29:21 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-06-02 14:51:24 +0000 |
commit | 7e910df7f133e80293117bdd069ed25998d10f8c (patch) | |
tree | 5bfeea96c4904ba67fa551a76def78f17470ad73 /src/gpu/GrAHardwareBufferImageGenerator.h | |
parent | affa6a3da87e9ea85f1d4fe3137b5bccbbc56f92 (diff) |
Implement an SkImage backed by a Android hardware buffer
Create a new SkImage public API to make an image from an Android
hardware buffer. Implementation is using a SkImageGenerator
derived class GrAndroidBufferImageGenerator.
A new EGLImage texture is created, which is then wrapped with
GrTextureProxy.
Bug: skia:
Change-Id: I610a4c5a58198686ce7c03e9a0adad3f9d2342e0
Reviewed-on: https://skia-review.googlesource.com/17789
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Stan Iliev <stani@google.com>
Diffstat (limited to 'src/gpu/GrAHardwareBufferImageGenerator.h')
-rw-r--r-- | src/gpu/GrAHardwareBufferImageGenerator.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/gpu/GrAHardwareBufferImageGenerator.h b/src/gpu/GrAHardwareBufferImageGenerator.h new file mode 100644 index 0000000000..4a5004b02e --- /dev/null +++ b/src/gpu/GrAHardwareBufferImageGenerator.h @@ -0,0 +1,52 @@ +/* + * Copyright 2017 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#ifndef GrAHardwareBufferImageGenerator_DEFINED +#define GrAHardwareBufferImageGenerator_DEFINED + +#include "SkImageGenerator.h" + +#include <android/hardware_buffer.h> + +/** + * GrAHardwareBufferImageGenerator allows to create an SkImage attached to + * an existing android native hardware buffer. A hardware buffer has to be + * created with AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE usage, because it is + * bound to an external texture using an EGLImage. The image generator will + * keep a reference to the hardware buffer for its lifetime. A hardware buffer + * can be shared between processes and same buffer can be used in multiple GPU + * contexts. + * To implement certain features like tiling, Skia may copy the texture to + * avoid OpenGL API limitations. + */ +class GrAHardwareBufferImageGenerator : public SkImageGenerator { +public: + static std::unique_ptr<SkImageGenerator> Make(AHardwareBuffer*, SkAlphaType, + sk_sp<SkColorSpace>); + + ~GrAHardwareBufferImageGenerator() override; + +protected: + + bool onIsValid(GrContext*) const override; + +#if SK_SUPPORT_GPU + bool onCanGenerateTexture() const override { return true; } + sk_sp<GrTextureProxy> onGenerateTexture(GrContext*, const SkImageInfo&, + const SkIPoint&) override; +#endif + +private: + GrAHardwareBufferImageGenerator(const SkImageInfo&, AHardwareBuffer*, SkAlphaType); + + static void deleteImageTexture(void* ctx); + + AHardwareBuffer* fGraphicBuffer; + SkAlphaType fAlphaType; + + typedef SkImageGenerator INHERITED; +}; +#endif // GrAHardwareBufferImageGenerator_DEFINED |