OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/ozone/platform/dri/gbm_surface_factory.h" |
| 6 |
| 7 #include <EGL/egl.h> |
| 8 |
| 9 #include "base/files/file_path.h" |
| 10 #include "ui/gfx/ozone/surface_ozone_egl.h" |
| 11 #include "ui/ozone/platform/dri/dri_vsync_provider.h" |
| 12 #include "ui/ozone/platform/dri/gbm_surface.h" |
| 13 #include "ui/ozone/platform/dri/hardware_display_controller.h" |
| 14 #include "ui/ozone/platform/dri/scanout_surface.h" |
| 15 #include "ui/ozone/platform/dri/screen_manager.h" |
| 16 |
| 17 namespace ui { |
| 18 |
| 19 namespace { |
| 20 |
| 21 class GbmSurfaceAdapter : public gfx::SurfaceOzoneEGL { |
| 22 public: |
| 23 GbmSurfaceAdapter(const base::WeakPtr<HardwareDisplayController>& controller); |
| 24 virtual ~GbmSurfaceAdapter(); |
| 25 |
| 26 // SurfaceOzoneEGL: |
| 27 virtual intptr_t GetNativeWindow() OVERRIDE; |
| 28 virtual bool ResizeNativeWindow(const gfx::Size& viewport_size) OVERRIDE; |
| 29 virtual bool OnSwapBuffers() OVERRIDE; |
| 30 virtual scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() OVERRIDE; |
| 31 |
| 32 private: |
| 33 base::WeakPtr<HardwareDisplayController> controller_; |
| 34 |
| 35 DISALLOW_COPY_AND_ASSIGN(GbmSurfaceAdapter); |
| 36 }; |
| 37 |
| 38 GbmSurfaceAdapter::GbmSurfaceAdapter( |
| 39 const base::WeakPtr<HardwareDisplayController>& controller) |
| 40 : controller_(controller) {} |
| 41 |
| 42 GbmSurfaceAdapter::~GbmSurfaceAdapter() {} |
| 43 |
| 44 intptr_t GbmSurfaceAdapter::GetNativeWindow() { |
| 45 if (!controller_) |
| 46 return 0; |
| 47 |
| 48 return reinterpret_cast<intptr_t>( |
| 49 static_cast<GbmSurface*>(controller_->surface())->native_surface()); |
| 50 } |
| 51 |
| 52 bool GbmSurfaceAdapter::ResizeNativeWindow(const gfx::Size& viewport_size) { |
| 53 NOTIMPLEMENTED(); |
| 54 return false; |
| 55 } |
| 56 |
| 57 bool GbmSurfaceAdapter::OnSwapBuffers() { |
| 58 if (!controller_) |
| 59 return false; |
| 60 |
| 61 static_cast<GbmSurface*>(controller_->surface())->LockCurrentDrawable(); |
| 62 if (controller_->SchedulePageFlip()) { |
| 63 controller_->WaitForPageFlipEvent(); |
| 64 return true; |
| 65 } |
| 66 |
| 67 return false; |
| 68 } |
| 69 |
| 70 scoped_ptr<gfx::VSyncProvider> GbmSurfaceAdapter::CreateVSyncProvider() { |
| 71 return scoped_ptr<gfx::VSyncProvider>(new DriVSyncProvider(controller_)); |
| 72 } |
| 73 |
| 74 } // namespace |
| 75 |
| 76 GbmSurfaceFactory::GbmSurfaceFactory(DriWrapper* dri, |
| 77 gbm_device* device, |
| 78 ScreenManager* screen_manager) |
| 79 : DriSurfaceFactory(dri, screen_manager), |
| 80 device_(device) {} |
| 81 |
| 82 GbmSurfaceFactory::~GbmSurfaceFactory() {} |
| 83 |
| 84 intptr_t GbmSurfaceFactory::GetNativeDisplay() { |
| 85 CHECK(state_ == INITIALIZED); |
| 86 return reinterpret_cast<intptr_t>(device_); |
| 87 } |
| 88 |
| 89 const int32* GbmSurfaceFactory::GetEGLSurfaceProperties( |
| 90 const int32* desired_list) { |
| 91 static const int32 kConfigAttribs[] = { |
| 92 EGL_BUFFER_SIZE, 32, |
| 93 EGL_ALPHA_SIZE, 8, |
| 94 EGL_BLUE_SIZE, 8, |
| 95 EGL_GREEN_SIZE, 8, |
| 96 EGL_RED_SIZE, 8, |
| 97 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| 98 EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
| 99 EGL_NONE |
| 100 }; |
| 101 |
| 102 return kConfigAttribs; |
| 103 } |
| 104 |
| 105 bool GbmSurfaceFactory::LoadEGLGLES2Bindings( |
| 106 AddGLLibraryCallback add_gl_library, |
| 107 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { |
| 108 base::NativeLibraryLoadError error; |
| 109 base::NativeLibrary gles_library = base::LoadNativeLibrary( |
| 110 base::FilePath("libGLESv2.so.2"), |
| 111 &error); |
| 112 if (!gles_library) { |
| 113 LOG(WARNING) << "Failed to load GLES library: " << error.ToString(); |
| 114 return false; |
| 115 } |
| 116 |
| 117 base::NativeLibrary egl_library = base::LoadNativeLibrary( |
| 118 base::FilePath("libEGL.so.1"), |
| 119 &error); |
| 120 if (!egl_library) { |
| 121 LOG(WARNING) << "Failed to load EGL library: " << error.ToString(); |
| 122 base::UnloadNativeLibrary(gles_library); |
| 123 return false; |
| 124 } |
| 125 |
| 126 GLGetProcAddressProc get_proc_address = |
| 127 reinterpret_cast<GLGetProcAddressProc>( |
| 128 base::GetFunctionPointerFromNativeLibrary( |
| 129 egl_library, "eglGetProcAddress")); |
| 130 if (!get_proc_address) { |
| 131 LOG(ERROR) << "eglGetProcAddress not found."; |
| 132 base::UnloadNativeLibrary(egl_library); |
| 133 base::UnloadNativeLibrary(gles_library); |
| 134 return false; |
| 135 } |
| 136 |
| 137 set_gl_get_proc_address.Run(get_proc_address); |
| 138 add_gl_library.Run(egl_library); |
| 139 add_gl_library.Run(gles_library); |
| 140 |
| 141 return true; |
| 142 } |
| 143 |
| 144 scoped_ptr<gfx::SurfaceOzoneEGL> GbmSurfaceFactory::CreateEGLSurfaceForWidget( |
| 145 gfx::AcceleratedWidget w) { |
| 146 CHECK(state_ == INITIALIZED); |
| 147 ResetCursor(w); |
| 148 |
| 149 return scoped_ptr<gfx::SurfaceOzoneEGL>( |
| 150 new GbmSurfaceAdapter(screen_manager_->GetDisplayController(w))); |
| 151 } |
| 152 |
| 153 } // namespace ui |
OLD | NEW |