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