| 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 #ifndef COMPONENTS_MUS_WS_PLATFORM_DISPLAY_H_ | |
| 6 #define COMPONENTS_MUS_WS_PLATFORM_DISPLAY_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <map> | |
| 11 #include <memory> | |
| 12 | |
| 13 #include "base/macros.h" | |
| 14 #include "base/memory/weak_ptr.h" | |
| 15 #include "base/strings/string16.h" | |
| 16 #include "base/timer/timer.h" | |
| 17 #include "build/build_config.h" | |
| 18 #include "cc/surfaces/surface.h" | |
| 19 #include "components/mus/public/interfaces/window_manager.mojom.h" | |
| 20 #include "components/mus/public/interfaces/window_manager_constants.mojom.h" | |
| 21 #include "components/mus/public/interfaces/window_tree.mojom.h" | |
| 22 #include "components/mus/ws/platform_display_delegate.h" | |
| 23 #include "components/mus/ws/platform_display_init_params.h" | |
| 24 #include "ui/gfx/geometry/rect.h" | |
| 25 #include "ui/platform_window/platform_window_delegate.h" | |
| 26 | |
| 27 namespace cc { | |
| 28 class CompositorFrame; | |
| 29 class CopyOutputRequest; | |
| 30 class SurfaceIdAllocator; | |
| 31 class SurfaceManager; | |
| 32 } // namespace cc | |
| 33 | |
| 34 namespace gles2 { | |
| 35 class GpuState; | |
| 36 } // namespace gles2 | |
| 37 | |
| 38 namespace shell { | |
| 39 class Connector; | |
| 40 } // namespace shell | |
| 41 | |
| 42 namespace ui { | |
| 43 class CursorLoader; | |
| 44 class PlatformWindow; | |
| 45 struct TextInputState; | |
| 46 } // namespace ui | |
| 47 | |
| 48 namespace mus { | |
| 49 | |
| 50 class GpuState; | |
| 51 class SurfacesState; | |
| 52 class DisplayCompositor; | |
| 53 | |
| 54 namespace ws { | |
| 55 | |
| 56 class EventDispatcher; | |
| 57 class PlatformDisplayFactory; | |
| 58 class ServerWindow; | |
| 59 | |
| 60 struct ViewportMetrics { | |
| 61 gfx::Size size_in_pixels; | |
| 62 float device_scale_factor = 0.f; | |
| 63 }; | |
| 64 | |
| 65 // PlatformDisplay is used to connect the root ServerWindow to a display. | |
| 66 class PlatformDisplay { | |
| 67 public: | |
| 68 virtual ~PlatformDisplay() {} | |
| 69 | |
| 70 static PlatformDisplay* Create(const PlatformDisplayInitParams& init_params); | |
| 71 | |
| 72 virtual void Init(PlatformDisplayDelegate* delegate) = 0; | |
| 73 | |
| 74 // Schedules a paint for the specified region in the coordinates of |window|. | |
| 75 virtual void SchedulePaint(const ServerWindow* window, | |
| 76 const gfx::Rect& bounds) = 0; | |
| 77 | |
| 78 virtual void SetViewportSize(const gfx::Size& size) = 0; | |
| 79 | |
| 80 virtual void SetTitle(const base::string16& title) = 0; | |
| 81 | |
| 82 virtual void SetCapture() = 0; | |
| 83 | |
| 84 virtual void ReleaseCapture() = 0; | |
| 85 | |
| 86 virtual void SetCursorById(int32_t cursor) = 0; | |
| 87 | |
| 88 virtual mojom::Rotation GetRotation() = 0; | |
| 89 | |
| 90 virtual float GetDeviceScaleFactor() = 0; | |
| 91 | |
| 92 virtual void UpdateTextInputState(const ui::TextInputState& state) = 0; | |
| 93 virtual void SetImeVisibility(bool visible) = 0; | |
| 94 | |
| 95 // Returns true if a compositor frame has been submitted but not drawn yet. | |
| 96 virtual bool IsFramePending() const = 0; | |
| 97 | |
| 98 virtual void RequestCopyOfOutput( | |
| 99 std::unique_ptr<cc::CopyOutputRequest> output_request) = 0; | |
| 100 | |
| 101 virtual int64_t GetDisplayId() const = 0; | |
| 102 | |
| 103 // Overrides factory for testing. Default (NULL) value indicates regular | |
| 104 // (non-test) environment. | |
| 105 static void set_factory_for_testing(PlatformDisplayFactory* factory) { | |
| 106 PlatformDisplay::factory_ = factory; | |
| 107 } | |
| 108 | |
| 109 private: | |
| 110 // Static factory instance (always NULL for non-test). | |
| 111 static PlatformDisplayFactory* factory_; | |
| 112 }; | |
| 113 | |
| 114 // PlatformDisplay implementation that connects to the services necessary to | |
| 115 // actually display. | |
| 116 class DefaultPlatformDisplay : public PlatformDisplay, | |
| 117 public ui::PlatformWindowDelegate { | |
| 118 public: | |
| 119 explicit DefaultPlatformDisplay(const PlatformDisplayInitParams& init_params); | |
| 120 ~DefaultPlatformDisplay() override; | |
| 121 | |
| 122 // PlatformDisplay: | |
| 123 void Init(PlatformDisplayDelegate* delegate) override; | |
| 124 void SchedulePaint(const ServerWindow* window, | |
| 125 const gfx::Rect& bounds) override; | |
| 126 void SetViewportSize(const gfx::Size& size) override; | |
| 127 void SetTitle(const base::string16& title) override; | |
| 128 void SetCapture() override; | |
| 129 void ReleaseCapture() override; | |
| 130 void SetCursorById(int32_t cursor) override; | |
| 131 float GetDeviceScaleFactor() override; | |
| 132 mojom::Rotation GetRotation() override; | |
| 133 void UpdateTextInputState(const ui::TextInputState& state) override; | |
| 134 void SetImeVisibility(bool visible) override; | |
| 135 bool IsFramePending() const override; | |
| 136 void RequestCopyOfOutput( | |
| 137 std::unique_ptr<cc::CopyOutputRequest> output_request) override; | |
| 138 int64_t GetDisplayId() const override; | |
| 139 | |
| 140 private: | |
| 141 void WantToDraw(); | |
| 142 | |
| 143 // This method initiates a top level redraw of the display. | |
| 144 // TODO(fsamuel): This should use vblank as a signal rather than a timer | |
| 145 // http://crbug.com/533042 | |
| 146 void Draw(); | |
| 147 | |
| 148 // This is called after cc::Display has completed generating a new frame | |
| 149 // for the display. TODO(fsamuel): Idle time processing should happen here | |
| 150 // if there is budget for it. | |
| 151 void DidDraw(cc::SurfaceDrawStatus status); | |
| 152 void UpdateMetrics(const gfx::Size& size, float device_scale_factor); | |
| 153 cc::CompositorFrame GenerateCompositorFrame(); | |
| 154 | |
| 155 // ui::PlatformWindowDelegate: | |
| 156 void OnBoundsChanged(const gfx::Rect& new_bounds) override; | |
| 157 void OnDamageRect(const gfx::Rect& damaged_region) override; | |
| 158 void DispatchEvent(ui::Event* event) override; | |
| 159 void OnCloseRequest() override; | |
| 160 void OnClosed() override; | |
| 161 void OnWindowStateChanged(ui::PlatformWindowState new_state) override; | |
| 162 void OnLostCapture() override; | |
| 163 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget, | |
| 164 float device_scale_factor) override; | |
| 165 void OnAcceleratedWidgetDestroyed() override; | |
| 166 void OnActivationChanged(bool active) override; | |
| 167 | |
| 168 int64_t display_id_; | |
| 169 | |
| 170 scoped_refptr<GpuState> gpu_state_; | |
| 171 scoped_refptr<SurfacesState> surfaces_state_; | |
| 172 PlatformDisplayDelegate* delegate_; | |
| 173 | |
| 174 ViewportMetrics metrics_; | |
| 175 gfx::Rect dirty_rect_; | |
| 176 base::Timer draw_timer_; | |
| 177 bool frame_pending_; | |
| 178 | |
| 179 std::unique_ptr<DisplayCompositor> display_compositor_; | |
| 180 std::unique_ptr<ui::PlatformWindow> platform_window_; | |
| 181 | |
| 182 #if !defined(OS_ANDROID) | |
| 183 std::unique_ptr<ui::CursorLoader> cursor_loader_; | |
| 184 #endif | |
| 185 | |
| 186 base::WeakPtrFactory<DefaultPlatformDisplay> weak_factory_; | |
| 187 | |
| 188 DISALLOW_COPY_AND_ASSIGN(DefaultPlatformDisplay); | |
| 189 }; | |
| 190 | |
| 191 } // namespace ws | |
| 192 | |
| 193 } // namespace mus | |
| 194 | |
| 195 #endif // COMPONENTS_MUS_WS_PLATFORM_DISPLAY_H_ | |
| OLD | NEW |