diff options
Diffstat (limited to 'drivers/gpu/drm/drm_plane_helper.c')
-rw-r--r-- | drivers/gpu/drm/drm_plane_helper.c | 111 |
1 files changed, 12 insertions, 99 deletions
diff --git a/drivers/gpu/drm/drm_plane_helper.c b/drivers/gpu/drm/drm_plane_helper.c index 759ed93f4ba8..f1be8cd4e387 100644 --- a/drivers/gpu/drm/drm_plane_helper.c +++ b/drivers/gpu/drm/drm_plane_helper.c | |||
@@ -100,97 +100,6 @@ static int get_connectors_for_crtc(struct drm_crtc *crtc, | |||
100 | } | 100 | } |
101 | 101 | ||
102 | /** | 102 | /** |
103 | * drm_plane_helper_check_state() - Check plane state for validity | ||
104 | * @state: plane state to check | ||
105 | * @clip: integer clipping coordinates | ||
106 | * @min_scale: minimum @src:@dest scaling factor in 16.16 fixed point | ||
107 | * @max_scale: maximum @src:@dest scaling factor in 16.16 fixed point | ||
108 | * @can_position: is it legal to position the plane such that it | ||
109 | * doesn't cover the entire crtc? This will generally | ||
110 | * only be false for primary planes. | ||
111 | * @can_update_disabled: can the plane be updated while the crtc | ||
112 | * is disabled? | ||
113 | * | ||
114 | * Checks that a desired plane update is valid, and updates various | ||
115 | * bits of derived state (clipped coordinates etc.). Drivers that provide | ||
116 | * their own plane handling rather than helper-provided implementations may | ||
117 | * still wish to call this function to avoid duplication of error checking | ||
118 | * code. | ||
119 | * | ||
120 | * RETURNS: | ||
121 | * Zero if update appears valid, error code on failure | ||
122 | */ | ||
123 | int drm_plane_helper_check_state(struct drm_plane_state *state, | ||
124 | const struct drm_rect *clip, | ||
125 | int min_scale, | ||
126 | int max_scale, | ||
127 | bool can_position, | ||
128 | bool can_update_disabled) | ||
129 | { | ||
130 | struct drm_crtc *crtc = state->crtc; | ||
131 | struct drm_framebuffer *fb = state->fb; | ||
132 | struct drm_rect *src = &state->src; | ||
133 | struct drm_rect *dst = &state->dst; | ||
134 | unsigned int rotation = state->rotation; | ||
135 | int hscale, vscale; | ||
136 | |||
137 | *src = drm_plane_state_src(state); | ||
138 | *dst = drm_plane_state_dest(state); | ||
139 | |||
140 | if (!fb) { | ||
141 | state->visible = false; | ||
142 | return 0; | ||
143 | } | ||
144 | |||
145 | /* crtc should only be NULL when disabling (i.e., !fb) */ | ||
146 | if (WARN_ON(!crtc)) { | ||
147 | state->visible = false; | ||
148 | return 0; | ||
149 | } | ||
150 | |||
151 | if (!crtc->enabled && !can_update_disabled) { | ||
152 | DRM_DEBUG_KMS("Cannot update plane of a disabled CRTC.\n"); | ||
153 | return -EINVAL; | ||
154 | } | ||
155 | |||
156 | drm_rect_rotate(src, fb->width << 16, fb->height << 16, rotation); | ||
157 | |||
158 | /* Check scaling */ | ||
159 | hscale = drm_rect_calc_hscale(src, dst, min_scale, max_scale); | ||
160 | vscale = drm_rect_calc_vscale(src, dst, min_scale, max_scale); | ||
161 | if (hscale < 0 || vscale < 0) { | ||
162 | DRM_DEBUG_KMS("Invalid scaling of plane\n"); | ||
163 | drm_rect_debug_print("src: ", &state->src, true); | ||
164 | drm_rect_debug_print("dst: ", &state->dst, false); | ||
165 | return -ERANGE; | ||
166 | } | ||
167 | |||
168 | state->visible = drm_rect_clip_scaled(src, dst, clip, hscale, vscale); | ||
169 | |||
170 | drm_rect_rotate_inv(src, fb->width << 16, fb->height << 16, rotation); | ||
171 | |||
172 | if (!state->visible) | ||
173 | /* | ||
174 | * Plane isn't visible; some drivers can handle this | ||
175 | * so we just return success here. Drivers that can't | ||
176 | * (including those that use the primary plane helper's | ||
177 | * update function) will return an error from their | ||
178 | * update_plane handler. | ||
179 | */ | ||
180 | return 0; | ||
181 | |||
182 | if (!can_position && !drm_rect_equals(dst, clip)) { | ||
183 | DRM_DEBUG_KMS("Plane must cover entire CRTC\n"); | ||
184 | drm_rect_debug_print("dst: ", dst, false); | ||
185 | drm_rect_debug_print("clip: ", clip, false); | ||
186 | return -EINVAL; | ||
187 | } | ||
188 | |||
189 | return 0; | ||
190 | } | ||
191 | EXPORT_SYMBOL(drm_plane_helper_check_state); | ||
192 | |||
193 | /** | ||
194 | * drm_plane_helper_check_update() - Check plane update for validity | 103 | * drm_plane_helper_check_update() - Check plane update for validity |
195 | * @plane: plane object to update | 104 | * @plane: plane object to update |
196 | * @crtc: owning CRTC of owning plane | 105 | * @crtc: owning CRTC of owning plane |
@@ -230,7 +139,7 @@ int drm_plane_helper_check_update(struct drm_plane *plane, | |||
230 | bool can_update_disabled, | 139 | bool can_update_disabled, |
231 | bool *visible) | 140 | bool *visible) |
232 | { | 141 | { |
233 | struct drm_plane_state state = { | 142 | struct drm_plane_state plane_state = { |
234 | .plane = plane, | 143 | .plane = plane, |
235 | .crtc = crtc, | 144 | .crtc = crtc, |
236 | .fb = fb, | 145 | .fb = fb, |
@@ -245,18 +154,22 @@ int drm_plane_helper_check_update(struct drm_plane *plane, | |||
245 | .rotation = rotation, | 154 | .rotation = rotation, |
246 | .visible = *visible, | 155 | .visible = *visible, |
247 | }; | 156 | }; |
157 | struct drm_crtc_state crtc_state = { | ||
158 | .crtc = crtc, | ||
159 | .enable = crtc->enabled, | ||
160 | }; | ||
248 | int ret; | 161 | int ret; |
249 | 162 | ||
250 | ret = drm_plane_helper_check_state(&state, clip, | 163 | ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state, |
251 | min_scale, max_scale, | 164 | clip, min_scale, max_scale, |
252 | can_position, | 165 | can_position, |
253 | can_update_disabled); | 166 | can_update_disabled); |
254 | if (ret) | 167 | if (ret) |
255 | return ret; | 168 | return ret; |
256 | 169 | ||
257 | *src = state.src; | 170 | *src = plane_state.src; |
258 | *dst = state.dst; | 171 | *dst = plane_state.dst; |
259 | *visible = state.visible; | 172 | *visible = plane_state.visible; |
260 | 173 | ||
261 | return 0; | 174 | return 0; |
262 | } | 175 | } |