• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 #include <EGL/egl.h>
18 #include <EGL/eglext.h>
19 #include <GLES2/gl2.h>
20 #include <GLES2/gl2ext.h>
21 
22 #include <atomic>
23 #include <future>
24 
25 #include "ColorBuffer.h"
26 #include "Display.h"
27 #include "Hwc2.h"
28 
29 namespace gfxstream {
30 namespace gl {
31 
32 class DisplayGl : public gfxstream::Display {
33   public:
DisplayGl(TextureDraw * textureDraw)34     DisplayGl(TextureDraw* textureDraw): mTextureDraw(textureDraw) {}
~DisplayGl()35     ~DisplayGl() {}
36 
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 
66     void exit();
67 
68     void setupContext();
69   protected:
bindToSurfaceImpl(gfxstream::DisplaySurface * surface)70     void bindToSurfaceImpl(gfxstream::DisplaySurface* surface) override {}
surfaceUpdated(gfxstream::DisplaySurface * surface)71     void surfaceUpdated(gfxstream::DisplaySurface* surface) override {}
unbindFromSurfaceImpl()72     void unbindFromSurfaceImpl() override {}
73 
74   private:
75     int mViewportWidth = 0;
76     int mViewportHeight = 0;
77 
78     TextureDraw* mTextureDraw = nullptr;
79 };
80 
81 }  // namespace gl
82 }  // namespace gfxstream
83