| 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/buffer_data.h" | 11 #include "ui/ozone/platform/dri/buffer_data.h" |
| 12 #include "ui/ozone/platform/dri/dri_vsync_provider.h" | 12 #include "ui/ozone/platform/dri/dri_vsync_provider.h" |
| 13 #include "ui/ozone/platform/dri/gbm_buffer.h" | 13 #include "ui/ozone/platform/dri/gbm_buffer.h" |
| 14 #include "ui/ozone/platform/dri/gbm_surface.h" | 14 #include "ui/ozone/platform/dri/gbm_surface.h" |
| 15 #include "ui/ozone/platform/dri/hardware_display_controller.h" | 15 #include "ui/ozone/platform/dri/hardware_display_controller.h" |
| 16 #include "ui/ozone/platform/dri/scanout_surface.h" | 16 #include "ui/ozone/platform/dri/scanout_surface.h" |
| 17 #include "ui/ozone/platform/dri/screen_manager.h" | 17 #include "ui/ozone/platform/dri/screen_manager.h" |
| 18 #include "ui/ozone/public/native_pixmap.h" |
| 18 #include "ui/ozone/public/surface_ozone_egl.h" | 19 #include "ui/ozone/public/surface_ozone_egl.h" |
| 19 | 20 |
| 20 namespace ui { | 21 namespace ui { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 class GbmSurfaceAdapter : public ui::SurfaceOzoneEGL { | 25 class GbmSurfaceAdapter : public ui::SurfaceOzoneEGL { |
| 25 public: | 26 public: |
| 26 GbmSurfaceAdapter(const base::WeakPtr<HardwareDisplayController>& controller); | 27 GbmSurfaceAdapter(const base::WeakPtr<HardwareDisplayController>& controller); |
| 27 virtual ~GbmSurfaceAdapter(); | 28 virtual ~GbmSurfaceAdapter(); |
| 28 | 29 |
| 29 // SurfaceOzoneEGL: | 30 // SurfaceOzoneEGL: |
| 30 virtual intptr_t GetNativeWindow() OVERRIDE; | 31 virtual intptr_t GetNativeWindow() OVERRIDE; |
| 31 virtual bool ResizeNativeWindow(const gfx::Size& viewport_size) OVERRIDE; | 32 virtual bool ResizeNativeWindow(const gfx::Size& viewport_size) OVERRIDE; |
| 32 virtual bool OnSwapBuffers() OVERRIDE; | 33 virtual bool OnSwapBuffers() OVERRIDE; |
| 33 virtual scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() OVERRIDE; | 34 virtual scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() OVERRIDE; |
| 34 virtual bool ScheduleOverlayPlane(int plane_z_order, | 35 virtual bool ScheduleOverlayPlane(int plane_z_order, |
| 35 gfx::OverlayTransform plane_transform, | 36 gfx::OverlayTransform plane_transform, |
| 36 scoped_refptr<ui::NativePixmap> buffer, | 37 scoped_refptr<ui::NativePixmap> buffer, |
| 37 const gfx::Rect& display_bounds, | 38 const gfx::Rect& display_bounds, |
| 38 const gfx::RectF& crop_rect) OVERRIDE; | 39 const gfx::RectF& crop_rect) OVERRIDE; |
| 39 | 40 |
| 40 private: | 41 private: |
| 41 base::WeakPtr<HardwareDisplayController> controller_; | 42 base::WeakPtr<HardwareDisplayController> controller_; |
| 43 NativePixmapList overlay_refs_; |
| 44 std::vector<OzoneOverlayPlane> overlays_; |
| 42 | 45 |
| 43 DISALLOW_COPY_AND_ASSIGN(GbmSurfaceAdapter); | 46 DISALLOW_COPY_AND_ASSIGN(GbmSurfaceAdapter); |
| 44 }; | 47 }; |
| 45 | 48 |
| 46 GbmSurfaceAdapter::GbmSurfaceAdapter( | 49 GbmSurfaceAdapter::GbmSurfaceAdapter( |
| 47 const base::WeakPtr<HardwareDisplayController>& controller) | 50 const base::WeakPtr<HardwareDisplayController>& controller) |
| 48 : controller_(controller) {} | 51 : controller_(controller) {} |
| 49 | 52 |
| 50 GbmSurfaceAdapter::~GbmSurfaceAdapter() {} | 53 GbmSurfaceAdapter::~GbmSurfaceAdapter() {} |
| 51 | 54 |
| 52 intptr_t GbmSurfaceAdapter::GetNativeWindow() { | 55 intptr_t GbmSurfaceAdapter::GetNativeWindow() { |
| 53 if (!controller_) | 56 if (!controller_) |
| 54 return 0; | 57 return 0; |
| 55 | 58 |
| 56 return reinterpret_cast<intptr_t>( | 59 return reinterpret_cast<intptr_t>( |
| 57 static_cast<GbmSurface*>(controller_->surface())->native_surface()); | 60 static_cast<GbmSurface*>(controller_->surface())->native_surface()); |
| 58 } | 61 } |
| 59 | 62 |
| 60 bool GbmSurfaceAdapter::ResizeNativeWindow(const gfx::Size& viewport_size) { | 63 bool GbmSurfaceAdapter::ResizeNativeWindow(const gfx::Size& viewport_size) { |
| 61 NOTIMPLEMENTED(); | 64 NOTIMPLEMENTED(); |
| 62 return false; | 65 return false; |
| 63 } | 66 } |
| 64 | 67 |
| 65 bool GbmSurfaceAdapter::OnSwapBuffers() { | 68 bool GbmSurfaceAdapter::OnSwapBuffers() { |
| 66 if (!controller_) | 69 if (!controller_) |
| 67 return false; | 70 return false; |
| 68 | 71 bool flip_succeeded = |
| 69 static_cast<GbmSurface*>(controller_->surface())->LockCurrentDrawable(); | 72 controller_->SchedulePageFlip(overlays_, &overlay_refs_); |
| 70 if (controller_->SchedulePageFlip()) { | 73 overlays_.clear(); |
| 74 if (flip_succeeded) |
| 71 controller_->WaitForPageFlipEvent(); | 75 controller_->WaitForPageFlipEvent(); |
| 72 return true; | 76 return flip_succeeded; |
| 73 } | |
| 74 | |
| 75 return false; | |
| 76 } | 77 } |
| 77 | 78 |
| 78 bool GbmSurfaceAdapter::ScheduleOverlayPlane( | 79 bool GbmSurfaceAdapter::ScheduleOverlayPlane( |
| 79 int plane_z_order, | 80 int plane_z_order, |
| 80 gfx::OverlayTransform plane_transform, | 81 gfx::OverlayTransform plane_transform, |
| 81 scoped_refptr<ui::NativePixmap> buffer, | 82 scoped_refptr<NativePixmap> buffer, |
| 82 const gfx::Rect& display_bounds, | 83 const gfx::Rect& display_bounds, |
| 83 const gfx::RectF& crop_rect) { | 84 const gfx::RectF& crop_rect) { |
| 84 NOTIMPLEMENTED(); | 85 GbmPixmap* pixmap = static_cast<GbmPixmap*>(buffer.get()); |
| 85 return false; | 86 if (!pixmap) { |
| 87 LOG(ERROR) << "ScheduleOverlayPlane passed NULL buffer"; |
| 88 return false; |
| 89 } |
| 90 overlays_.push_back(OzoneOverlayPlane(pixmap->buffer(), |
| 91 plane_z_order, |
| 92 plane_transform, |
| 93 display_bounds, |
| 94 crop_rect)); |
| 95 overlay_refs_.push_back(buffer); |
| 96 return true; |
| 86 } | 97 } |
| 87 | 98 |
| 88 scoped_ptr<gfx::VSyncProvider> GbmSurfaceAdapter::CreateVSyncProvider() { | 99 scoped_ptr<gfx::VSyncProvider> GbmSurfaceAdapter::CreateVSyncProvider() { |
| 89 return scoped_ptr<gfx::VSyncProvider>(new DriVSyncProvider(controller_)); | 100 return scoped_ptr<gfx::VSyncProvider>(new DriVSyncProvider(controller_)); |
| 90 } | 101 } |
| 91 | 102 |
| 92 } // namespace | 103 } // namespace |
| 93 | 104 |
| 94 GbmSurfaceFactory::GbmSurfaceFactory() | 105 GbmSurfaceFactory::GbmSurfaceFactory(bool allow_surfaceless) |
| 95 : DriSurfaceFactory(NULL, NULL), | 106 : DriSurfaceFactory(NULL, NULL), |
| 96 device_(NULL) {} | 107 device_(NULL), |
| 108 allow_surfaceless_(allow_surfaceless) { |
| 109 } |
| 97 | 110 |
| 98 GbmSurfaceFactory::~GbmSurfaceFactory() {} | 111 GbmSurfaceFactory::~GbmSurfaceFactory() {} |
| 99 | 112 |
| 100 void GbmSurfaceFactory::InitializeGpu( | 113 void GbmSurfaceFactory::InitializeGpu( |
| 101 DriWrapper* dri, gbm_device* device, ScreenManager* screen_manager) { | 114 DriWrapper* dri, gbm_device* device, ScreenManager* screen_manager) { |
| 102 drm_ = dri; | 115 drm_ = dri; |
| 103 device_ = device; | 116 device_ = device; |
| 104 screen_manager_ = screen_manager; | 117 screen_manager_ = screen_manager; |
| 105 } | 118 } |
| 106 | 119 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 CHECK(state_ == INITIALIZED); | 182 CHECK(state_ == INITIALIZED); |
| 170 ResetCursor(w); | 183 ResetCursor(w); |
| 171 | 184 |
| 172 return scoped_ptr<ui::SurfaceOzoneEGL>( | 185 return scoped_ptr<ui::SurfaceOzoneEGL>( |
| 173 new GbmSurfaceAdapter(screen_manager_->GetDisplayController(w))); | 186 new GbmSurfaceAdapter(screen_manager_->GetDisplayController(w))); |
| 174 } | 187 } |
| 175 | 188 |
| 176 scoped_refptr<ui::NativePixmap> GbmSurfaceFactory::CreateNativePixmap( | 189 scoped_refptr<ui::NativePixmap> GbmSurfaceFactory::CreateNativePixmap( |
| 177 gfx::Size size, | 190 gfx::Size size, |
| 178 BufferFormat format) { | 191 BufferFormat format) { |
| 179 scoped_refptr<GbmBuffer> buf = new GbmBuffer(device_, drm_, size); | 192 scoped_refptr<GbmPixmap> buf = new GbmPixmap(device_, drm_, size); |
| 180 if (!buf->InitializeBuffer(format, true)) { | 193 if (!buf->buffer()->InitializeBuffer(format, true)) { |
| 181 return NULL; | 194 return NULL; |
| 182 } | 195 } |
| 183 return buf; | 196 return buf; |
| 184 } | 197 } |
| 185 | 198 |
| 199 bool GbmSurfaceFactory::CanShowPrimaryPlaneAsOverlay() { |
| 200 return allow_surfaceless_; |
| 201 } |
| 202 |
| 186 } // namespace ui | 203 } // namespace ui |
| OLD | NEW |