Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / ozone / platform / drm / gpu / hardware_display_plane_manager_atomic.cc
blob9ee6948c1a39ea8f9a887ddde49609def6041f5b
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.
5 #include "ui/ozone/platform/drm/gpu/hardware_display_plane_manager_atomic.h"
7 #include "base/bind.h"
8 #include "ui/ozone/platform/drm/gpu/crtc_controller.h"
9 #include "ui/ozone/platform/drm/gpu/drm_device.h"
10 #include "ui/ozone/platform/drm/gpu/hardware_display_plane_atomic.h"
11 #include "ui/ozone/platform/drm/gpu/scanout_buffer.h"
13 namespace ui {
15 static void AtomicPageFlipCallback(
16 std::vector<base::WeakPtr<CrtcController>> crtcs,
17 unsigned int frame,
18 unsigned int seconds,
19 unsigned int useconds) {
20 for (auto& crtc : crtcs) {
21 auto* crtc_ptr = crtc.get();
22 if (crtc_ptr)
23 crtc_ptr->OnPageFlipEvent(frame, seconds, useconds);
27 HardwareDisplayPlaneManagerAtomic::HardwareDisplayPlaneManagerAtomic() {
30 HardwareDisplayPlaneManagerAtomic::~HardwareDisplayPlaneManagerAtomic() {
33 bool HardwareDisplayPlaneManagerAtomic::Commit(
34 HardwareDisplayPlaneList* plane_list,
35 bool is_sync,
36 bool test_only) {
37 for (HardwareDisplayPlane* plane : plane_list->old_plane_list) {
38 bool found =
39 std::find(plane_list->plane_list.begin(), plane_list->plane_list.end(),
40 plane) != plane_list->plane_list.end();
41 if (!found) {
42 // This plane is being released, so we need to zero it.
43 plane->set_in_use(false);
44 HardwareDisplayPlaneAtomic* atomic_plane =
45 static_cast<HardwareDisplayPlaneAtomic*>(plane);
46 atomic_plane->SetPlaneData(plane_list->atomic_property_set.get(), 0, 0,
47 gfx::Rect(), gfx::Rect());
51 std::vector<base::WeakPtr<CrtcController>> crtcs;
52 for (HardwareDisplayPlane* plane : plane_list->plane_list) {
53 HardwareDisplayPlaneAtomic* atomic_plane =
54 static_cast<HardwareDisplayPlaneAtomic*>(plane);
55 if (crtcs.empty() || crtcs.back().get() != atomic_plane->crtc())
56 crtcs.push_back(atomic_plane->crtc()->AsWeakPtr());
59 if (test_only) {
60 for (HardwareDisplayPlane* plane : plane_list->plane_list) {
61 plane->set_in_use(false);
63 } else {
64 plane_list->plane_list.swap(plane_list->old_plane_list);
66 plane_list->plane_list.clear();
67 if (!drm_->CommitProperties(plane_list->atomic_property_set.get(), 0, is_sync,
68 test_only,
69 base::Bind(&AtomicPageFlipCallback, crtcs))) {
70 PLOG(ERROR) << "Failed to commit properties";
71 return false;
73 plane_list->atomic_property_set.reset(drmModePropertySetAlloc());
74 return true;
77 bool HardwareDisplayPlaneManagerAtomic::SetPlaneData(
78 HardwareDisplayPlaneList* plane_list,
79 HardwareDisplayPlane* hw_plane,
80 const OverlayPlane& overlay,
81 uint32_t crtc_id,
82 const gfx::Rect& src_rect,
83 CrtcController* crtc) {
84 HardwareDisplayPlaneAtomic* atomic_plane =
85 static_cast<HardwareDisplayPlaneAtomic*>(hw_plane);
86 if (!atomic_plane->SetPlaneData(plane_list->atomic_property_set.get(),
87 crtc_id, overlay.buffer->GetFramebufferId(),
88 overlay.display_bounds, src_rect)) {
89 LOG(ERROR) << "Failed to set plane properties";
90 return false;
92 atomic_plane->set_crtc(crtc);
93 return true;
96 scoped_ptr<HardwareDisplayPlane> HardwareDisplayPlaneManagerAtomic::CreatePlane(
97 uint32_t plane_id,
98 uint32_t possible_crtcs) {
99 return scoped_ptr<HardwareDisplayPlane>(
100 new HardwareDisplayPlaneAtomic(plane_id, possible_crtcs));
103 } // namespace ui