1 /* 2 * Copyright 2023 Google LLC 3 * SPDX-License-Identifier: MIT 4 */ 5 6 #pragma once 7 8 #if defined(ANDROID) 9 10 #include <EGL/egl.h> 11 #include <EGL/eglext.h> 12 13 #include "GfxStreamGralloc.h" 14 15 using EGLClientBuffer = void*; 16 17 namespace gfxstream { 18 19 // Abstraction around libnativewindow to support testing. 20 class ANativeWindowHelper { 21 public: ~ANativeWindowHelper()22 virtual ~ANativeWindowHelper() {} 23 24 virtual bool isValid(EGLNativeWindowType window) = 0; 25 virtual bool isValid(EGLClientBuffer buffer) = 0; 26 27 virtual void acquire(EGLNativeWindowType window) = 0; 28 virtual void release(EGLNativeWindowType window) = 0; 29 30 virtual void acquire(EGLClientBuffer buffer) = 0; 31 virtual void release(EGLClientBuffer buffer) = 0; 32 33 virtual int getConsumerUsage(EGLNativeWindowType window, int* usage) = 0; 34 virtual void setUsage(EGLNativeWindowType window, int usage) = 0; 35 36 virtual int getWidth(EGLNativeWindowType window) = 0; 37 virtual int getHeight(EGLNativeWindowType window) = 0; 38 39 virtual int getWidth(EGLClientBuffer buffer) = 0; 40 virtual int getHeight(EGLClientBuffer buffer) = 0; 41 virtual int getFormat(EGLClientBuffer buffer, Gralloc* helper) = 0; 42 virtual int getHostHandle(EGLClientBuffer buffer, Gralloc* helper) = 0; 43 44 virtual void setSwapInterval(EGLNativeWindowType window, int interval) = 0; 45 46 virtual int queueBuffer(EGLNativeWindowType window, EGLClientBuffer buffer, int fence) = 0; 47 virtual int dequeueBuffer(EGLNativeWindowType window, EGLClientBuffer* buffer, int* fence) = 0; 48 virtual int cancelBuffer(EGLNativeWindowType window, EGLClientBuffer buffer) = 0; 49 createNativeWindowForTesting(Gralloc *,uint32_t,uint32_t)50 virtual EGLNativeWindowType createNativeWindowForTesting(Gralloc* /*gralloc*/, 51 uint32_t /*width*/, 52 uint32_t /*height*/) { 53 return (EGLNativeWindowType)0; 54 } 55 }; 56 57 ANativeWindowHelper* createPlatformANativeWindowHelper(); 58 59 } // namespace gfxstream 60 61 #endif // defined(ANDROID) 62