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 COMPONENTS_EXO_DISPLAY_H_
6 #define COMPONENTS_EXO_DISPLAY_H_
7 
8 #include <stddef.h>
9 
10 #include <memory>
11 #include <string>
12 
13 #include "base/macros.h"
14 #include "base/memory/unsafe_shared_memory_region.h"
15 #include "components/exo/seat.h"
16 
17 #if defined(USE_OZONE)
18 #include "base/files/scoped_file.h"
19 #include "ui/gfx/buffer_types.h"
20 #include "ui/gfx/geometry/size.h"
21 #include "ui/gfx/native_pixmap_handle.h"
22 #endif
23 
24 namespace gfx {
25 class ClientNativePixmapFactory;
26 }
27 
28 namespace exo {
29 class ClientControlledShellSurface;
30 class DataDevice;
31 class DataDeviceDelegate;
32 class FileHelper;
33 class InputMethodSurfaceManager;
34 class NotificationSurface;
35 class NotificationSurfaceManager;
36 class SharedMemory;
37 class SubSurface;
38 class Surface;
39 
40 #if defined(OS_CHROMEOS)
41 class InputMethodSurface;
42 class ShellSurface;
43 class XdgShellSurface;
44 #endif
45 
46 #if defined(USE_OZONE)
47 class Buffer;
48 #endif
49 
50 // The core display class. This class provides functions for creating surfaces
51 // and is in charge of combining the contents of multiple surfaces into one
52 // displayable output.
53 class Display {
54  public:
55   Display();
56 
57 #if defined(OS_CHROMEOS)
58   Display(NotificationSurfaceManager* notification_surface_manager,
59           InputMethodSurfaceManager* input_method_surface_manager,
60           std::unique_ptr<FileHelper> file_helper);
61 #endif  // defined(OS_CHROMEOS)
62 
63   ~Display();
64 
65   // Creates a new surface.
66   std::unique_ptr<Surface> CreateSurface();
67 
68   // Creates a shared memory segment from |shared_memory_region|. This function
69   // takes ownership of the region.
70   std::unique_ptr<SharedMemory> CreateSharedMemory(
71       base::UnsafeSharedMemoryRegion shared_memory_region);
72 
73 #if defined(USE_OZONE)
74   // Creates a buffer for a Linux DMA-buf file descriptor.
75   std::unique_ptr<Buffer> CreateLinuxDMABufBuffer(
76       const gfx::Size& size,
77       gfx::BufferFormat format,
78       gfx::NativePixmapHandle handle,
79       bool y_invert);
80 #endif  // defined(USE_OZONE)
81 
82 #if defined(OS_CHROMEOS)
83   // Creates a shell surface for an existing surface.
84   std::unique_ptr<ShellSurface> CreateShellSurface(Surface* surface);
85 
86   // Creates a xdg shell surface for an existing surface.
87   std::unique_ptr<XdgShellSurface> CreateXdgShellSurface(Surface* surface);
88 
89   // Creates a remote shell surface for an existing surface using |container|.
90   // The surface is scaled by 1 / |default_device_scale_factor|.
91   std::unique_ptr<ClientControlledShellSurface>
92   CreateClientControlledShellSurface(Surface* surface,
93                                      int container,
94                                      double default_device_scale_factor);
95 
96   // Creates a notification surface for a surface and notification id.
97   std::unique_ptr<NotificationSurface> CreateNotificationSurface(
98       Surface* surface,
99       const std::string& notification_key);
100 
101   // Creates a input method surface for a surface.
102   std::unique_ptr<InputMethodSurface> CreateInputMethodSurface(
103       Surface* surface,
104       double default_device_scale_factor);
105 #endif  // defined(OS_CHROMEOS)
106 
107   // Creates a sub-surface for an existing surface. The sub-surface will be
108   // a child of |parent|.
109   std::unique_ptr<SubSurface> CreateSubSurface(Surface* surface,
110                                                Surface* parent);
111 
112   // Creates a data device for a |delegate|.
113   std::unique_ptr<DataDevice> CreateDataDevice(DataDeviceDelegate* delegate);
114 
115   // Obtains seat instance.
seat()116   Seat* seat() { return &seat_; }
117 
118  private:
119 #if defined(OS_CHROMEOS)
120   NotificationSurfaceManager* notification_surface_manager_ = nullptr;
121   InputMethodSurfaceManager* input_method_surface_manager_ = nullptr;
122 #endif  // defined(OS_CHROMEOS)
123 
124   std::unique_ptr<FileHelper> file_helper_;
125   Seat seat_;
126 
127 #if defined(USE_OZONE)
128   std::unique_ptr<gfx::ClientNativePixmapFactory> client_native_pixmap_factory_;
129 #endif  // defined(USE_OZONE)
130 
131   DISALLOW_COPY_AND_ASSIGN(Display);
132 };
133 
134 }  // namespace exo
135 
136 #endif  // COMPONENTS_EXO_DISPLAY_H_
137