• 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     // If false, this display will use the existing bound context when
38     // performing display ops.
setUseBoundSurfaceContext(bool use)39     void setUseBoundSurfaceContext(bool use) { mUseBoundSurfaceContext = use; }
40 
41     struct PostLayer {
42       ColorBuffer* colorBuffer = nullptr;
43 
44       std::optional<ComposeLayer> layerOptions;
45 
46       // TODO: This should probably be removed and TextureDraw should
47       // only use drawLayer() but this is currently needed to support
48       // existing draw paths without depending on FrameBuffer directly.
49       struct OverlayOptions {
50         float rotation;
51         float dx;
52         float dy;
53       };
54       std::optional<OverlayOptions> overlayOptions;
55     };
56 
57     // TODO(b/233939967): move to generic Display.
58     struct Post {
59       uint32_t frameWidth = 0;
60       uint32_t frameHeight = 0;
61       std::vector<PostLayer> layers;
62     };
63 
64     std::shared_future<void> post(const Post& request);
65 
66     void viewport(int width, int height);
67 
68     void clear();
69 
70   protected:
bindToSurfaceImpl(gfxstream::DisplaySurface * surface)71     void bindToSurfaceImpl(gfxstream::DisplaySurface* surface) override {}
surfaceUpdated(gfxstream::DisplaySurface * surface)72     void surfaceUpdated(gfxstream::DisplaySurface* surface) override{} ;
unbindFromSurfaceImpl()73     void unbindFromSurfaceImpl() override {}
74 
75   private:
76     int mViewportWidth = 0;
77     int mViewportHeight = 0;
78 
79     std::atomic_bool mUseBoundSurfaceContext{true};
80     TextureDraw* mTextureDraw = nullptr;
81 };
82 
83 }  // namespace gl
84 }  // namespace gfxstream
85