diff mbox series

[v2,03/10] drm/client: Add drm_client_framebuffer_flush()

Message ID 20200509141619.32970-4-noralf@tronnes.org (mailing list archive)
State New, archived
Headers show
Series Generic USB Display driver | expand

Commit Message

Noralf Trønnes May 9, 2020, 2:16 p.m. UTC
Some drivers need explicit flushing of buffer changes, add a function
that does that.

v2:
- Put all clip rect stuff inside if statement (Sam)

Reviewed-by: Sam Ravnborg <sam@ravnborg.org>
Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
---
 drivers/gpu/drm/drm_client.c | 33 +++++++++++++++++++++++++++++++++
 include/drm/drm_client.h     |  1 +
 2 files changed, 34 insertions(+)

Comments

Emil Velikov May 28, 2020, 1:48 p.m. UTC | #1
Hi all,

I realise this has landed, so a small FYI comment.

On Sat, 9 May 2020 at 15:16, Noralf Trønnes <noralf@tronnes.org> wrote:

> +int drm_client_framebuffer_flush(struct drm_client_buffer *buffer, struct drm_rect *rect)
> +{
> +       if (!buffer || !buffer->fb || !buffer->fb->funcs->dirty)

Hmm cannot think of a good reason why anyone would call this with
!buffer || !buffer->fb?
Might be a good idea to WARN in those cases - otherwise the user is
given false sense to security.

Looking at the upcoming user (drm/gud) it already has both - so it's
perfectly safe.

-Emil
Noralf Trønnes June 3, 2020, 12:19 p.m. UTC | #2
Den 28.05.2020 15.48, skrev Emil Velikov:
> Hi all,
> 
> I realise this has landed, so a small FYI comment.
> 
> On Sat, 9 May 2020 at 15:16, Noralf Trønnes <noralf@tronnes.org> wrote:
> 
>> +int drm_client_framebuffer_flush(struct drm_client_buffer *buffer, struct drm_rect *rect)
>> +{
>> +       if (!buffer || !buffer->fb || !buffer->fb->funcs->dirty)
> 
> Hmm cannot think of a good reason why anyone would call this with
> !buffer || !buffer->fb?
> Might be a good idea to WARN in those cases - otherwise the user is
> given false sense to security.
> 

I agree, I'll send a fixup when I get through my backlog.

Noralf.

> Looking at the upcoming user (drm/gud) it already has both - so it's
> perfectly safe.
> 
> -Emil
>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/drm_client.c b/drivers/gpu/drm/drm_client.c
index 12787915db01..827ee6422dd2 100644
--- a/drivers/gpu/drm/drm_client.c
+++ b/drivers/gpu/drm/drm_client.c
@@ -483,6 +483,39 @@  void drm_client_framebuffer_delete(struct drm_client_buffer *buffer)
 }
 EXPORT_SYMBOL(drm_client_framebuffer_delete);
 
+/**
+ * drm_client_framebuffer_flush - Manually flush client framebuffer
+ * @buffer: DRM client buffer (can be NULL)
+ * @rect: Damage rectangle (if NULL flushes all)
+ *
+ * This calls &drm_framebuffer_funcs->dirty (if present) to flush buffer changes
+ * for drivers that need it.
+ *
+ * Returns:
+ * Zero on success or negative error code on failure.
+ */
+int drm_client_framebuffer_flush(struct drm_client_buffer *buffer, struct drm_rect *rect)
+{
+	if (!buffer || !buffer->fb || !buffer->fb->funcs->dirty)
+		return 0;
+
+	if (rect) {
+		struct drm_clip_rect clip = {
+			.x1 = rect->x1,
+			.y1 = rect->y1,
+			.x2 = rect->x2,
+			.y2 = rect->y2,
+		};
+
+		return buffer->fb->funcs->dirty(buffer->fb, buffer->client->file,
+						0, 0, &clip, 1);
+	}
+
+	return buffer->fb->funcs->dirty(buffer->fb, buffer->client->file,
+					0, 0, NULL, 0);
+}
+EXPORT_SYMBOL(drm_client_framebuffer_flush);
+
 #ifdef CONFIG_DEBUG_FS
 static int drm_client_debugfs_internal_clients(struct seq_file *m, void *data)
 {
diff --git a/include/drm/drm_client.h b/include/drm/drm_client.h
index 96ebc7523aa0..9737dd7b147f 100644
--- a/include/drm/drm_client.h
+++ b/include/drm/drm_client.h
@@ -156,6 +156,7 @@  struct drm_client_buffer {
 struct drm_client_buffer *
 drm_client_framebuffer_create(struct drm_client_dev *client, u32 width, u32 height, u32 format);
 void drm_client_framebuffer_delete(struct drm_client_buffer *buffer);
+int drm_client_framebuffer_flush(struct drm_client_buffer *buffer, struct drm_rect *rect);
 void *drm_client_buffer_vmap(struct drm_client_buffer *buffer);
 void drm_client_buffer_vunmap(struct drm_client_buffer *buffer);