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