blob: d4d3d8c0f5dfb9ce2f4cb7b6afbf4cd1d215fa78 [file] [log] [blame]
Chia-I Wu7e60ecc2017-11-09 11:04:45 -08001/*
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
23struct ANativeWindow;
24
25namespace android {
Chia-I Wu7e60ecc2017-11-09 11:04:45 -080026namespace RE {
27
28class Surface {
29public:
Lloyd Pique144e1162017-12-20 16:44:52 -080030 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
47namespace impl {
48
49class RenderEngine;
50
51class Surface final : public RE::Surface {
52public:
Chia-I Wu7e60ecc2017-11-09 11:04:45 -080053 Surface(const RenderEngine& engine);
54 ~Surface();
55
56 Surface(const Surface&) = delete;
57 Surface& operator=(const Surface&) = delete;
58
Lloyd Pique144e1162017-12-20 16:44:52 -080059 // RE::Surface implementation
60 void setCritical(bool enable) override { mCritical = enable; }
61 void setAsync(bool enable) override { mAsync = enable; }
Chia-I Wu7e60ecc2017-11-09 11:04:45 -080062
Lloyd Pique144e1162017-12-20 16:44:52 -080063 void setNativeWindow(ANativeWindow* window) override;
64 void swapBuffers() const override;
Chia-I Wu7e60ecc2017-11-09 11:04:45 -080065
Lloyd Pique144e1162017-12-20 16:44:52 -080066 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 Wu7e60ecc2017-11-09 11:04:45 -080070
Lloyd Pique144e1162017-12-20 16:44:52 -080071 int32_t queryWidth() const override;
72 int32_t queryHeight() const override;
Chia-I Wu7e60ecc2017-11-09 11:04:45 -080073
74private:
75 EGLint queryConfig(EGLint attrib) const;
76 EGLint querySurface(EGLint attrib) const;
77
78 // methods internal to RenderEngine
Lloyd Pique144e1162017-12-20 16:44:52 -080079 friend class RenderEngine;
Chia-I Wu7e60ecc2017-11-09 11:04:45 -080080 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 Pique144e1162017-12-20 16:44:52 -080093} // namespace impl
Chia-I Wu7e60ecc2017-11-09 11:04:45 -080094} // namespace RE
95} // namespace android