OLD | NEW |
---|---|
(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/dri/hardware_display_plane.h" | |
6 | |
7 #include <drm.h> | |
8 #include <errno.h> | |
9 #include <xf86drm.h> | |
10 | |
11 #include "base/logging.h" | |
12 #include "ui/gfx/geometry/rect.h" | |
13 #include "ui/ozone/platform/dri/dri_wrapper.h" | |
14 #include "ui/ozone/platform/dri/scoped_drm_types.h" | |
15 | |
16 namespace ui { | |
17 | |
18 namespace { | |
19 const char* kCrtcPropName = "CRTC_ID"; | |
20 const char* kFbPropName = "FB_ID"; | |
21 const char* kCrtcXPropName = "CRTC_X"; | |
22 const char* kCrtcYPropName = "CRTC_Y"; | |
23 const char* kCrtcWPropName = "CRTC_W"; | |
24 const char* kCrtcHPropName = "CRTC_H"; | |
25 const char* kSrcXPropName = "SRC_X"; | |
26 const char* kSrcYPropName = "SRC_Y"; | |
27 const char* kSrcWPropName = "SRC_W"; | |
28 const char* kSrcHPropName = "SRC_H"; | |
29 } | |
30 | |
31 HardwareDisplayPlane::Property::Property() : id_(0) { | |
32 } | |
33 | |
34 bool HardwareDisplayPlane::Property::Initialize( | |
35 DriWrapper* drm, | |
36 const char* name, | |
37 drmModeObjectPropertiesPtr plane_props) { | |
38 for (uint32_t i = 0; i < plane_props->count_props; i++) { | |
39 ScopedDrmPropertyPtr property( | |
40 drmModeGetProperty(drm->get_fd(), plane_props->props[i])); | |
41 if (!strcmp(property->name, name)) { | |
42 id_ = property->prop_id; | |
43 break; | |
44 } | |
45 } | |
46 if (!id_) { | |
47 LOG(ERROR) << "Could not find property " << name; | |
48 return false; | |
49 } | |
50 return true; | |
51 } | |
52 | |
53 HardwareDisplayPlane::HardwareDisplayPlane( | |
54 DriWrapper* drm, | |
55 drmModePropertySetPtr atomic_property_set, | |
56 drmModePlanePtr plane, | |
57 uint32_t plane_id) | |
58 : drm_(drm), property_set_(atomic_property_set), plane_(plane) { | |
59 } | |
60 | |
61 HardwareDisplayPlane::~HardwareDisplayPlane() { | |
62 } | |
63 | |
64 bool HardwareDisplayPlane::SetPlaneData(uint32_t crtc_id, | |
65 uint32_t framebuffer, | |
66 const gfx::Rect& crtc_rect, | |
67 const gfx::Rect& src_rect) { | |
68 int plane_set_error = | |
69 drmModePropertySetAdd( | |
70 property_set_, plane_id_, crtc_prop_.id_, crtc_id) || | |
71 drmModePropertySetAdd( | |
72 property_set_, plane_id_, fb_prop_.id_, framebuffer) || | |
73 drmModePropertySetAdd( | |
74 property_set_, plane_id_, crtc_x_prop_.id_, crtc_rect.x()) || | |
75 drmModePropertySetAdd( | |
76 property_set_, plane_id_, crtc_y_prop_.id_, crtc_rect.y()) || | |
77 drmModePropertySetAdd( | |
78 property_set_, plane_id_, crtc_w_prop_.id_, crtc_rect.width()) || | |
79 drmModePropertySetAdd( | |
80 property_set_, plane_id_, crtc_h_prop_.id_, crtc_rect.height()) || | |
81 drmModePropertySetAdd( | |
82 property_set_, plane_id_, src_x_prop_.id_, src_rect.x()) || | |
83 drmModePropertySetAdd( | |
84 property_set_, plane_id_, src_y_prop_.id_, src_rect.x()) || | |
85 drmModePropertySetAdd( | |
86 property_set_, plane_id_, src_w_prop_.id_, src_rect.width()) || | |
87 drmModePropertySetAdd( | |
88 property_set_, plane_id_, src_h_prop_.id_, src_rect.height()); | |
89 | |
90 if (plane_set_error) { | |
91 LOG(ERROR) << "Failed to set plane data"; | |
92 return false; | |
93 } | |
94 return true; | |
95 } | |
96 | |
97 bool HardwareDisplayPlane::Initialize() { | |
98 drmModeObjectPropertiesPtr plane_props = drmModeObjectGetProperties( | |
dnicoara
2014/07/11 15:24:04
Could you please add the type to scoped_drm_types.
alexst (slow to review)
2014/07/11 20:19:43
Good point, done.
| |
99 drm_->get_fd(), plane_id_, DRM_MODE_OBJECT_PLANE); | |
100 | |
101 if (!plane_props) { | |
102 LOG(ERROR) << "Unable to get plane properties."; | |
103 return false; | |
104 } | |
105 | |
106 bool props_init = | |
107 crtc_prop_.Initialize(drm_, kCrtcPropName, plane_props) && | |
108 fb_prop_.Initialize(drm_, kFbPropName, plane_props) && | |
109 crtc_x_prop_.Initialize(drm_, kCrtcXPropName, plane_props) && | |
110 crtc_y_prop_.Initialize(drm_, kCrtcYPropName, plane_props) && | |
111 crtc_w_prop_.Initialize(drm_, kCrtcWPropName, plane_props) && | |
112 crtc_h_prop_.Initialize(drm_, kCrtcHPropName, plane_props) && | |
113 src_x_prop_.Initialize(drm_, kSrcXPropName, plane_props) && | |
114 src_y_prop_.Initialize(drm_, kSrcYPropName, plane_props) && | |
115 src_w_prop_.Initialize(drm_, kSrcWPropName, plane_props) && | |
116 src_h_prop_.Initialize(drm_, kSrcHPropName, plane_props); | |
117 | |
118 if (!props_init) { | |
119 LOG(ERROR) << "Unable to get plane properties."; | |
120 return false; | |
121 } | |
122 return true; | |
123 } | |
124 | |
125 } // namespace ui | |
OLD | NEW |