• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 #pragma once
17 
18 #include <future>
19 #include <optional>
20 
21 #include "DisplaySurfaceUser.h"
22 #include "PostWorker.h"
23 #include "gl/DisplayGl.h"
24 #include "gl/EmulationGl.h"
25 
26 namespace gfxstream {
27 
28 class RecursiveScopedContextBind;
29 
30 namespace gl {
31 class DisplayGl;
32 class EmulationGl;
33 }  // namespace gl
34 
35 class PostWorkerGl : public PostWorker, public DisplaySurfaceUser {
36    public:
37     PostWorkerGl(bool mainThreadPostingOnly, FrameBuffer* fb, Compositor* compositor,
38                  gl::DisplayGl* displayGl, gl::EmulationGl* emulationGl);
39 
40     void screenshot(ColorBuffer* cb, int screenwidth, int screenheight, GLenum format, GLenum type,
41                     int skinRotation, void* pixels, Rect rect) override;
42 
43    protected:
44     std::shared_future<void> postImpl(ColorBuffer* cb) override;
45     void viewportImpl(int width, int height) override;
46     void clearImpl() override;
47     void exitImpl() override;
48     std::shared_future<void> composeImpl(const FlatComposeRequest& composeRequest) override;
49 
bindToSurfaceImpl(gfxstream::DisplaySurface * surface)50     void bindToSurfaceImpl(gfxstream::DisplaySurface* surface) override {}
surfaceUpdated(gfxstream::DisplaySurface * surface)51     void surfaceUpdated(gfxstream::DisplaySurface* surface) override {}
unbindFromSurfaceImpl()52     void unbindFromSurfaceImpl() override {}
53 
54    private:
55     void setupContext();
56     gl::DisplayGl::PostLayer postWithOverlay(ColorBuffer* cb);
57 
58    private:
59     // TODO(b/233939967): conslidate DisplayGl and DisplayVk into
60     // `Display* const m_display`.
61     gl::DisplayGl* const m_displayGl;
62 
63     int m_viewportWidth = 0;
64     int m_viewportHeight = 0;
65 
66     bool mContextBound = false;
67     std::unique_ptr<gfxstream::DisplaySurface> mFakeWindowSurface = nullptr;
68     gl::EmulationGl* mEmulationGl;
69 };
70 
71 }  // namespace gfxstream