1 // Copyright (C) 2016 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 #pragma once 15 16 #include <memory> 17 18 #include "aemu/base/files/Stream.h" 19 #include "host-common/crash_reporter.h" 20 #include "host-common/dma_device.h" 21 #include "host-common/multi_display_agent.h" 22 #include "host-common/RefcountPipe.h" 23 #include "host-common/sync_device.h" 24 #include "host-common/vm_operations.h" 25 #include "host-common/window_agent.h" 26 #include "host-common/opengl/emugl_config.h" 27 #include "render-utils/Renderer.h" 28 #include "render-utils/render_api_types.h" 29 30 extern "C" { 31 32 struct address_space_device_control_ops; 33 34 } // extern "C" 35 36 namespace android { 37 namespace base { 38 39 class CpuUsage; 40 class MemoryTracker; 41 class GLObjectCounter; 42 43 } // namespace base 44 } // namespace android 45 46 namespace gfxstream { 47 48 struct RenderOpt { 49 void* display; 50 void* surface; 51 void* config; 52 }; 53 54 using android::emulation::OnLastColorBufferRef; 55 56 // RenderLib - root interface for the GPU emulation library 57 // Use it to set the library-wide parameters (logging, crash reporting) and 58 // create indivudual renderers that take care of drawing windows. 59 class RenderLib { 60 public: 61 virtual ~RenderLib() = default; 62 63 // Get the selected renderer 64 virtual void setRenderer(SelectedRenderer renderer) = 0; 65 // Tell emugl the API version of the system image 66 virtual void setAvdInfo(bool phone, int api) = 0; 67 // Get the GLES major/minor version determined by libOpenglRender. 68 virtual void getGlesVersion(int* maj, int* min) = 0; 69 virtual void setLogger(emugl_logger_struct logger) = 0; 70 virtual void setGLObjectCounter( 71 android::base::GLObjectCounter* counter) = 0; 72 virtual void setCrashReporter(emugl_crash_reporter_t reporter) = 0; 73 virtual void setFeatureController(emugl_feature_is_enabled_t featureController) = 0; 74 virtual void setSyncDevice(emugl_sync_create_timeline_t, 75 emugl_sync_create_fence_t, 76 emugl_sync_timeline_inc_t, 77 emugl_sync_destroy_timeline_t, 78 emugl_sync_register_trigger_wait_t, 79 emugl_sync_device_exists_t) = 0; 80 81 // Sets the function use to read from the guest 82 // physically contiguous DMA region at particular offsets. 83 virtual void setDmaOps(emugl_dma_ops) = 0; 84 85 virtual void setVmOps(const QAndroidVmOperations &vm_operations) = 0; 86 virtual void setAddressSpaceDeviceControlOps(struct address_space_device_control_ops* ops) = 0; 87 88 virtual void setWindowOps(const QAndroidEmulatorWindowAgent &window_operations, 89 const QAndroidMultiDisplayAgent &multi_display_operations) = 0; 90 91 virtual void setUsageTracker(android::base::CpuUsage* cpuUsage, 92 android::base::MemoryTracker* memUsage) = 0; 93 94 virtual void setGrallocImplementation(GrallocImplementation gralloc) = 0; 95 96 virtual bool getOpt(RenderOpt* opt) = 0; 97 98 // initRenderer - initialize the OpenGL renderer object. 99 // 100 // |width| and |height| are the framebuffer dimensions that will be reported 101 // to the guest display driver. 102 // 103 // |useSubWindow| is true to indicate that renderer has to support an 104 // OpenGL subwindow. If false, it only supports setPostCallback(). 105 // See Renderer.h for more info. 106 // 107 // There might be only one renderer. 108 virtual RendererPtr initRenderer(int width, int height, 109 bool useSubWindow, bool egl2egl) = 0; 110 111 virtual OnLastColorBufferRef getOnLastColorBufferRef() = 0; 112 }; 113 114 using RenderLibPtr = std::unique_ptr<RenderLib>; 115 116 } // namespace gfxstream 117