Jason Macnak | 2920f94 | 2022-10-12 13:02:57 -0700 | [diff] [blame] | 1 | // Copyright (C) 2022 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 express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #pragma once |
| 16 | |
Jason Macnak | 2920f94 | 2022-10-12 13:02:57 -0700 | [diff] [blame] | 17 | #include <EGL/egl.h> |
| 18 | #include <EGL/eglext.h> |
| 19 | #include <GLES2/gl2.h> |
| 20 | #include <GLES2/gl2ext.h> |
| 21 | |
Jason Macnak | b2a4a79 | 2023-02-23 00:40:01 +0000 | [diff] [blame] | 22 | #include <atomic> |
| 23 | #include <future> |
| 24 | |
| 25 | #include "ColorBuffer.h" |
Jason Macnak | 2920f94 | 2022-10-12 13:02:57 -0700 | [diff] [blame] | 26 | #include "Display.h" |
| 27 | #include "Hwc2.h" |
Jason Macnak | 2920f94 | 2022-10-12 13:02:57 -0700 | [diff] [blame] | 28 | |
Jason Macnak | ed0c9e6 | 2023-03-30 15:58:24 -0700 | [diff] [blame] | 29 | namespace gfxstream { |
| 30 | namespace gl { |
| 31 | |
Jason Macnak | 2920f94 | 2022-10-12 13:02:57 -0700 | [diff] [blame] | 32 | class DisplayGl : public gfxstream::Display { |
| 33 | public: |
Yahan Zhou | aa03807 | 2023-01-12 15:00:52 -0800 | [diff] [blame] | 34 | DisplayGl(TextureDraw* textureDraw): mTextureDraw(textureDraw) {} |
Jason Macnak | 2920f94 | 2022-10-12 13:02:57 -0700 | [diff] [blame] | 35 | ~DisplayGl() {} |
| 36 | |
Jason Macnak | 2920f94 | 2022-10-12 13:02:57 -0700 | [diff] [blame] | 37 | struct PostLayer { |
| 38 | ColorBuffer* colorBuffer = nullptr; |
| 39 | |
| 40 | std::optional<ComposeLayer> layerOptions; |
| 41 | |
| 42 | // TODO: This should probably be removed and TextureDraw should |
| 43 | // only use drawLayer() but this is currently needed to support |
| 44 | // existing draw paths without depending on FrameBuffer directly. |
| 45 | struct OverlayOptions { |
| 46 | float rotation; |
| 47 | float dx; |
| 48 | float dy; |
| 49 | }; |
| 50 | std::optional<OverlayOptions> overlayOptions; |
| 51 | }; |
| 52 | |
| 53 | // TODO(b/233939967): move to generic Display. |
| 54 | struct Post { |
| 55 | uint32_t frameWidth = 0; |
| 56 | uint32_t frameHeight = 0; |
| 57 | std::vector<PostLayer> layers; |
| 58 | }; |
| 59 | |
| 60 | std::shared_future<void> post(const Post& request); |
| 61 | |
| 62 | void viewport(int width, int height); |
| 63 | |
| 64 | void clear(); |
| 65 | |
Yahan Zhou | 28c9f67 | 2023-05-11 14:51:58 -0700 | [diff] [blame] | 66 | void exit(); |
| 67 | |
| 68 | void setupContext(); |
Jason Macnak | 2920f94 | 2022-10-12 13:02:57 -0700 | [diff] [blame] | 69 | protected: |
| 70 | void bindToSurfaceImpl(gfxstream::DisplaySurface* surface) override {} |
Yahan Zhou | 28c9f67 | 2023-05-11 14:51:58 -0700 | [diff] [blame] | 71 | void surfaceUpdated(gfxstream::DisplaySurface* surface) override {} |
Jason Macnak | 2920f94 | 2022-10-12 13:02:57 -0700 | [diff] [blame] | 72 | void unbindFromSurfaceImpl() override {} |
| 73 | |
| 74 | private: |
| 75 | int mViewportWidth = 0; |
| 76 | int mViewportHeight = 0; |
| 77 | |
Yahan Zhou | aa03807 | 2023-01-12 15:00:52 -0800 | [diff] [blame] | 78 | TextureDraw* mTextureDraw = nullptr; |
Hailin Zhang | 919bbb8 | 2022-12-08 16:30:59 -0800 | [diff] [blame] | 79 | }; |
Jason Macnak | ed0c9e6 | 2023-03-30 15:58:24 -0700 | [diff] [blame] | 80 | |
| 81 | } // namespace gl |
| 82 | } // namespace gfxstream |