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