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_atomic.cc
blob3f0952e1f830322d46b0202af144d76ac35e4bb6
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 <drm.h>
8 #include <errno.h>
9 #include <xf86drm.h>
11 #include "ui/ozone/platform/drm/gpu/drm_device.h"
13 namespace ui {
14 namespace {
16 const char* kCrtcPropName = "CRTC_ID";
17 const char* kFbPropName = "FB_ID";
18 const char* kCrtcXPropName = "CRTC_X";
19 const char* kCrtcYPropName = "CRTC_Y";
20 const char* kCrtcWPropName = "CRTC_W";
21 const char* kCrtcHPropName = "CRTC_H";
22 const char* kSrcXPropName = "SRC_X";
23 const char* kSrcYPropName = "SRC_Y";
24 const char* kSrcWPropName = "SRC_W";
25 const char* kSrcHPropName = "SRC_H";
27 } // namespace
29 HardwareDisplayPlaneAtomic::Property::Property() {
32 bool HardwareDisplayPlaneAtomic::Property::Initialize(
33 DrmDevice* drm,
34 const char* name,
35 const ScopedDrmObjectPropertyPtr& plane_props) {
36 for (uint32_t i = 0; i < plane_props->count_props; i++) {
37 ScopedDrmPropertyPtr property(
38 drmModeGetProperty(drm->get_fd(), plane_props->props[i]));
39 if (property && !strcmp(property->name, name)) {
40 id = property->prop_id;
41 break;
44 if (!id) {
45 LOG(ERROR) << "Could not find property " << name;
46 return false;
48 return true;
51 HardwareDisplayPlaneAtomic::HardwareDisplayPlaneAtomic(uint32_t plane_id,
52 uint32_t possible_crtcs)
53 : HardwareDisplayPlane(plane_id, possible_crtcs) {
55 HardwareDisplayPlaneAtomic::~HardwareDisplayPlaneAtomic() {
58 bool HardwareDisplayPlaneAtomic::SetPlaneData(drmModePropertySet* property_set,
59 uint32_t crtc_id,
60 uint32_t framebuffer,
61 const gfx::Rect& crtc_rect,
62 const gfx::Rect& src_rect) {
63 int plane_set_error =
64 drmModePropertySetAdd(property_set, plane_id_, crtc_prop_.id, crtc_id) ||
65 drmModePropertySetAdd(property_set, plane_id_, fb_prop_.id,
66 framebuffer) ||
67 drmModePropertySetAdd(property_set, plane_id_, crtc_x_prop_.id,
68 crtc_rect.x()) ||
69 drmModePropertySetAdd(property_set, plane_id_, crtc_y_prop_.id,
70 crtc_rect.y()) ||
71 drmModePropertySetAdd(property_set, plane_id_, crtc_w_prop_.id,
72 crtc_rect.width()) ||
73 drmModePropertySetAdd(property_set, plane_id_, crtc_h_prop_.id,
74 crtc_rect.height()) ||
75 drmModePropertySetAdd(property_set, plane_id_, src_x_prop_.id,
76 src_rect.x()) ||
77 drmModePropertySetAdd(property_set, plane_id_, src_y_prop_.id,
78 src_rect.x()) ||
79 drmModePropertySetAdd(property_set, plane_id_, src_w_prop_.id,
80 src_rect.width()) ||
81 drmModePropertySetAdd(property_set, plane_id_, src_h_prop_.id,
82 src_rect.height());
83 if (plane_set_error) {
84 PLOG(ERROR) << "Failed to set plane data";
85 return false;
87 return true;
90 bool HardwareDisplayPlaneAtomic::Initialize(DrmDevice* drm) {
91 ScopedDrmObjectPropertyPtr plane_props(drmModeObjectGetProperties(
92 drm->get_fd(), plane_id_, DRM_MODE_OBJECT_PLANE));
94 if (!plane_props) {
95 PLOG(ERROR) << "Unable to get plane properties.";
96 return false;
99 bool props_init = crtc_prop_.Initialize(drm, kCrtcPropName, plane_props) &&
100 fb_prop_.Initialize(drm, kFbPropName, plane_props) &&
101 crtc_x_prop_.Initialize(drm, kCrtcXPropName, plane_props) &&
102 crtc_y_prop_.Initialize(drm, kCrtcYPropName, plane_props) &&
103 crtc_w_prop_.Initialize(drm, kCrtcWPropName, plane_props) &&
104 crtc_h_prop_.Initialize(drm, kCrtcHPropName, plane_props) &&
105 src_x_prop_.Initialize(drm, kSrcXPropName, plane_props) &&
106 src_y_prop_.Initialize(drm, kSrcYPropName, plane_props) &&
107 src_w_prop_.Initialize(drm, kSrcWPropName, plane_props) &&
108 src_h_prop_.Initialize(drm, kSrcHPropName, plane_props);
110 if (!props_init) {
111 LOG(ERROR) << "Unable to get plane properties.";
112 return false;
114 return true;
117 } // namespace ui