| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_BROWSER_RENDERER_HOST_COMPOSITOR_IMPL_ANDROID_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_COMPOSITOR_IMPL_ANDROID_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_COMPOSITOR_IMPL_ANDROID_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_COMPOSITOR_IMPL_ANDROID_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "base/cancelable_callback.h" | 12 #include "base/cancelable_callback.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
| 17 #include "base/timer/timer.h" | 17 #include "base/timer/timer.h" |
| 18 #include "cc/trees/layer_tree_host_client.h" | 18 #include "cc/trees/layer_tree_host_client.h" |
| 19 #include "cc/trees/layer_tree_host_single_thread_client.h" | 19 #include "cc/trees/layer_tree_host_single_thread_client.h" |
| 20 #include "content/common/content_export.h" | 20 #include "content/common/content_export.h" |
| 21 #include "content/common/gpu/client/context_provider_command_buffer.h" | 21 #include "content/common/gpu/client/context_provider_command_buffer.h" |
| 22 #include "content/public/browser/android/compositor.h" | 22 #include "content/public/browser/android/compositor.h" |
| 23 #include "gpu/command_buffer/common/capabilities.h" | 23 #include "gpu/command_buffer/common/capabilities.h" |
| 24 #include "gpu/ipc/common/surface_handle.h" | 24 #include "gpu/ipc/common/surface_handle.h" |
| 25 #include "third_party/khronos/GLES2/gl2.h" | 25 #include "third_party/khronos/GLES2/gl2.h" |
| 26 #include "ui/android/context_provider_factory.h" |
| 26 #include "ui/android/resources/resource_manager_impl.h" | 27 #include "ui/android/resources/resource_manager_impl.h" |
| 27 #include "ui/android/resources/ui_resource_provider.h" | 28 #include "ui/android/resources/ui_resource_provider.h" |
| 28 #include "ui/android/window_android_compositor.h" | 29 #include "ui/android/window_android_compositor.h" |
| 29 | 30 |
| 30 class SkBitmap; | 31 class SkBitmap; |
| 31 struct ANativeWindow; | 32 struct ANativeWindow; |
| 32 | 33 |
| 33 namespace cc { | 34 namespace cc { |
| 34 class Display; | 35 class Display; |
| 35 class Layer; | 36 class Layer; |
| 36 class LayerTreeHost; | 37 class LayerTreeHost; |
| 37 class SurfaceIdAllocator; | 38 class SurfaceIdAllocator; |
| 38 class SurfaceManager; | 39 class SurfaceManager; |
| 40 class VulkanContextProvider; |
| 39 class VulkanInProcessContextProvider; | 41 class VulkanInProcessContextProvider; |
| 40 } | 42 } |
| 41 | 43 |
| 42 namespace content { | 44 namespace content { |
| 43 class CompositorClient; | 45 class CompositorClient; |
| 44 | 46 |
| 45 // ----------------------------------------------------------------------------- | 47 // ----------------------------------------------------------------------------- |
| 46 // Browser-side compositor that manages a tree of content and UI layers. | 48 // Browser-side compositor that manages a tree of content and UI layers. |
| 47 // ----------------------------------------------------------------------------- | 49 // ----------------------------------------------------------------------------- |
| 48 class CONTENT_EXPORT CompositorImpl | 50 class CONTENT_EXPORT CompositorImpl |
| 49 : public Compositor, | 51 : public Compositor, |
| 50 public cc::LayerTreeHostClient, | 52 public cc::LayerTreeHostClient, |
| 51 public cc::LayerTreeHostSingleThreadClient, | 53 public cc::LayerTreeHostSingleThreadClient, |
| 52 public ui::UIResourceProvider, | 54 public ui::UIResourceProvider, |
| 53 public ui::WindowAndroidCompositor { | 55 public ui::WindowAndroidCompositor { |
| 54 public: | 56 public: |
| 55 class VSyncObserver { | 57 class VSyncObserver { |
| 56 public: | 58 public: |
| 57 virtual void OnVSync(base::TimeTicks timebase, | 59 virtual void OnVSync(base::TimeTicks timebase, |
| 58 base::TimeDelta interval) = 0; | 60 base::TimeDelta interval) = 0; |
| 59 }; | 61 }; |
| 60 | 62 |
| 61 CompositorImpl(CompositorClient* client, gfx::NativeWindow root_window); | 63 CompositorImpl(CompositorClient* client, gfx::NativeWindow root_window); |
| 62 ~CompositorImpl() override; | 64 ~CompositorImpl() override; |
| 63 | 65 |
| 64 static bool IsInitialized(); | 66 static bool IsInitialized(); |
| 65 | 67 |
| 66 static cc::SurfaceManager* GetSurfaceManager(); | |
| 67 static uint32_t AllocateSurfaceClientId(); | |
| 68 | |
| 69 static scoped_refptr<cc::VulkanInProcessContextProvider> | |
| 70 SharedVulkanContextProviderAndroid(); | |
| 71 | |
| 72 void PopulateGpuCapabilities(gpu::Capabilities gpu_capabilities); | 68 void PopulateGpuCapabilities(gpu::Capabilities gpu_capabilities); |
| 73 | 69 |
| 74 void AddObserver(VSyncObserver* observer); | 70 void AddObserver(VSyncObserver* observer); |
| 75 void RemoveObserver(VSyncObserver* observer); | 71 void RemoveObserver(VSyncObserver* observer); |
| 76 void OnNeedsBeginFramesChange(bool needs_begin_frames); | 72 void OnNeedsBeginFramesChange(bool needs_begin_frames); |
| 77 | 73 |
| 78 // ui::ResourceProvider implementation. | 74 // ui::ResourceProvider implementation. |
| 79 cc::UIResourceId CreateUIResource(cc::UIResourceClient* client) override; | 75 cc::UIResourceId CreateUIResource(cc::UIResourceClient* client) override; |
| 80 void DeleteUIResource(cc::UIResourceId resource_id) override; | 76 void DeleteUIResource(cc::UIResourceId resource_id) override; |
| 81 bool SupportsETC1NonPowerOfTwo() const override; | 77 bool SupportsETC1NonPowerOfTwo() const override; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 void DidPostSwapBuffers() override; | 111 void DidPostSwapBuffers() override; |
| 116 void DidAbortSwapBuffers() override; | 112 void DidAbortSwapBuffers() override; |
| 117 | 113 |
| 118 // WindowAndroidCompositor implementation. | 114 // WindowAndroidCompositor implementation. |
| 119 void RequestCopyOfOutputOnRootLayer( | 115 void RequestCopyOfOutputOnRootLayer( |
| 120 std::unique_ptr<cc::CopyOutputRequest> request) override; | 116 std::unique_ptr<cc::CopyOutputRequest> request) override; |
| 121 void OnVSync(base::TimeTicks frame_time, | 117 void OnVSync(base::TimeTicks frame_time, |
| 122 base::TimeDelta vsync_period) override; | 118 base::TimeDelta vsync_period) override; |
| 123 void SetNeedsAnimate() override; | 119 void SetNeedsAnimate() override; |
| 124 void SetVisible(bool visible); | 120 void SetVisible(bool visible); |
| 125 void CreateOutputSurface(); | |
| 126 void CreateLayerTreeHost(); | 121 void CreateLayerTreeHost(); |
| 127 | 122 |
| 128 void OnGpuChannelEstablished(); | 123 void HandlePendingOutputSurfaceRequest(); |
| 129 void OnGpuChannelTimeout(); | 124 |
| 125 #if defined(ENABLE_VULKAN) |
| 126 void CreateVulkanOutputSurface(); |
| 127 #endif |
| 128 void CreateCompositorOutputSurface( |
| 129 const scoped_refptr<cc::ContextProvider>& context_provider); |
| 130 void InitializeDisplay( |
| 131 std::unique_ptr<cc::OutputSurface> display_output_surface, |
| 132 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider, |
| 133 scoped_refptr<cc::ContextProvider> context_provider); |
| 130 | 134 |
| 131 // root_layer_ is the persistent internal root layer, while subroot_layer_ | 135 // root_layer_ is the persistent internal root layer, while subroot_layer_ |
| 132 // is the one attached by the compositor client. | 136 // is the one attached by the compositor client. |
| 133 scoped_refptr<cc::Layer> subroot_layer_; | 137 scoped_refptr<cc::Layer> subroot_layer_; |
| 134 | 138 |
| 135 // Destruction order matters here: | 139 // Destruction order matters here: |
| 136 std::unique_ptr<cc::SurfaceIdAllocator> surface_id_allocator_; | 140 std::unique_ptr<cc::SurfaceIdAllocator> surface_id_allocator_; |
| 137 base::ObserverList<VSyncObserver, true> observer_list_; | 141 base::ObserverList<VSyncObserver, true> observer_list_; |
| 138 std::unique_ptr<cc::LayerTreeHost> host_; | 142 std::unique_ptr<cc::LayerTreeHost> host_; |
| 139 ui::ResourceManagerImpl resource_manager_; | 143 ui::ResourceManagerImpl resource_manager_; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 153 | 157 |
| 154 // Whether we need to update animations on the next composite. | 158 // Whether we need to update animations on the next composite. |
| 155 bool needs_animate_; | 159 bool needs_animate_; |
| 156 | 160 |
| 157 // The number of SwapBuffer calls that have not returned and ACK'd from | 161 // The number of SwapBuffer calls that have not returned and ACK'd from |
| 158 // the GPU thread. | 162 // the GPU thread. |
| 159 unsigned int pending_swapbuffers_; | 163 unsigned int pending_swapbuffers_; |
| 160 | 164 |
| 161 size_t num_successive_context_creation_failures_; | 165 size_t num_successive_context_creation_failures_; |
| 162 | 166 |
| 163 base::OneShotTimer establish_gpu_channel_timeout_; | |
| 164 | |
| 165 // Whether there is an OutputSurface request pending from the current | 167 // Whether there is an OutputSurface request pending from the current |
| 166 // |host_|. Becomes |true| if RequestNewOutputSurface is called, and |false| | 168 // |host_|. Becomes |true| if RequestNewOutputSurface is called, and |false| |
| 167 // if |host_| is deleted or we succeed in creating *and* initializing an | 169 // if |host_| is deleted or we succeed in creating *and* initializing an |
| 168 // OutputSurface (which is essentially the contract with cc). | 170 // OutputSurface (which is essentially the contract with cc). |
| 169 bool output_surface_request_pending_; | 171 bool output_surface_request_pending_; |
| 170 | 172 |
| 171 gpu::Capabilities gpu_capabilities_; | 173 gpu::Capabilities gpu_capabilities_; |
| 172 bool needs_begin_frames_; | 174 bool needs_begin_frames_; |
| 173 base::WeakPtrFactory<CompositorImpl> weak_factory_; | 175 base::WeakPtrFactory<CompositorImpl> weak_factory_; |
| 174 | 176 |
| 175 DISALLOW_COPY_AND_ASSIGN(CompositorImpl); | 177 DISALLOW_COPY_AND_ASSIGN(CompositorImpl); |
| 176 }; | 178 }; |
| 177 | 179 |
| 178 } // namespace content | 180 } // namespace content |
| 179 | 181 |
| 180 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITOR_IMPL_ANDROID_H_ | 182 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITOR_IMPL_ANDROID_H_ |
| OLD | NEW |