Debian Codegraph @

src/gpu/ganesh/GrAHardwareBufferImageGenerator.h

raw
1 /*
2 * Copyright 2017 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 */
7 #ifndef GrAHardwareBufferImageGenerator_DEFINED
8 #define GrAHardwareBufferImageGenerator_DEFINED
9
10 #include "include/private/gpu/ganesh/GrTextureGenerator.h"
11 #include "include/private/gpu/ganesh/GrTypesPriv.h"
12
13 class GrGpuResource;
14 class GrSurfaceProxyView;
15 class SkRecorder;
16
17 extern "C" {
18 typedef struct AHardwareBuffer AHardwareBuffer;
19 }
20
21 /**
22 * GrAHardwareBufferImageGenerator allows to create an SkImage attached to
23 * an existing android native hardware buffer. A hardware buffer has to be
24 * created with AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE usage, because it is
25 * bound to an external texture using an EGLImage. The image generator will
26 * keep a reference to the hardware buffer for its lifetime. A hardware buffer
27 * can be shared between processes and same buffer can be used in multiple GPU
28 * contexts.
29 * To implement certain features like tiling, Skia may copy the texture to
30 * avoid OpenGL API limitations.
31 */
32 class GrAHardwareBufferImageGenerator : public GrTextureGenerator {
33 public:
34 static std::unique_ptr<GrAHardwareBufferImageGenerator> Make(AHardwareBuffer*, SkAlphaType,
35 sk_sp<SkColorSpace>, GrSurfaceOrigin);
36
37 ~GrAHardwareBufferImageGenerator() override;
38
39 static void DeleteGLTexture(void* ctx);
40
41 private:
42 GrAHardwareBufferImageGenerator(const SkImageInfo&, AHardwareBuffer*, SkAlphaType,
43 bool isProtectedContent, uint32_t bufferFormat,
44 GrSurfaceOrigin surfaceOrigin);
45
46 bool onIsValid(SkRecorder*) const override;
47
48 GrSurfaceProxyView onGenerateTexture(GrRecordingContext*,
49 const SkImageInfo&,
50 skgpu::Mipmapped,
51 GrImageTexGenPolicy) override;
52
53 GrSurfaceOrigin origin() const override { return fSurfaceOrigin; }
54
55 GrSurfaceProxyView makeView(GrRecordingContext* context);
56
57 void releaseTextureRef();
58
59 static void ReleaseRefHelper_TextureReleaseProc(void* ctx);
60
61 AHardwareBuffer* fHardwareBuffer;
62 uint32_t fBufferFormat;
63 const bool fIsProtectedContent;
64 GrSurfaceOrigin fSurfaceOrigin;
65 };
66 #endif // GrAHardwareBufferImageGenerator_DEFINED