blob: 801750a9a5fd8ee1cb5ba62557e60fad6d3929cc [file] [log] [blame]
Jason Macnak2920f942022-10-12 13:02:57 -07001// 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 Macnak2920f942022-10-12 13:02:57 -070017#include <EGL/egl.h>
18#include <EGL/eglext.h>
19#include <GLES2/gl2.h>
20#include <GLES2/gl2ext.h>
21
Jason Macnakb2a4a792023-02-23 00:40:01 +000022#include <atomic>
23#include <future>
24
25#include "ColorBuffer.h"
Jason Macnak2920f942022-10-12 13:02:57 -070026#include "Display.h"
27#include "Hwc2.h"
Jason Macnak2920f942022-10-12 13:02:57 -070028
Jason Macnaked0c9e62023-03-30 15:58:24 -070029namespace gfxstream {
30namespace gl {
31
Jason Macnak2920f942022-10-12 13:02:57 -070032class DisplayGl : public gfxstream::Display {
33 public:
Yahan Zhouaa038072023-01-12 15:00:52 -080034 DisplayGl(TextureDraw* textureDraw): mTextureDraw(textureDraw) {}
Jason Macnak2920f942022-10-12 13:02:57 -070035 ~DisplayGl() {}
36
Jason Macnak2920f942022-10-12 13:02:57 -070037 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 Zhou28c9f672023-05-11 14:51:58 -070066 void exit();
67
68 void setupContext();
Jason Macnak2920f942022-10-12 13:02:57 -070069 protected:
70 void bindToSurfaceImpl(gfxstream::DisplaySurface* surface) override {}
Yahan Zhou28c9f672023-05-11 14:51:58 -070071 void surfaceUpdated(gfxstream::DisplaySurface* surface) override {}
Jason Macnak2920f942022-10-12 13:02:57 -070072 void unbindFromSurfaceImpl() override {}
73
74 private:
75 int mViewportWidth = 0;
76 int mViewportHeight = 0;
77
Yahan Zhouaa038072023-01-12 15:00:52 -080078 TextureDraw* mTextureDraw = nullptr;
Hailin Zhang919bbb82022-12-08 16:30:59 -080079};
Jason Macnaked0c9e62023-03-30 15:58:24 -070080
81} // namespace gl
82} // namespace gfxstream