| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_MUS_WS_PLATFORM_DISPLAY_H_ | 5 #ifndef COMPONENTS_MUS_WS_FRAME_GENERATOR_H_ |
| 6 #define COMPONENTS_MUS_WS_PLATFORM_DISPLAY_H_ | 6 #define COMPONENTS_MUS_WS_FRAME_GENERATOR_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <map> | |
| 11 #include <memory> | 8 #include <memory> |
| 12 | 9 |
| 13 #include "base/macros.h" | 10 #include "base/macros.h" |
| 14 #include "base/memory/weak_ptr.h" | |
| 15 #include "base/strings/string16.h" | |
| 16 #include "base/timer/timer.h" | 11 #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" | 12 #include "ui/gfx/geometry/rect.h" |
| 25 #include "ui/platform_window/platform_window_delegate.h" | 13 #include "ui/gfx/native_widget_types.h" |
| 26 | 14 |
| 27 namespace cc { | 15 namespace cc { |
| 28 class CompositorFrame; | 16 class CompositorFrame; |
| 29 class CopyOutputRequest; | 17 class CopyOutputRequest; |
| 30 class SurfaceIdAllocator; | 18 class RenderPass; |
| 31 class SurfaceManager; | 19 enum class SurfaceDrawStatus; |
| 32 } // namespace cc | 20 } |
| 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 | 21 |
| 48 namespace mus { | 22 namespace mus { |
| 49 | 23 |
| 24 class DisplayCompositor; |
| 50 class GpuState; | 25 class GpuState; |
| 51 class SurfacesState; | 26 class SurfacesState; |
| 52 class DisplayCompositor; | |
| 53 | 27 |
| 54 namespace ws { | 28 namespace ws { |
| 55 | 29 |
| 56 class EventDispatcher; | 30 class FrameGeneratorDelegate; |
| 57 class PlatformDisplayFactory; | |
| 58 class ServerWindow; | 31 class ServerWindow; |
| 59 | 32 |
| 60 struct ViewportMetrics { | 33 // Responsible for redrawing the display in response to the redraw requests by |
| 61 gfx::Size size_in_pixels; | 34 // submitting CompositorFrames to the owned DisplayCompositor. |
| 62 float device_scale_factor = 0.f; | 35 class FrameGenerator { |
| 63 }; | 36 public: |
| 37 FrameGenerator(FrameGeneratorDelegate* delegate, |
| 38 scoped_refptr<GpuState> gpu_state, |
| 39 scoped_refptr<SurfacesState> surfaces_state); |
| 40 virtual ~FrameGenerator(); |
| 64 | 41 |
| 65 // PlatformDisplay is used to connect the root ServerWindow to a display. | 42 // Schedules a redraw for the provided region. |
| 66 class PlatformDisplay { | 43 void RequestRedraw(const gfx::Rect& redraw_region); |
| 67 public: | 44 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget); |
| 68 virtual ~PlatformDisplay() {} | 45 void RequestCopyOfOutput( |
| 46 std::unique_ptr<cc::CopyOutputRequest> output_request); |
| 69 | 47 |
| 70 static PlatformDisplay* Create(const PlatformDisplayInitParams& init_params); | 48 bool is_frame_pending() { return frame_pending_; } |
| 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 | 49 |
| 140 private: | 50 private: |
| 141 void WantToDraw(); | 51 void WantToDraw(); |
| 142 | 52 |
| 143 // This method initiates a top level redraw of the display. | 53 // This method initiates a top level redraw of the display. |
| 144 // TODO(fsamuel): This should use vblank as a signal rather than a timer | 54 // TODO(fsamuel): This should use vblank as a signal rather than a timer |
| 145 // http://crbug.com/533042 | 55 // http://crbug.com/533042 |
| 146 void Draw(); | 56 void Draw(); |
| 147 | 57 |
| 148 // This is called after cc::Display has completed generating a new frame | 58 // This is called after the DisplayCompositor has completed generating a new |
| 149 // for the display. TODO(fsamuel): Idle time processing should happen here | 59 // frame for the display. TODO(fsamuel): Idle time processing should happen |
| 150 // if there is budget for it. | 60 // here if there is budget for it. |
| 151 void DidDraw(cc::SurfaceDrawStatus status); | 61 void DidDraw(cc::SurfaceDrawStatus status); |
| 152 void UpdateMetrics(const gfx::Size& size, float device_scale_factor); | 62 |
| 63 // Generates the CompositorFrame for the current |dirty_rect_|. |
| 153 std::unique_ptr<cc::CompositorFrame> GenerateCompositorFrame(); | 64 std::unique_ptr<cc::CompositorFrame> GenerateCompositorFrame(); |
| 154 | 65 |
| 155 // ui::PlatformWindowDelegate: | 66 // DrawWindowTree recursively visits ServerWindows, creating a SurfaceDrawQuad |
| 156 void OnBoundsChanged(const gfx::Rect& new_bounds) override; | 67 // for each that lacks one. |
| 157 void OnDamageRect(const gfx::Rect& damaged_region) override; | 68 void DrawWindowTree(cc::RenderPass* pass, |
| 158 void DispatchEvent(ui::Event* event) override; | 69 ServerWindow* window, |
| 159 void OnCloseRequest() override; | 70 const gfx::Vector2d& parent_to_root_origin_offset, |
| 160 void OnClosed() override; | 71 float opacity); |
| 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 | 72 |
| 168 int64_t display_id_; | 73 FrameGeneratorDelegate* delegate_; |
| 169 | |
| 170 scoped_refptr<GpuState> gpu_state_; | 74 scoped_refptr<GpuState> gpu_state_; |
| 171 scoped_refptr<SurfacesState> surfaces_state_; | 75 scoped_refptr<SurfacesState> surfaces_state_; |
| 172 PlatformDisplayDelegate* delegate_; | |
| 173 | 76 |
| 174 ViewportMetrics metrics_; | 77 std::unique_ptr<DisplayCompositor> display_compositor_; |
| 78 |
| 79 // The region that needs to be redrawn next time the compositor frame is |
| 80 // generated. |
| 175 gfx::Rect dirty_rect_; | 81 gfx::Rect dirty_rect_; |
| 176 base::Timer draw_timer_; | 82 base::Timer draw_timer_; |
| 177 bool frame_pending_; | 83 bool frame_pending_ = false; |
| 178 | 84 |
| 179 std::unique_ptr<DisplayCompositor> display_compositor_; | 85 base::WeakPtrFactory<FrameGenerator> weak_factory_; |
| 180 std::unique_ptr<ui::PlatformWindow> platform_window_; | |
| 181 | 86 |
| 182 #if !defined(OS_ANDROID) | 87 DISALLOW_COPY_AND_ASSIGN(FrameGenerator); |
| 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 }; | 88 }; |
| 190 | 89 |
| 191 } // namespace ws | 90 } // namespace ws |
| 192 | 91 |
| 193 } // namespace mus | 92 } // namespace mus |
| 194 | 93 |
| 195 #endif // COMPONENTS_MUS_WS_PLATFORM_DISPLAY_H_ | 94 #endif // COMPONENTS_MUS_WS_FRAME_GENERATOR_H_ |
| OLD | NEW |