1 // Copyright 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 expresso 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 <atomic> 18 19 #include <EGL/egl.h> 20 #include <GLES/gl.h> 21 #include <GLES/glext.h> 22 #include <GLES3/gl3.h> 23 24 #include "Compositor.h" 25 #include "DisplaySurfaceUser.h" 26 #include "TextureDraw.h" 27 28 namespace gfxstream { 29 namespace gl { 30 31 class CompositorGl : public Compositor, public gfxstream::DisplaySurfaceUser { 32 public: 33 CompositorGl(TextureDraw* textureDraw); 34 virtual ~CompositorGl(); 35 36 // If false, this display will use the existing bound context when performing compositions. setUseBoundSurfaceContext(bool use)37 void setUseBoundSurfaceContext(bool use) { mUseBoundSurfaceContext = use; } 38 39 CompositionFinishedWaitable compose(const CompositionRequest& compositionRequest) override; 40 41 protected: 42 void bindToSurfaceImpl(gfxstream::DisplaySurface* surface) override; surfaceUpdated(gfxstream::DisplaySurface * surface)43 void surfaceUpdated(gfxstream::DisplaySurface* surface) override {}; 44 void unbindFromSurfaceImpl() override; 45 46 private: 47 GLuint m_composeFbo = 0; 48 49 // Owned by FrameBuffer. 50 TextureDraw* m_textureDraw = nullptr; 51 52 std::atomic_bool mUseBoundSurfaceContext{true}; 53 }; 54 55 } // namespace gl 56 } // namespace gfxstream 57