| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/ozone/platform/dri/gbm_surface_factory.h" | 5 #include "ui/ozone/platform/dri/gbm_surface_factory.h" |
| 6 | 6 |
| 7 #include <EGL/egl.h> | 7 #include <EGL/egl.h> |
| 8 #include <gbm.h> | 8 #include <gbm.h> |
| 9 | 9 |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "ui/ozone/platform/dri/dri_vsync_provider.h" | 11 #include "ui/ozone/platform/dri/dri_vsync_provider.h" |
| 12 #include "ui/ozone/platform/dri/gbm_buffer.h" | 12 #include "ui/ozone/platform/dri/gbm_buffer.h" |
| 13 #include "ui/ozone/platform/dri/gbm_surface.h" | 13 #include "ui/ozone/platform/dri/gbm_surface.h" |
| 14 #include "ui/ozone/platform/dri/hardware_display_controller.h" | 14 #include "ui/ozone/platform/dri/hardware_display_controller.h" |
| 15 #include "ui/ozone/platform/dri/scanout_surface.h" | 15 #include "ui/ozone/platform/dri/scanout_surface.h" |
| 16 #include "ui/ozone/platform/dri/screen_manager.h" | 16 #include "ui/ozone/platform/dri/screen_manager.h" |
| 17 #include "ui/ozone/public/native_pixmap.h" | 17 #include "ui/ozone/public/native_pixmap.h" |
| 18 #include "ui/ozone/public/surface_ozone_egl.h" | 18 #include "ui/ozone/public/surface_ozone_egl.h" |
| 19 | 19 |
| 20 namespace ui { | 20 namespace ui { |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 class GbmSurfaceAdapter : public ui::SurfaceOzoneEGL { | 24 class GbmSurfaceAdapter : public ui::SurfaceOzoneEGL { |
| 25 public: | 25 public: |
| 26 GbmSurfaceAdapter(const base::WeakPtr<HardwareDisplayController>& controller); | 26 GbmSurfaceAdapter( |
| 27 gbm_device* device, |
| 28 DriWrapper* dri, |
| 29 const base::WeakPtr<HardwareDisplayController>& controller); |
| 27 virtual ~GbmSurfaceAdapter(); | 30 virtual ~GbmSurfaceAdapter(); |
| 28 | 31 |
| 32 bool Initialize(); |
| 33 |
| 29 // SurfaceOzoneEGL: | 34 // SurfaceOzoneEGL: |
| 30 virtual intptr_t GetNativeWindow() OVERRIDE; | 35 virtual intptr_t GetNativeWindow() OVERRIDE; |
| 31 virtual bool ResizeNativeWindow(const gfx::Size& viewport_size) OVERRIDE; | 36 virtual bool ResizeNativeWindow(const gfx::Size& viewport_size) OVERRIDE; |
| 32 virtual bool OnSwapBuffers() OVERRIDE; | 37 virtual bool OnSwapBuffers() OVERRIDE; |
| 33 virtual scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() OVERRIDE; | 38 virtual scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() OVERRIDE; |
| 34 virtual bool ScheduleOverlayPlane(int plane_z_order, | 39 virtual bool ScheduleOverlayPlane(int plane_z_order, |
| 35 gfx::OverlayTransform plane_transform, | 40 gfx::OverlayTransform plane_transform, |
| 36 scoped_refptr<ui::NativePixmap> buffer, | 41 scoped_refptr<ui::NativePixmap> buffer, |
| 37 const gfx::Rect& display_bounds, | 42 const gfx::Rect& display_bounds, |
| 38 const gfx::RectF& crop_rect) OVERRIDE; | 43 const gfx::RectF& crop_rect) OVERRIDE; |
| 39 | 44 |
| 40 private: | 45 private: |
| 46 gbm_device* device_; |
| 47 DriWrapper* dri_; |
| 48 scoped_ptr<GbmSurface> surface_; |
| 41 base::WeakPtr<HardwareDisplayController> controller_; | 49 base::WeakPtr<HardwareDisplayController> controller_; |
| 42 NativePixmapList overlay_refs_; | 50 OverlayPlaneList overlays_; |
| 43 std::vector<OzoneOverlayPlane> overlays_; | |
| 44 | 51 |
| 45 DISALLOW_COPY_AND_ASSIGN(GbmSurfaceAdapter); | 52 DISALLOW_COPY_AND_ASSIGN(GbmSurfaceAdapter); |
| 46 }; | 53 }; |
| 47 | 54 |
| 48 GbmSurfaceAdapter::GbmSurfaceAdapter( | 55 GbmSurfaceAdapter::GbmSurfaceAdapter( |
| 56 gbm_device* device, |
| 57 DriWrapper* dri, |
| 49 const base::WeakPtr<HardwareDisplayController>& controller) | 58 const base::WeakPtr<HardwareDisplayController>& controller) |
| 50 : controller_(controller) {} | 59 : device_(device), dri_(dri), controller_(controller) {} |
| 51 | 60 |
| 52 GbmSurfaceAdapter::~GbmSurfaceAdapter() {} | 61 GbmSurfaceAdapter::~GbmSurfaceAdapter() {} |
| 53 | 62 |
| 63 bool GbmSurfaceAdapter::Initialize() { |
| 64 if (controller_) { |
| 65 surface_.reset( |
| 66 new GbmSurface(device_, |
| 67 dri_, |
| 68 gfx::Size(controller_->get_mode().hdisplay, |
| 69 controller_->get_mode().vdisplay))); |
| 70 return surface_->Initialize(); |
| 71 } |
| 72 |
| 73 return false; |
| 74 } |
| 75 |
| 54 intptr_t GbmSurfaceAdapter::GetNativeWindow() { | 76 intptr_t GbmSurfaceAdapter::GetNativeWindow() { |
| 55 if (!controller_) | 77 if (!controller_) |
| 56 return 0; | 78 return 0; |
| 57 | 79 |
| 58 return reinterpret_cast<intptr_t>( | 80 return reinterpret_cast<intptr_t>(surface_->native_surface()); |
| 59 static_cast<GbmSurface*>(controller_->surface())->native_surface()); | |
| 60 } | 81 } |
| 61 | 82 |
| 62 bool GbmSurfaceAdapter::ResizeNativeWindow(const gfx::Size& viewport_size) { | 83 bool GbmSurfaceAdapter::ResizeNativeWindow(const gfx::Size& viewport_size) { |
| 63 NOTIMPLEMENTED(); | 84 |
| 64 return false; | 85 return true; |
| 65 } | 86 } |
| 66 | 87 |
| 67 bool GbmSurfaceAdapter::OnSwapBuffers() { | 88 bool GbmSurfaceAdapter::OnSwapBuffers() { |
| 68 if (!controller_) | 89 if (!controller_) |
| 69 return false; | 90 return false; |
| 70 bool flip_succeeded = | 91 if (surface_) { |
| 71 controller_->SchedulePageFlip(overlays_, &overlay_refs_); | 92 surface_->PreSwapBuffers(); |
| 93 overlays_.push_back(OverlayPlane(surface_->backbuffer())); |
| 94 } |
| 95 |
| 96 bool flip_succeeded = controller_->SchedulePageFlip(overlays_); |
| 72 overlays_.clear(); | 97 overlays_.clear(); |
| 73 if (flip_succeeded) | 98 if (flip_succeeded) |
| 74 controller_->WaitForPageFlipEvent(); | 99 controller_->WaitForPageFlipEvent(); |
| 100 |
| 101 if (surface_) |
| 102 surface_->SwapBuffers(); |
| 103 |
| 75 return flip_succeeded; | 104 return flip_succeeded; |
| 76 } | 105 } |
| 77 | 106 |
| 78 bool GbmSurfaceAdapter::ScheduleOverlayPlane( | 107 bool GbmSurfaceAdapter::ScheduleOverlayPlane( |
| 79 int plane_z_order, | 108 int plane_z_order, |
| 80 gfx::OverlayTransform plane_transform, | 109 gfx::OverlayTransform plane_transform, |
| 81 scoped_refptr<NativePixmap> buffer, | 110 scoped_refptr<NativePixmap> buffer, |
| 82 const gfx::Rect& display_bounds, | 111 const gfx::Rect& display_bounds, |
| 83 const gfx::RectF& crop_rect) { | 112 const gfx::RectF& crop_rect) { |
| 84 GbmPixmap* pixmap = static_cast<GbmPixmap*>(buffer.get()); | 113 GbmPixmap* pixmap = static_cast<GbmPixmap*>(buffer.get()); |
| 85 if (!pixmap) { | 114 if (!pixmap) { |
| 86 LOG(ERROR) << "ScheduleOverlayPlane passed NULL buffer"; | 115 LOG(ERROR) << "ScheduleOverlayPlane passed NULL buffer"; |
| 87 return false; | 116 return false; |
| 88 } | 117 } |
| 89 overlays_.push_back(OzoneOverlayPlane(pixmap->buffer(), | 118 overlays_.push_back(OverlayPlane(pixmap->buffer(), |
| 90 plane_z_order, | 119 plane_z_order, |
| 91 plane_transform, | 120 plane_transform, |
| 92 display_bounds, | 121 display_bounds, |
| 93 crop_rect)); | 122 crop_rect)); |
| 94 overlay_refs_.push_back(buffer); | |
| 95 return true; | 123 return true; |
| 96 } | 124 } |
| 97 | 125 |
| 98 scoped_ptr<gfx::VSyncProvider> GbmSurfaceAdapter::CreateVSyncProvider() { | 126 scoped_ptr<gfx::VSyncProvider> GbmSurfaceAdapter::CreateVSyncProvider() { |
| 99 return scoped_ptr<gfx::VSyncProvider>(new DriVSyncProvider(controller_)); | 127 return scoped_ptr<gfx::VSyncProvider>(new DriVSyncProvider(controller_)); |
| 100 } | 128 } |
| 101 | 129 |
| 102 } // namespace | 130 } // namespace |
| 103 | 131 |
| 104 GbmSurfaceFactory::GbmSurfaceFactory(bool allow_surfaceless) | 132 GbmSurfaceFactory::GbmSurfaceFactory(bool allow_surfaceless) |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 add_gl_library.Run(gles_library); | 202 add_gl_library.Run(gles_library); |
| 175 | 203 |
| 176 return true; | 204 return true; |
| 177 } | 205 } |
| 178 | 206 |
| 179 scoped_ptr<ui::SurfaceOzoneEGL> GbmSurfaceFactory::CreateEGLSurfaceForWidget( | 207 scoped_ptr<ui::SurfaceOzoneEGL> GbmSurfaceFactory::CreateEGLSurfaceForWidget( |
| 180 gfx::AcceleratedWidget w) { | 208 gfx::AcceleratedWidget w) { |
| 181 CHECK(state_ == INITIALIZED); | 209 CHECK(state_ == INITIALIZED); |
| 182 ResetCursor(w); | 210 ResetCursor(w); |
| 183 | 211 |
| 184 return scoped_ptr<ui::SurfaceOzoneEGL>( | 212 scoped_ptr<GbmSurfaceAdapter> surface( |
| 185 new GbmSurfaceAdapter(screen_manager_->GetDisplayController(w))); | 213 new GbmSurfaceAdapter(device_, |
| 214 drm_, |
| 215 screen_manager_->GetDisplayController(w))); |
| 216 if (!allow_surfaceless_ && !surface->Initialize()) |
| 217 return scoped_ptr<SurfaceOzoneEGL>(); |
| 218 |
| 219 return surface.PassAs<SurfaceOzoneEGL>(); |
| 186 } | 220 } |
| 187 | 221 |
| 188 scoped_refptr<ui::NativePixmap> GbmSurfaceFactory::CreateNativePixmap( | 222 scoped_refptr<ui::NativePixmap> GbmSurfaceFactory::CreateNativePixmap( |
| 189 gfx::Size size, | 223 gfx::Size size, |
| 190 BufferFormat format) { | 224 BufferFormat format) { |
| 191 scoped_refptr<GbmPixmap> buf = new GbmPixmap(device_, drm_, size); | 225 scoped_refptr<GbmBuffer> buffer = GbmBuffer::CreateBuffer( |
| 192 if (!buf->buffer()->InitializeBuffer(format, true)) { | 226 drm_, device_, format, size, true); |
| 227 if (!buffer) |
| 193 return NULL; | 228 return NULL; |
| 194 } | 229 |
| 195 return buf; | 230 return scoped_refptr<GbmPixmap>(new GbmPixmap(buffer)); |
| 196 } | 231 } |
| 197 | 232 |
| 198 bool GbmSurfaceFactory::CanShowPrimaryPlaneAsOverlay() { | 233 bool GbmSurfaceFactory::CanShowPrimaryPlaneAsOverlay() { |
| 199 return allow_surfaceless_; | 234 return allow_surfaceless_; |
| 200 } | 235 } |
| 201 | 236 |
| 202 } // namespace ui | 237 } // namespace ui |
| OLD | NEW |