1 // Copyright 2023 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expresso or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma once 16 17 #if defined(ANDROID) 18 19 #include <EGL/egl.h> 20 #include <EGL/eglext.h> 21 22 #include "Gralloc.h" 23 24 using EGLClientBuffer = void*; 25 26 namespace gfxstream { 27 28 // Abstraction around libnativewindow to support testing. 29 class ANativeWindowHelper { 30 public: ~ANativeWindowHelper()31 virtual ~ANativeWindowHelper() {} 32 33 virtual bool isValid(EGLNativeWindowType window) = 0; 34 virtual bool isValid(EGLClientBuffer buffer) = 0; 35 36 virtual void acquire(EGLNativeWindowType window) = 0; 37 virtual void release(EGLNativeWindowType window) = 0; 38 39 virtual void acquire(EGLClientBuffer buffer) = 0; 40 virtual void release(EGLClientBuffer buffer) = 0; 41 42 virtual int getConsumerUsage(EGLNativeWindowType window, int* usage) = 0; 43 virtual void setUsage(EGLNativeWindowType window, int usage) = 0; 44 45 virtual int getWidth(EGLNativeWindowType window) = 0; 46 virtual int getHeight(EGLNativeWindowType window) = 0; 47 48 virtual int getWidth(EGLClientBuffer buffer) = 0; 49 virtual int getHeight(EGLClientBuffer buffer) = 0; 50 virtual int getFormat(EGLClientBuffer buffer, Gralloc* helper) = 0; 51 virtual int getHostHandle(EGLClientBuffer buffer, Gralloc* helper) = 0; 52 53 virtual void setSwapInterval(EGLNativeWindowType window, int interval) = 0; 54 55 virtual int queueBuffer(EGLNativeWindowType window, EGLClientBuffer buffer, int fence) = 0; 56 virtual int dequeueBuffer(EGLNativeWindowType window, EGLClientBuffer* buffer, int* fence) = 0; 57 virtual int cancelBuffer(EGLNativeWindowType window, EGLClientBuffer buffer) = 0; 58 createNativeWindowForTesting(Gralloc *,uint32_t,uint32_t)59 virtual EGLNativeWindowType createNativeWindowForTesting(Gralloc* /*gralloc*/, 60 uint32_t /*width*/, 61 uint32_t /*height*/) { 62 return (EGLNativeWindowType)0; 63 } 64 }; 65 66 ANativeWindowHelper* createPlatformANativeWindowHelper(); 67 68 } // namespace gfxstream 69 70 #endif // defined(ANDROID)