| Chia-I Wu | 7e60ecc | 2017-11-09 11:04:45 -0800 | [diff] [blame] | 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 { | 
| Chia-I Wu | 7e60ecc | 2017-11-09 11:04:45 -0800 | [diff] [blame] | 26 | namespace RE { | 
 | 27 |  | 
 | 28 | class Surface { | 
 | 29 | public: | 
| Lloyd Pique | 144e116 | 2017-12-20 16:44:52 -0800 | [diff] [blame] | 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: | 
| Chia-I Wu | 7e60ecc | 2017-11-09 11:04:45 -0800 | [diff] [blame] | 53 |     Surface(const RenderEngine& engine); | 
 | 54 |     ~Surface(); | 
 | 55 |  | 
 | 56 |     Surface(const Surface&) = delete; | 
 | 57 |     Surface& operator=(const Surface&) = delete; | 
 | 58 |  | 
| Lloyd Pique | 144e116 | 2017-12-20 16:44:52 -0800 | [diff] [blame] | 59 |     // RE::Surface implementation | 
 | 60 |     void setCritical(bool enable) override { mCritical = enable; } | 
 | 61 |     void setAsync(bool enable) override { mAsync = enable; } | 
| Chia-I Wu | 7e60ecc | 2017-11-09 11:04:45 -0800 | [diff] [blame] | 62 |  | 
| Lloyd Pique | 144e116 | 2017-12-20 16:44:52 -0800 | [diff] [blame] | 63 |     void setNativeWindow(ANativeWindow* window) override; | 
 | 64 |     void swapBuffers() const override; | 
| Chia-I Wu | 7e60ecc | 2017-11-09 11:04:45 -0800 | [diff] [blame] | 65 |  | 
| Lloyd Pique | 144e116 | 2017-12-20 16:44:52 -0800 | [diff] [blame] | 66 |     int32_t queryRedSize() const override; | 
 | 67 |     int32_t queryGreenSize() const override; | 
 | 68 |     int32_t queryBlueSize() const override; | 
 | 69 |     int32_t queryAlphaSize() const override; | 
| Chia-I Wu | 7e60ecc | 2017-11-09 11:04:45 -0800 | [diff] [blame] | 70 |  | 
| Lloyd Pique | 144e116 | 2017-12-20 16:44:52 -0800 | [diff] [blame] | 71 |     int32_t queryWidth() const override; | 
 | 72 |     int32_t queryHeight() const override; | 
| Chia-I Wu | 7e60ecc | 2017-11-09 11:04:45 -0800 | [diff] [blame] | 73 |  | 
 | 74 | private: | 
 | 75 |     EGLint queryConfig(EGLint attrib) const; | 
 | 76 |     EGLint querySurface(EGLint attrib) const; | 
 | 77 |  | 
 | 78 |     // methods internal to RenderEngine | 
| Lloyd Pique | 144e116 | 2017-12-20 16:44:52 -0800 | [diff] [blame] | 79 |     friend class RenderEngine; | 
| Chia-I Wu | 7e60ecc | 2017-11-09 11:04:45 -0800 | [diff] [blame] | 80 |     bool getAsync() const { return mAsync; } | 
 | 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 |  | 
| Lloyd Pique | 144e116 | 2017-12-20 16:44:52 -0800 | [diff] [blame] | 93 | } // namespace impl | 
| Chia-I Wu | 7e60ecc | 2017-11-09 11:04:45 -0800 | [diff] [blame] | 94 | } // namespace RE | 
 | 95 | } // namespace android |