| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 ANDROID_WEBVIEW_BROWSER_HARDWARE_RENDERER_H_ | 5 #ifndef ANDROID_WEBVIEW_BROWSER_HARDWARE_RENDERER_H_ |
| 6 #define ANDROID_WEBVIEW_BROWSER_HARDWARE_RENDERER_H_ | 6 #define ANDROID_WEBVIEW_BROWSER_HARDWARE_RENDERER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "android_webview/browser/child_frame.h" | 10 #include "android_webview/browser/child_frame.h" |
| 11 #include "android_webview/browser/compositor_id.h" | 11 #include "android_webview/browser/compositor_id.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "cc/surfaces/compositor_frame_sink_support_client.h" |
| 14 #include "cc/surfaces/frame_sink_id.h" | 15 #include "cc/surfaces/frame_sink_id.h" |
| 15 #include "cc/surfaces/surface_factory_client.h" | |
| 16 #include "cc/surfaces/surface_id.h" | 16 #include "cc/surfaces/surface_id.h" |
| 17 | 17 |
| 18 struct AwDrawGLInfo; | 18 struct AwDrawGLInfo; |
| 19 | 19 |
| 20 namespace cc { | 20 namespace cc { |
| 21 class SurfaceFactory; | 21 class CompositorFrameSinkSupport; |
| 22 class LocalSurfaceIdAllocator; | 22 class LocalSurfaceIdAllocator; |
| 23 } | 23 } |
| 24 | 24 |
| 25 namespace android_webview { | 25 namespace android_webview { |
| 26 | 26 |
| 27 class ChildFrame; | 27 class ChildFrame; |
| 28 class RenderThreadManager; | 28 class RenderThreadManager; |
| 29 class SurfacesInstance; | 29 class SurfacesInstance; |
| 30 | 30 |
| 31 class HardwareRenderer : public cc::SurfaceFactoryClient { | 31 class HardwareRenderer : public cc::CompositorFrameSinkSupportClient { |
| 32 public: | 32 public: |
| 33 // Two rules: | 33 // Two rules: |
| 34 // 1) Never wait on |new_frame| on the UI thread, or in kModeSync. Otherwise | 34 // 1) Never wait on |new_frame| on the UI thread, or in kModeSync. Otherwise |
| 35 // this defeats the purpose of having a future. | 35 // this defeats the purpose of having a future. |
| 36 // 2) Never replace a non-empty frames with an empty frame. | 36 // 2) Never replace a non-empty frames with an empty frame. |
| 37 // The only way to do both is to hold up to two frames here. This is a helper | 37 // The only way to do both is to hold up to two frames here. This is a helper |
| 38 // method to do this. General pattern is call this method to prune existing | 38 // method to do this. General pattern is call this method to prune existing |
| 39 // queue, and then append the new frame. Wait on all frames in queue. Then | 39 // queue, and then append the new frame. Wait on all frames in queue. Then |
| 40 // remove all except the latest non-empty frame. If all frames are empty, | 40 // remove all except the latest non-empty frame. If all frames are empty, |
| 41 // then the deque is cleared. Return any non-empty frames that are pruned. | 41 // then the deque is cleared. Return any non-empty frames that are pruned. |
| 42 // Return value does not guarantee relative order is maintained. | 42 // Return value does not guarantee relative order is maintained. |
| 43 static ChildFrameQueue WaitAndPruneFrameQueue(ChildFrameQueue* child_frames); | 43 static ChildFrameQueue WaitAndPruneFrameQueue(ChildFrameQueue* child_frames); |
| 44 | 44 |
| 45 explicit HardwareRenderer(RenderThreadManager* state); | 45 explicit HardwareRenderer(RenderThreadManager* state); |
| 46 ~HardwareRenderer() override; | 46 ~HardwareRenderer() override; |
| 47 | 47 |
| 48 void DrawGL(AwDrawGLInfo* draw_info); | 48 void DrawGL(AwDrawGLInfo* draw_info); |
| 49 void CommitFrame(); | 49 void CommitFrame(); |
| 50 | 50 |
| 51 private: | 51 private: |
| 52 // cc::SurfaceFactoryClient implementation. | 52 // cc::CompositorFrameSinkSupportClient implementation. |
| 53 void ReturnResources(const cc::ReturnedResourceArray& resources) override; | 53 void DidReceiveCompositorFrameAck() override; |
| 54 void SetBeginFrameSource(cc::BeginFrameSource* begin_frame_source) override; | 54 void OnBeginFrame(const cc::BeginFrameArgs& args) override; |
| 55 void ReclaimResources(const cc::ReturnedResourceArray& resources) override; |
| 56 void WillDrawSurface(const cc::LocalSurfaceId& local_surface_id, |
| 57 const gfx::Rect& damage_rect) override; |
| 55 | 58 |
| 56 void ReturnChildFrame(std::unique_ptr<ChildFrame> child_frame); | 59 void ReturnChildFrame(std::unique_ptr<ChildFrame> child_frame); |
| 57 void ReturnResourcesToCompositor(const cc::ReturnedResourceArray& resources, | 60 void ReturnResourcesToCompositor(const cc::ReturnedResourceArray& resources, |
| 58 const CompositorID& compositor_id, | 61 const CompositorID& compositor_id, |
| 59 uint32_t compositor_frame_sink_id); | 62 uint32_t compositor_frame_sink_id); |
| 60 | 63 |
| 61 void AllocateSurface(); | 64 void AllocateSurface(); |
| 62 void DestroySurface(); | 65 void DestroySurface(); |
| 63 | 66 |
| 67 void CreateNewCompositorFrameSinkSupport(); |
| 68 |
| 64 RenderThreadManager* render_thread_manager_; | 69 RenderThreadManager* render_thread_manager_; |
| 65 | 70 |
| 66 typedef void* EGLContext; | 71 typedef void* EGLContext; |
| 67 EGLContext last_egl_context_; | 72 EGLContext last_egl_context_; |
| 68 | 73 |
| 69 // Information about last delegated frame. | 74 // Information about last delegated frame. |
| 70 gfx::Size frame_size_; | 75 gfx::Size frame_size_; |
| 71 | 76 |
| 72 // Infromation from UI on last commit. | 77 // Infromation from UI on last commit. |
| 73 gfx::Vector2d scroll_offset_; | 78 gfx::Vector2d scroll_offset_; |
| 74 | 79 |
| 75 ChildFrameQueue child_frame_queue_; | 80 ChildFrameQueue child_frame_queue_; |
| 76 | 81 |
| 77 // This holds the last ChildFrame received. Contains the frame info of the | 82 // This holds the last ChildFrame received. Contains the frame info of the |
| 78 // last frame. The |frame| member is always null since frame has already | 83 // last frame. The |frame| member is always null since frame has already |
| 79 // been submitted. | 84 // been submitted. |
| 80 std::unique_ptr<ChildFrame> child_frame_; | 85 std::unique_ptr<ChildFrame> child_frame_; |
| 81 | 86 |
| 82 const scoped_refptr<SurfacesInstance> surfaces_; | 87 const scoped_refptr<SurfacesInstance> surfaces_; |
| 83 cc::FrameSinkId frame_sink_id_; | 88 cc::FrameSinkId frame_sink_id_; |
| 84 const std::unique_ptr<cc::LocalSurfaceIdAllocator> | 89 const std::unique_ptr<cc::LocalSurfaceIdAllocator> |
| 85 local_surface_id_allocator_; | 90 local_surface_id_allocator_; |
| 86 std::unique_ptr<cc::SurfaceFactory> surface_factory_; | 91 std::unique_ptr<cc::CompositorFrameSinkSupport> support_; |
| 87 cc::LocalSurfaceId child_id_; | 92 cc::LocalSurfaceId child_id_; |
| 88 CompositorID compositor_id_; | 93 CompositorID compositor_id_; |
| 89 // HardwareRenderer guarantees resources are returned in the order of | 94 // HardwareRenderer guarantees resources are returned in the order of |
| 90 // compositor_frame_sink_id, and resources for old output surfaces are | 95 // compositor_frame_sink_id, and resources for old output surfaces are |
| 91 // dropped. | 96 // dropped. |
| 92 uint32_t last_committed_compositor_frame_sink_id_; | 97 uint32_t last_committed_compositor_frame_sink_id_; |
| 93 uint32_t last_submitted_compositor_frame_sink_id_; | 98 uint32_t last_submitted_compositor_frame_sink_id_; |
| 94 | 99 |
| 95 DISALLOW_COPY_AND_ASSIGN(HardwareRenderer); | 100 DISALLOW_COPY_AND_ASSIGN(HardwareRenderer); |
| 96 }; | 101 }; |
| 97 | 102 |
| 98 } // namespace android_webview | 103 } // namespace android_webview |
| 99 | 104 |
| 100 #endif // ANDROID_WEBVIEW_BROWSER_HARDWARE_RENDERER_H_ | 105 #endif // ANDROID_WEBVIEW_BROWSER_HARDWARE_RENDERER_H_ |
| OLD | NEW |