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

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

Issue 1285183008: Ozone integration. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: add missing license header Created 5 years, 4 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_delegate)
39 : window_delegate_(window_delegate),
40 weak_ptr_factory_(this) {
41 }
42
43 DrmSurface::~DrmSurface() {
44 }
45
46 skia::RefPtr<SkSurface> DrmSurface::GetSurface() {
47 return surface_;
48 }
49
50 void DrmSurface::ResizeCanvas(const gfx::Size& viewport_size) {
51 SkImageInfo info = SkImageInfo::MakeN32(
52 viewport_size.width(), viewport_size.height(), kOpaque_SkAlphaType);
53 surface_ = skia::AdoptRef(SkSurface::NewRaster(info));
54
55 HardwareDisplayController* controller = window_delegate_->GetController();
56 if (!controller)
57 return;
58
59 // For the display buffers use the mode size since a |viewport_size| smaller
60 // than the display size will not scanout.
61 front_buffer_ = AllocateBuffer(controller->GetAllocationDrmDevice(),
62 controller->GetModeSize());
63 back_buffer_ = AllocateBuffer(controller->GetAllocationDrmDevice(),
64 controller->GetModeSize());
65 }
66
67 void DrmSurface::PresentCanvas(const gfx::Rect& damage) {
68 DCHECK(base::MessageLoopForUI::IsCurrent());
69
70 // Create a snapshot of the requested drawing. If we get here again before
71 // presenting, just add the additional damage.
72 pending_image_damage_.Union(damage);
73 pending_image_ = skia::AdoptRef(surface_->newImageSnapshot());
74
75 if (!pending_pageflip_)
76 SchedulePageFlip();
77 }
78
79 scoped_ptr<gfx::VSyncProvider> DrmSurface::CreateVSyncProvider() {
80 return make_scoped_ptr(new DrmVSyncProvider(window_delegate_));
81 }
82
83 void DrmSurface::SchedulePageFlip() {
84 DCHECK(back_buffer_);
85 SkCanvas* canvas = back_buffer_->GetCanvas();
86
87 // The DrmSurface is double buffered, so the current back buffer is
88 // missing the previous update. Expand damage region.
89 SkRect real_damage =
90 RectToSkRect(UnionRects(pending_image_damage_, last_damage_));
91
92 // Copy damage region.
93 canvas->drawImageRect(pending_image_.get(), &real_damage, real_damage, NULL);
94 last_damage_ = pending_image_damage_;
95
96 pending_image_.clear();
97 pending_image_damage_ = gfx::Rect();
98
99 window_delegate_->QueueOverlayPlane(OverlayPlane(back_buffer_));
100
101 // Update our front buffer pointer.
102 std::swap(front_buffer_, back_buffer_);
103 pending_pageflip_ = window_delegate_->SchedulePageFlip(
104 false /* is_sync */,
105 base::Bind(&DrmSurface::OnPageFlip, weak_ptr_factory_.GetWeakPtr()));
106 }
107
108 void DrmSurface::OnPageFlip(gfx::SwapResult result) {
109 pending_pageflip_ = false;
110 if (!pending_image_)
111 return;
112
113 SchedulePageFlip();
114 }
115
116 } // 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