| 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/drm/gpu/drm_surface.h" | 5 #include "ui/ozone/platform/drm/gpu/drm_surface.h" |
| 6 | 6 |
| 7 #include "base/bind_helpers.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "third_party/skia/include/core/SkCanvas.h" | 10 #include "third_party/skia/include/core/SkCanvas.h" |
| 11 #include "third_party/skia/include/core/SkSurface.h" | 11 #include "third_party/skia/include/core/SkSurface.h" |
| 12 #include "ui/gfx/geometry/rect.h" | 12 #include "ui/gfx/geometry/rect.h" |
| 13 #include "ui/gfx/skia_util.h" | 13 #include "ui/gfx/skia_util.h" |
| 14 #include "ui/ozone/platform/drm/gpu/drm_buffer.h" | 14 #include "ui/ozone/platform/drm/gpu/drm_buffer.h" |
| 15 #include "ui/ozone/platform/drm/gpu/drm_device.h" | 15 #include "ui/ozone/platform/drm/gpu/drm_device.h" |
| 16 #include "ui/ozone/platform/drm/gpu/drm_vsync_provider.h" | 16 #include "ui/ozone/platform/drm/gpu/drm_vsync_provider.h" |
| 17 #include "ui/ozone/platform/drm/gpu/drm_window.h" | 17 #include "ui/ozone/platform/drm/gpu/drm_window_proxy.h" |
| 18 #include "ui/ozone/platform/drm/gpu/hardware_display_controller.h" | 18 #include "ui/ozone/platform/drm/gpu/hardware_display_controller.h" |
| 19 | 19 |
| 20 namespace ui { | 20 namespace ui { |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 scoped_refptr<DrmBuffer> AllocateBuffer(const scoped_refptr<DrmDevice>& drm, | 24 scoped_refptr<DrmBuffer> AllocateBuffer(const scoped_refptr<DrmDevice>& drm, |
| 25 const gfx::Size& size) { | 25 const gfx::Size& size) { |
| 26 scoped_refptr<DrmBuffer> buffer(new DrmBuffer(drm)); | 26 scoped_refptr<DrmBuffer> buffer(new DrmBuffer(drm)); |
| 27 SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.height()); | 27 SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.height()); |
| 28 | 28 |
| 29 bool initialized = | 29 bool initialized = |
| 30 buffer->Initialize(info, true /* should_register_framebuffer */); | 30 buffer->Initialize(info, true /* should_register_framebuffer */); |
| 31 DCHECK(initialized) << "Failed to create drm buffer."; | 31 DCHECK(initialized) << "Failed to create drm buffer."; |
| 32 | 32 |
| 33 return buffer; | 33 return buffer; |
| 34 } | 34 } |
| 35 | 35 |
| 36 } // namespace | 36 } // namespace |
| 37 | 37 |
| 38 DrmSurface::DrmSurface(DrmWindow* window) | 38 DrmSurface::DrmSurface(scoped_ptr<DrmWindowProxy> window) |
| 39 : window_(window), weak_ptr_factory_(this) { | 39 : window_(window.Pass()), weak_ptr_factory_(this) {} |
| 40 } | |
| 41 | 40 |
| 42 DrmSurface::~DrmSurface() { | 41 DrmSurface::~DrmSurface() { |
| 43 } | 42 } |
| 44 | 43 |
| 45 skia::RefPtr<SkSurface> DrmSurface::GetSurface() { | 44 skia::RefPtr<SkSurface> DrmSurface::GetSurface() { |
| 46 return surface_; | 45 return surface_; |
| 47 } | 46 } |
| 48 | 47 |
| 49 void DrmSurface::ResizeCanvas(const gfx::Size& viewport_size) { | 48 void DrmSurface::ResizeCanvas(const gfx::Size& viewport_size) { |
| 50 SkImageInfo info = SkImageInfo::MakeN32( | 49 SkImageInfo info = SkImageInfo::MakeN32( |
| 51 viewport_size.width(), viewport_size.height(), kOpaque_SkAlphaType); | 50 viewport_size.width(), viewport_size.height(), kOpaque_SkAlphaType); |
| 52 surface_ = skia::AdoptRef(SkSurface::NewRaster(info)); | 51 surface_ = skia::AdoptRef(SkSurface::NewRaster(info)); |
| 53 | 52 |
| 54 HardwareDisplayController* controller = window_->GetController(); | 53 scoped_refptr<DrmDevice> drm = window_->GetDrmDevice(); |
| 55 if (!controller) | 54 if (!drm) |
| 56 return; | 55 return; |
| 57 | 56 |
| 58 // For the display buffers use the mode size since a |viewport_size| smaller | 57 // For the display buffers use the mode size since a |viewport_size| smaller |
| 59 // than the display size will not scanout. | 58 // than the display size will not scanout. |
| 60 front_buffer_ = AllocateBuffer(controller->GetAllocationDrmDevice(), | 59 front_buffer_ = AllocateBuffer(drm, window_->GetBounds().size()); |
| 61 controller->GetModeSize()); | 60 back_buffer_ = AllocateBuffer(drm, window_->GetBounds().size()); |
| 62 back_buffer_ = AllocateBuffer(controller->GetAllocationDrmDevice(), | |
| 63 controller->GetModeSize()); | |
| 64 } | 61 } |
| 65 | 62 |
| 66 void DrmSurface::PresentCanvas(const gfx::Rect& damage) { | 63 void DrmSurface::PresentCanvas(const gfx::Rect& damage) { |
| 67 DCHECK(base::MessageLoopForUI::IsCurrent()); | 64 DCHECK(base::MessageLoopForUI::IsCurrent()); |
| 68 | 65 |
| 69 // Create a snapshot of the requested drawing. If we get here again before | 66 // Create a snapshot of the requested drawing. If we get here again before |
| 70 // presenting, just add the additional damage. | 67 // presenting, just add the additional damage. |
| 71 pending_image_damage_.Union(damage); | 68 pending_image_damage_.Union(damage); |
| 72 pending_image_ = skia::AdoptRef(surface_->newImageSnapshot()); | 69 pending_image_ = skia::AdoptRef(surface_->newImageSnapshot()); |
| 73 | 70 |
| 74 if (!pending_pageflip_) | 71 if (!pending_pageflip_) |
| 75 SchedulePageFlip(); | 72 SchedulePageFlip(); |
| 76 } | 73 } |
| 77 | 74 |
| 78 scoped_ptr<gfx::VSyncProvider> DrmSurface::CreateVSyncProvider() { | 75 scoped_ptr<gfx::VSyncProvider> DrmSurface::CreateVSyncProvider() { |
| 79 return make_scoped_ptr(new DrmVSyncProvider(window_)); | 76 return make_scoped_ptr(new DrmVSyncProvider(window_.get())); |
| 80 } | 77 } |
| 81 | 78 |
| 82 void DrmSurface::SchedulePageFlip() { | 79 void DrmSurface::SchedulePageFlip() { |
| 83 DCHECK(back_buffer_); | 80 DCHECK(back_buffer_); |
| 84 SkCanvas* canvas = back_buffer_->GetCanvas(); | 81 SkCanvas* canvas = back_buffer_->GetCanvas(); |
| 85 | 82 |
| 86 // The DrmSurface is double buffered, so the current back buffer is | 83 // The DrmSurface is double buffered, so the current back buffer is |
| 87 // missing the previous update. Expand damage region. | 84 // missing the previous update. Expand damage region. |
| 88 SkRect real_damage = | 85 SkRect real_damage = |
| 89 RectToSkRect(UnionRects(pending_image_damage_, last_damage_)); | 86 RectToSkRect(UnionRects(pending_image_damage_, last_damage_)); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 106 | 103 |
| 107 void DrmSurface::OnPageFlip(gfx::SwapResult result) { | 104 void DrmSurface::OnPageFlip(gfx::SwapResult result) { |
| 108 pending_pageflip_ = false; | 105 pending_pageflip_ = false; |
| 109 if (!pending_image_) | 106 if (!pending_image_) |
| 110 return; | 107 return; |
| 111 | 108 |
| 112 SchedulePageFlip(); | 109 SchedulePageFlip(); |
| 113 } | 110 } |
| 114 | 111 |
| 115 } // namespace ui | 112 } // namespace ui |
| OLD | NEW |