1 /* 2 * Copyright 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <cstdint> 20 21 #include <EGL/egl.h> 22 23 struct ANativeWindow; 24 25 namespace android { 26 namespace RE { 27 28 class Surface { 29 public: 30 virtual ~Surface() = 0; 31 32 virtual void setCritical(bool enable) = 0; 33 virtual void setAsync(bool enable) = 0; 34 35 virtual void setNativeWindow(ANativeWindow* window) = 0; 36 virtual void swapBuffers() const = 0; 37 38 virtual int32_t queryRedSize() const = 0; 39 virtual int32_t queryGreenSize() const = 0; 40 virtual int32_t queryBlueSize() const = 0; 41 virtual int32_t queryAlphaSize() const = 0; 42 43 virtual int32_t queryWidth() const = 0; 44 virtual int32_t queryHeight() const = 0; 45 }; 46 47 namespace impl { 48 49 class RenderEngine; 50 51 class Surface final : public RE::Surface { 52 public: 53 Surface(const RenderEngine& engine); 54 ~Surface(); 55 56 Surface(const Surface&) = delete; 57 Surface& operator=(const Surface&) = delete; 58 59 // RE::Surface implementation setCritical(bool enable)60 void setCritical(bool enable) override { mCritical = enable; } setAsync(bool enable)61 void setAsync(bool enable) override { mAsync = enable; } 62 63 void setNativeWindow(ANativeWindow* window) override; 64 void swapBuffers() const override; 65 66 int32_t queryRedSize() const override; 67 int32_t queryGreenSize() const override; 68 int32_t queryBlueSize() const override; 69 int32_t queryAlphaSize() const override; 70 71 int32_t queryWidth() const override; 72 int32_t queryHeight() const override; 73 74 private: 75 EGLint queryConfig(EGLint attrib) const; 76 EGLint querySurface(EGLint attrib) const; 77 78 // methods internal to RenderEngine 79 friend class RenderEngine; getAsync()80 bool getAsync() const { return mAsync; } getEGLSurface()81 EGLSurface getEGLSurface() const { return mEGLSurface; } 82 83 EGLDisplay mEGLDisplay; 84 EGLConfig mEGLConfig; 85 86 bool mCritical = false; 87 bool mAsync = false; 88 89 ANativeWindow* mWindow = nullptr; 90 EGLSurface mEGLSurface = EGL_NO_SURFACE; 91 }; 92 93 } // namespace impl 94 } // namespace RE 95 } // namespace android 96