Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / ozone / platform / drm / gpu / hardware_display_plane_atomic.cc
blob6ca6f6b45f933d69aa3ca748ce2f5f0c9cd21bc7
1 // Copyright 2015 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_atomic.h"
7 #include "ui/ozone/platform/drm/gpu/drm_device.h"
9 namespace ui {
10 namespace {
12 const char* kCrtcPropName = "CRTC_ID";
13 const char* kFbPropName = "FB_ID";
14 const char* kCrtcXPropName = "CRTC_X";
15 const char* kCrtcYPropName = "CRTC_Y";
16 const char* kCrtcWPropName = "CRTC_W";
17 const char* kCrtcHPropName = "CRTC_H";
18 const char* kSrcXPropName = "SRC_X";
19 const char* kSrcYPropName = "SRC_Y";
20 const char* kSrcWPropName = "SRC_W";
21 const char* kSrcHPropName = "SRC_H";
23 } // namespace
25 HardwareDisplayPlaneAtomic::Property::Property() {
28 bool HardwareDisplayPlaneAtomic::Property::Initialize(
29 DrmDevice* drm,
30 const char* name,
31 const ScopedDrmObjectPropertyPtr& plane_props) {
32 for (uint32_t i = 0; i < plane_props->count_props; i++) {
33 ScopedDrmPropertyPtr property(
34 drmModeGetProperty(drm->get_fd(), plane_props->props[i]));
35 if (property && !strcmp(property->name, name)) {
36 id = property->prop_id;
37 break;
40 if (!id) {
41 LOG(ERROR) << "Could not find property " << name;
42 return false;
44 return true;
47 HardwareDisplayPlaneAtomic::HardwareDisplayPlaneAtomic(uint32_t plane_id,
48 uint32_t possible_crtcs)
49 : HardwareDisplayPlane(plane_id, possible_crtcs) {
51 HardwareDisplayPlaneAtomic::~HardwareDisplayPlaneAtomic() {
54 bool HardwareDisplayPlaneAtomic::SetPlaneData(drmModeAtomicReq* property_set,
55 uint32_t crtc_id,
56 uint32_t framebuffer,
57 const gfx::Rect& crtc_rect,
58 const gfx::Rect& src_rect) {
59 int plane_set_succeeded =
60 drmModeAtomicAddProperty(property_set, plane_id_, crtc_prop_.id,
61 crtc_id) &&
62 drmModeAtomicAddProperty(property_set, plane_id_, fb_prop_.id,
63 framebuffer) &&
64 drmModeAtomicAddProperty(property_set, plane_id_, crtc_x_prop_.id,
65 crtc_rect.x()) &&
66 drmModeAtomicAddProperty(property_set, plane_id_, crtc_y_prop_.id,
67 crtc_rect.y()) &&
68 drmModeAtomicAddProperty(property_set, plane_id_, crtc_w_prop_.id,
69 crtc_rect.width()) &&
70 drmModeAtomicAddProperty(property_set, plane_id_, crtc_h_prop_.id,
71 crtc_rect.height()) &&
72 drmModeAtomicAddProperty(property_set, plane_id_, src_x_prop_.id,
73 src_rect.x()) &&
74 drmModeAtomicAddProperty(property_set, plane_id_, src_y_prop_.id,
75 src_rect.x()) &&
76 drmModeAtomicAddProperty(property_set, plane_id_, src_w_prop_.id,
77 src_rect.width()) &&
78 drmModeAtomicAddProperty(property_set, plane_id_, src_h_prop_.id,
79 src_rect.height());
80 if (!plane_set_succeeded) {
81 PLOG(ERROR) << "Failed to set plane data";
82 return false;
84 return true;
87 bool HardwareDisplayPlaneAtomic::InitializeProperties(
88 DrmDevice* drm,
89 const ScopedDrmObjectPropertyPtr& plane_props) {
90 bool props_init = crtc_prop_.Initialize(drm, kCrtcPropName, plane_props) &&
91 fb_prop_.Initialize(drm, kFbPropName, plane_props) &&
92 crtc_x_prop_.Initialize(drm, kCrtcXPropName, plane_props) &&
93 crtc_y_prop_.Initialize(drm, kCrtcYPropName, plane_props) &&
94 crtc_w_prop_.Initialize(drm, kCrtcWPropName, plane_props) &&
95 crtc_h_prop_.Initialize(drm, kCrtcHPropName, plane_props) &&
96 src_x_prop_.Initialize(drm, kSrcXPropName, plane_props) &&
97 src_y_prop_.Initialize(drm, kSrcYPropName, plane_props) &&
98 src_w_prop_.Initialize(drm, kSrcWPropName, plane_props) &&
99 src_h_prop_.Initialize(drm, kSrcHPropName, plane_props);
101 if (!props_init) {
102 LOG(ERROR) << "Unable to get plane properties.";
103 return false;
106 return true;
109 } // namespace ui