Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CONTENT_RENDERER_ANDROID_SYNCHRONOUS_COMPOSITOR_OUTPUT_SURFACE_H_ | 5 #ifndef CONTENT_RENDERER_ANDROID_SYNCHRONOUS_COMPOSITOR_OUTPUT_SURFACE_H_ |
| 6 #define CONTENT_RENDERER_ANDROID_SYNCHRONOUS_COMPOSITOR_OUTPUT_SURFACE_H_ | 6 #define CONTENT_RENDERER_ANDROID_SYNCHRONOUS_COMPOSITOR_OUTPUT_SURFACE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/cancelable_callback.h" | 13 #include "base/cancelable_callback.h" |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
| 18 #include "cc/output/compositor_frame.h" | 18 #include "cc/output/compositor_frame.h" |
| 19 #include "cc/output/managed_memory_policy.h" | 19 #include "cc/output/managed_memory_policy.h" |
| 20 #include "cc/output/output_surface.h" | 20 #include "cc/output/output_surface.h" |
| 21 #include "cc/surfaces/display.h" | |
|
boliu
2016/07/07 00:37:54
should be ok to forward declare
danakj
2016/07/07 00:46:30
Done.
| |
| 22 #include "cc/surfaces/display_client.h" | |
| 23 #include "cc/surfaces/surface_factory_client.h" | |
| 21 #include "ipc/ipc_message.h" | 24 #include "ipc/ipc_message.h" |
| 22 #include "ui/gfx/transform.h" | 25 #include "ui/gfx/transform.h" |
| 23 | 26 |
| 24 namespace cc { | 27 namespace cc { |
| 25 class ContextProvider; | 28 class ContextProvider; |
| 26 class CompositorFrameMetadata; | 29 class CompositorFrameMetadata; |
| 30 class SharedBitmapManager; | |
| 31 class SurfaceFactory; | |
| 32 class SurfaceIdAllocator; | |
| 33 class SurfaceManager; | |
| 27 } | 34 } |
| 28 | 35 |
| 29 namespace IPC { | 36 namespace IPC { |
| 30 class Message; | 37 class Message; |
| 31 class Sender; | 38 class Sender; |
| 32 } | 39 } |
| 33 | 40 |
| 34 namespace content { | 41 namespace content { |
| 35 | 42 |
| 36 class FrameSwapMessageQueue; | 43 class FrameSwapMessageQueue; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 50 | 57 |
| 51 // Specialization of the output surface that adapts it to implement the | 58 // Specialization of the output surface that adapts it to implement the |
| 52 // content::SynchronousCompositor public API. This class effects an "inversion | 59 // content::SynchronousCompositor public API. This class effects an "inversion |
| 53 // of control" - enabling drawing to be orchestrated by the embedding | 60 // of control" - enabling drawing to be orchestrated by the embedding |
| 54 // layer, instead of driven by the compositor internals - hence it holds two | 61 // layer, instead of driven by the compositor internals - hence it holds two |
| 55 // 'client' pointers (|client_| in the OutputSurface baseclass and | 62 // 'client' pointers (|client_| in the OutputSurface baseclass and |
| 56 // |delegate_|) which represent the consumers of the two roles in plays. | 63 // |delegate_|) which represent the consumers of the two roles in plays. |
| 57 // This class can be created only on the main thread, but then becomes pinned | 64 // This class can be created only on the main thread, but then becomes pinned |
| 58 // to a fixed thread when BindToClient is called. | 65 // to a fixed thread when BindToClient is called. |
| 59 class SynchronousCompositorOutputSurface | 66 class SynchronousCompositorOutputSurface |
| 60 : NON_EXPORTED_BASE(public cc::OutputSurface) { | 67 : NON_EXPORTED_BASE(public cc::OutputSurface), |
| 68 public cc::SurfaceFactoryClient { | |
| 61 public: | 69 public: |
| 62 SynchronousCompositorOutputSurface( | 70 SynchronousCompositorOutputSurface( |
| 63 scoped_refptr<cc::ContextProvider> context_provider, | 71 scoped_refptr<cc::ContextProvider> context_provider, |
| 64 scoped_refptr<cc::ContextProvider> worker_context_provider, | 72 scoped_refptr<cc::ContextProvider> worker_context_provider, |
| 73 cc::SharedBitmapManager* shared_bitmap_manager, | |
| 65 int routing_id, | 74 int routing_id, |
| 66 uint32_t output_surface_id, | 75 uint32_t output_surface_id, |
| 67 SynchronousCompositorRegistry* registry, | 76 SynchronousCompositorRegistry* registry, |
| 68 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue); | 77 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue); |
| 69 ~SynchronousCompositorOutputSurface() override; | 78 ~SynchronousCompositorOutputSurface() override; |
| 70 | 79 |
| 71 void SetSyncClient(SynchronousCompositorOutputSurfaceClient* compositor); | 80 void SetSyncClient(SynchronousCompositorOutputSurfaceClient* compositor); |
| 72 bool OnMessageReceived(const IPC::Message& message); | 81 bool OnMessageReceived(const IPC::Message& message); |
| 73 | 82 |
| 74 // OutputSurface. | 83 // OutputSurface. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 85 | 94 |
| 86 // Partial SynchronousCompositor API implementation. | 95 // Partial SynchronousCompositor API implementation. |
| 87 void DemandDrawHw(const gfx::Size& surface_size, | 96 void DemandDrawHw(const gfx::Size& surface_size, |
| 88 const gfx::Transform& transform, | 97 const gfx::Transform& transform, |
| 89 const gfx::Rect& viewport, | 98 const gfx::Rect& viewport, |
| 90 const gfx::Rect& clip, | 99 const gfx::Rect& clip, |
| 91 const gfx::Rect& viewport_rect_for_tile_priority, | 100 const gfx::Rect& viewport_rect_for_tile_priority, |
| 92 const gfx::Transform& transform_for_tile_priority); | 101 const gfx::Transform& transform_for_tile_priority); |
| 93 void DemandDrawSw(SkCanvas* canvas); | 102 void DemandDrawSw(SkCanvas* canvas); |
| 94 | 103 |
| 104 // SurfaceFactoryClient implementation. | |
| 105 void ReturnResources(const cc::ReturnedResourceArray& resources) override; | |
| 106 void SetBeginFrameSource(cc::BeginFrameSource* begin_frame_source) override; | |
| 107 | |
| 95 private: | 108 private: |
| 96 class SoftwareDevice; | |
| 97 friend class SoftwareDevice; | |
| 98 | |
| 99 void InvokeComposite(const gfx::Transform& transform, | 109 void InvokeComposite(const gfx::Transform& transform, |
| 100 const gfx::Rect& viewport, | 110 const gfx::Rect& viewport, |
| 101 const gfx::Rect& clip, | 111 const gfx::Rect& clip); |
| 102 bool hardware_draw); | |
| 103 bool Send(IPC::Message* message); | 112 bool Send(IPC::Message* message); |
| 104 void DidActivatePendingTree(); | 113 void DidActivatePendingTree(); |
| 105 void DeliverMessages(); | 114 void DeliverMessages(); |
| 106 bool CalledOnValidThread() const; | 115 bool CalledOnValidThread() const; |
| 107 | 116 |
| 108 void CancelFallbackTick(); | 117 void CancelFallbackTick(); |
| 109 void FallbackTickFired(); | 118 void FallbackTickFired(); |
| 110 | 119 |
| 111 // IPC handlers. | 120 // IPC handlers. |
| 112 void SetMemoryPolicy(size_t bytes_limit); | 121 void SetMemoryPolicy(size_t bytes_limit); |
| 113 void OnReclaimResources(uint32_t output_surface_id, | 122 void OnReclaimResources(uint32_t output_surface_id, |
| 114 const cc::CompositorFrameAck& ack); | 123 const cc::CompositorFrameAck& ack); |
| 115 | 124 |
| 125 cc::SharedBitmapManager* const shared_bitmap_manager_; | |
| 116 const int routing_id_; | 126 const int routing_id_; |
| 117 const uint32_t output_surface_id_; | 127 const uint32_t output_surface_id_; |
| 118 SynchronousCompositorRegistry* const registry_; // Not owned. | 128 SynchronousCompositorRegistry* const registry_; // Not owned. |
| 119 IPC::Sender* const sender_; // Not owned. | 129 IPC::Sender* const sender_; // Not owned. |
| 120 bool registered_; | 130 bool registered_ = false; |
|
boliu
2016/07/07 00:37:54
inline init is just ok for all constant values now
danakj
2016/07/07 00:46:30
For non-constant also. The contructor will set the
| |
| 121 | 131 |
| 122 // Not owned. | 132 // Not owned. |
| 123 SynchronousCompositorOutputSurfaceClient* sync_client_; | 133 SynchronousCompositorOutputSurfaceClient* sync_client_ = nullptr; |
| 124 | 134 |
| 125 // Only valid (non-NULL) during a DemandDrawSw() call. | 135 // Only valid (non-NULL) during a DemandDrawSw() call. |
| 126 SkCanvas* current_sw_canvas_; | 136 SkCanvas* current_sw_canvas_ = nullptr; |
| 127 | 137 |
| 128 cc::ManagedMemoryPolicy memory_policy_; | 138 cc::ManagedMemoryPolicy memory_policy_; |
| 129 bool did_swap_; | 139 bool in_software_draw_ = false; |
| 140 bool did_swap_ = false; | |
| 130 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue_; | 141 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue_; |
| 131 | 142 |
| 132 base::CancelableClosure fallback_tick_; | 143 base::CancelableClosure fallback_tick_; |
| 133 bool fallback_tick_pending_; | 144 bool fallback_tick_pending_ = false; |
| 134 bool fallback_tick_running_; | 145 bool fallback_tick_running_ = false; |
| 146 | |
| 147 class StubDisplayClient : public cc::DisplayClient { | |
| 148 void DisplayOutputSurfaceLost() override {} | |
| 149 void DisplaySetMemoryPolicy( | |
| 150 const cc::ManagedMemoryPolicy& policy) override {} | |
| 151 }; | |
| 152 | |
| 153 // TODO(danakj): These don't to be stored in unique_ptrs when OutputSurface | |
| 154 // is owned/destroyed on the compositor thread. | |
| 155 std::unique_ptr<cc::SurfaceManager> surface_manager_; | |
| 156 std::unique_ptr<cc::SurfaceIdAllocator> surface_id_allocator_; | |
| 157 cc::SurfaceId delegated_surface_id_; | |
| 158 // Uses surface_manager_. | |
| 159 std::unique_ptr<cc::SurfaceFactory> surface_factory_; | |
| 160 StubDisplayClient display_client_; | |
| 161 // Uses surface_manager_. | |
| 162 std::unique_ptr<cc::Display> display_; | |
| 135 | 163 |
| 136 base::ThreadChecker thread_checker_; | 164 base::ThreadChecker thread_checker_; |
| 137 | 165 |
| 138 DISALLOW_COPY_AND_ASSIGN(SynchronousCompositorOutputSurface); | 166 DISALLOW_COPY_AND_ASSIGN(SynchronousCompositorOutputSurface); |
| 139 }; | 167 }; |
| 140 | 168 |
| 141 } // namespace content | 169 } // namespace content |
| 142 | 170 |
| 143 #endif // CONTENT_RENDERER_ANDROID_SYNCHRONOUS_COMPOSITOR_OUTPUT_SURFACE_H_ | 171 #endif // CONTENT_RENDERER_ANDROID_SYNCHRONOUS_COMPOSITOR_OUTPUT_SURFACE_H_ |
| OLD | NEW |