Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: ui/ozone/platform/drm/gpu/drm_surface.cc

Issue 1350473002: Revert of ozone: Remove the "drm" software composited platform (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/drm/gpu/drm_surface.h"
6
7 #include "base/bind_helpers.h"
8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h"
10 #include "third_party/skia/include/core/SkCanvas.h"
11 #include "third_party/skia/include/core/SkSurface.h"
12 #include "ui/gfx/geometry/rect.h"
13 #include "ui/gfx/skia_util.h"
14 #include "ui/ozone/platform/drm/gpu/drm_buffer.h"
15 #include "ui/ozone/platform/drm/gpu/drm_device.h"
16 #include "ui/ozone/platform/drm/gpu/drm_vsync_provider.h"
17 #include "ui/ozone/platform/drm/gpu/drm_window.h"
18 #include "ui/ozone/platform/drm/gpu/hardware_display_controller.h"
19
20 namespace ui {
21
22 namespace {
23
24 scoped_refptr<DrmBuffer> AllocateBuffer(const scoped_refptr<DrmDevice>& drm,
25 const gfx::Size& size) {
26 scoped_refptr<DrmBuffer> buffer(new DrmBuffer(drm));
27 SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.height());
28
29 bool initialized =
30 buffer->Initialize(info, true /* should_register_framebuffer */);
31 DCHECK(initialized) << "Failed to create drm buffer.";
32
33 return buffer;
34 }
35
36 } // namespace
37
38 DrmSurface::DrmSurface(DrmWindow* window)
39 : window_(window), weak_ptr_factory_(this) {
40 }
41
42 DrmSurface::~DrmSurface() {
43 }
44
45 skia::RefPtr<SkSurface> DrmSurface::GetSurface() {
46 return surface_;
47 }
48
49 void DrmSurface::ResizeCanvas(const gfx::Size& viewport_size) {
50 SkImageInfo info = SkImageInfo::MakeN32(
51 viewport_size.width(), viewport_size.height(), kOpaque_SkAlphaType);
52 surface_ = skia::AdoptRef(SkSurface::NewRaster(info));
53
54 HardwareDisplayController* controller = window_->GetController();
55 if (!controller)
56 return;
57
58 // For the display buffers use the mode size since a |viewport_size| smaller
59 // than the display size will not scanout.
60 front_buffer_ = AllocateBuffer(controller->GetAllocationDrmDevice(),
61 controller->GetModeSize());
62 back_buffer_ = AllocateBuffer(controller->GetAllocationDrmDevice(),
63 controller->GetModeSize());
64 }
65
66 void DrmSurface::PresentCanvas(const gfx::Rect& damage) {
67 DCHECK(base::MessageLoopForUI::IsCurrent());
68
69 // Create a snapshot of the requested drawing. If we get here again before
70 // presenting, just add the additional damage.
71 pending_image_damage_.Union(damage);
72 pending_image_ = skia::AdoptRef(surface_->newImageSnapshot());
73
74 if (!pending_pageflip_)
75 SchedulePageFlip();
76 }
77
78 scoped_ptr<gfx::VSyncProvider> DrmSurface::CreateVSyncProvider() {
79 return make_scoped_ptr(new DrmVSyncProvider(window_));
80 }
81
82 void DrmSurface::SchedulePageFlip() {
83 DCHECK(back_buffer_);
84 SkCanvas* canvas = back_buffer_->GetCanvas();
85
86 // The DrmSurface is double buffered, so the current back buffer is
87 // missing the previous update. Expand damage region.
88 SkRect real_damage =
89 RectToSkRect(UnionRects(pending_image_damage_, last_damage_));
90
91 // Copy damage region.
92 canvas->drawImageRect(pending_image_.get(), real_damage, real_damage, NULL);
93 last_damage_ = pending_image_damage_;
94
95 pending_image_ = nullptr;
96 pending_image_damage_ = gfx::Rect();
97
98 window_->QueueOverlayPlane(OverlayPlane(back_buffer_));
99
100 // Update our front buffer pointer.
101 std::swap(front_buffer_, back_buffer_);
102 // First set the pending flag otherwise there could be a re-entrancy issue if
103 // the callback is executed synchronously.
104 pending_pageflip_ = true;
105 if (!window_->SchedulePageFlip(false /* is_sync */,
106 base::Bind(&DrmSurface::OnPageFlip,
107 weak_ptr_factory_.GetWeakPtr()))) {
108 pending_pageflip_ = false;
109 }
110 }
111
112 void DrmSurface::OnPageFlip(gfx::SwapResult result) {
113 pending_pageflip_ = false;
114 if (!pending_image_)
115 return;
116
117 SchedulePageFlip();
118 }
119
120 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/drm/gpu/drm_surface.h ('k') | ui/ozone/platform/drm/gpu/drm_surface_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698