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.
4 
5 #ifndef UI_OZONE_PLATFORM_DRM_GPU_DRM_THREAD_PROXY_H_
6 #define UI_OZONE_PLATFORM_DRM_GPU_DRM_THREAD_PROXY_H_
7 
8 #include <memory>
9 #include <vector>
10 
11 #include "base/callback.h"
12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h"
14 #include "mojo/public/cpp/bindings/pending_receiver.h"
15 #include "ui/ozone/platform/drm/gpu/drm_thread.h"
16 #include "ui/ozone/public/mojom/device_cursor.mojom.h"
17 #include "ui/ozone/public/overlay_surface_candidate.h"
18 
19 namespace ui {
20 
21 class DrmWindowProxy;
22 class InterThreadMessagingProxy;
23 
24 // Mediates the communication between GPU main/compositor/IO threads and the DRM
25 // thread. It serves proxy objects that are safe to call on the GPU threads. The
26 // proxy objects then deal with safely posting the messages to the DRM thread.
27 class DrmThreadProxy {
28  public:
29   DrmThreadProxy();
30   ~DrmThreadProxy();
31 
32   void BindThreadIntoMessagingProxy(InterThreadMessagingProxy* messaging_proxy);
33 
34   void StartDrmThread(base::OnceClosure receiver_drainer);
35 
36   std::unique_ptr<DrmWindowProxy> CreateDrmWindowProxy(
37       gfx::AcceleratedWidget widget);
38 
39   void CreateBuffer(gfx::AcceleratedWidget widget,
40                     const gfx::Size& size,
41                     const gfx::Size& framebuffer_size,
42                     gfx::BufferFormat format,
43                     gfx::BufferUsage usage,
44                     uint32_t flags,
45                     std::unique_ptr<GbmBuffer>* buffer,
46                     scoped_refptr<DrmFramebuffer>* framebuffer);
47 
48   using CreateBufferAsyncCallback =
49       base::OnceCallback<void(std::unique_ptr<GbmBuffer>,
50                               scoped_refptr<DrmFramebuffer>)>;
51   void CreateBufferAsync(gfx::AcceleratedWidget widget,
52                          const gfx::Size& size,
53                          gfx::BufferFormat format,
54                          gfx::BufferUsage usage,
55                          uint32_t flags,
56                          CreateBufferAsyncCallback callback);
57 
58   void CreateBufferFromHandle(gfx::AcceleratedWidget widget,
59                               const gfx::Size& size,
60                               gfx::BufferFormat format,
61                               gfx::NativePixmapHandle handle,
62                               std::unique_ptr<GbmBuffer>* buffer,
63                               scoped_refptr<DrmFramebuffer>* framebuffer);
64 
65   // Sets a callback that will be notified when display configuration may have
66   // changed to clear the overlay configuration cache. |callback| will be run on
67   // origin thread.
68   void SetClearOverlayCacheCallback(base::RepeatingClosure reset_callback);
69 
70   // Checks if overlay |candidates| can be displayed asynchronously and then
71   // runs |callback|. Testing the overlay configuration requires posting a task
72   // to the DRM thread, but |callback| will be run on origin thread.
73   void CheckOverlayCapabilities(
74       gfx::AcceleratedWidget widget,
75       const std::vector<OverlaySurfaceCandidate>& candidates,
76       DrmThread::OverlayCapabilitiesCallback callback);
77 
78   // Similar to CheckOverlayCapabilities() but returns the result synchronously.
79   std::vector<OverlayStatus> CheckOverlayCapabilitiesSync(
80       gfx::AcceleratedWidget widget,
81       const std::vector<OverlaySurfaceCandidate>& candidates);
82 
83   void AddDrmDeviceReceiver(
84       mojo::PendingReceiver<ozone::mojom::DrmDevice> receiver);
85 
86   bool WaitUntilDrmThreadStarted();
87   scoped_refptr<base::SingleThreadTaskRunner> GetDrmThreadTaskRunner();
88 
89  private:
90   DrmThread drm_thread_;
91 
92   DISALLOW_COPY_AND_ASSIGN(DrmThreadProxy);
93 };
94 
95 }  // namespace ui
96 
97 #endif  // UI_OZONE_PLATFORM_DRM_GPU_DRM_THREAD_PROXY_H_
98