Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(442)

Side by Side Diff: android_webview/browser/shared_renderer_state.h

Issue 653173004: Part 2: WIP Refactor Webview graphics related code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rewrite rebase, without renames Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_SHARED_RENDERER_STATE_H_ 5 #ifndef ANDROID_WEBVIEW_BROWSER_SHARED_RENDERER_STATE_H_
6 #define ANDROID_WEBVIEW_BROWSER_SHARED_RENDERER_STATE_H_ 6 #define ANDROID_WEBVIEW_BROWSER_SHARED_RENDERER_STATE_H_
7 7
8 #include "android_webview/browser/gl_view_renderer_manager.h"
8 #include "android_webview/browser/parent_compositor_draw_constraints.h" 9 #include "android_webview/browser/parent_compositor_draw_constraints.h"
9 #include "base/cancelable_callback.h" 10 #include "base/cancelable_callback.h"
10 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
11 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
12 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
13 #include "cc/output/compositor_frame.h" 14 #include "cc/output/compositor_frame.h"
14 #include "cc/output/compositor_frame_ack.h" 15 #include "cc/output/compositor_frame_ack.h"
15 #include "ui/gfx/geometry/rect.h" 16 #include "ui/gfx/geometry/rect.h"
16 #include "ui/gfx/geometry/vector2d.h" 17 #include "ui/gfx/geometry/vector2d.h"
17 18
19 struct AwDrawGLInfo;
20
18 namespace android_webview { 21 namespace android_webview {
19 22
20 namespace internal { 23 namespace internal {
21 class RequestDrawGLTracker; 24 class RequestDrawGLTracker;
22 } 25 }
23 26
24 class BrowserViewRenderer; 27 class BrowserViewRenderer;
28 class HardwareRenderer;
25 class InsideHardwareReleaseReset; 29 class InsideHardwareReleaseReset;
26 30
27 // This class is used to pass data between UI thread and RenderThread. 31 // This class is used to pass data between UI thread and RenderThread.
28 // TODO(hush): this class should own HardwareRenderer.
29 class SharedRendererState { 32 class SharedRendererState {
30 public: 33 public:
31 SharedRendererState( 34 SharedRendererState(
32 const scoped_refptr<base::SingleThreadTaskRunner>& ui_loop, 35 const scoped_refptr<base::SingleThreadTaskRunner>& ui_loop,
33 BrowserViewRenderer* browser_view_renderer); 36 BrowserViewRenderer* browser_view_renderer);
34 ~SharedRendererState(); 37 ~SharedRendererState();
35 38
39 // This function can be called from any thread.
36 void ClientRequestDrawGL(); 40 void ClientRequestDrawGL();
37 void DidDrawGLProcess();
38 41
42 // UI thread methods.
39 void SetScrollOffsetOnUI(gfx::Vector2d scroll_offset); 43 void SetScrollOffsetOnUI(gfx::Vector2d scroll_offset);
40 gfx::Vector2d GetScrollOffsetOnRT();
41
42 bool HasCompositorFrameOnUI() const; 44 bool HasCompositorFrameOnUI() const;
43 void SetCompositorFrameOnUI(scoped_ptr<cc::CompositorFrame> frame, 45 void SetCompositorFrameOnUI(scoped_ptr<cc::CompositorFrame> frame,
44 bool force_commit); 46 bool force_commit);
45 // Right now this method is called on both UI and RT. 47 void InitializeHardwareDrawIfNeededOnUI();
46 // TODO(hush): Make it only called from RT. 48 void ReleaseHardwareDrawIfNeededOnUI();
47 scoped_ptr<cc::CompositorFrame> PassCompositorFrame(); 49 ParentCompositorDrawConstraints GetParentDrawConstraintsOnUI() const;
50 void SetForceInvalidateOnNextDrawGLOnUI(
51 bool needs_force_invalidate_on_next_draw_gl);
52 bool NeedsForceInvalidateOnNextDrawGLOnUI() const;
53 void SwapReturnedResourcesOnUI(cc::ReturnedResourceArray* resources);
54 bool ReturnedResourcesEmptyOnUI() const;
55
56 // RT thread methods.
57 gfx::Vector2d GetScrollOffsetOnRT();
58 scoped_ptr<cc::CompositorFrame> PassCompositorFrameOnRT();
48 bool ForceCommitOnRT() const; 59 bool ForceCommitOnRT() const;
49 60 void DrawGL(AwDrawGLInfo* draw_info);
50 // TODO(hush): this will be private after DrawGL moves to this class.
51 bool IsInsideHardwareRelease() const;
52 // Returns true if the draw constraints are updated. 61 // Returns true if the draw constraints are updated.
53 bool UpdateDrawConstraintsOnRT( 62 bool UpdateDrawConstraintsOnRT(
54 const ParentCompositorDrawConstraints& parent_draw_constraints); 63 const ParentCompositorDrawConstraints& parent_draw_constraints);
55 void PostExternalDrawConstraintsToChildCompositorOnRT( 64 void PostExternalDrawConstraintsToChildCompositorOnRT(
56 const ParentCompositorDrawConstraints& parent_draw_constraints); 65 const ParentCompositorDrawConstraints& parent_draw_constraints);
57 ParentCompositorDrawConstraints GetParentDrawConstraintsOnUI() const;
58
59 void DidSkipCommitFrameOnRT(); 66 void DidSkipCommitFrameOnRT();
60 void SetForceInvalidateOnNextDrawGLOnUI(
61 bool needs_force_invalidate_on_next_draw_gl);
62 bool NeedsForceInvalidateOnNextDrawGLOnUI() const;
63
64 void InsertReturnedResourcesOnRT(const cc::ReturnedResourceArray& resources); 67 void InsertReturnedResourcesOnRT(const cc::ReturnedResourceArray& resources);
65 void SwapReturnedResourcesOnUI(cc::ReturnedResourceArray* resources);
66 bool ReturnedResourcesEmpty() const;
67 68
68 private: 69 private:
69 friend class InsideHardwareReleaseReset;
70 friend class internal::RequestDrawGLTracker; 70 friend class internal::RequestDrawGLTracker;
71 71
72 // RT thread method.
73 void DidDrawGLProcess();
74
75 // UI thread methods.
72 void ResetRequestDrawGLCallback(); 76 void ResetRequestDrawGLCallback();
73 void ClientRequestDrawGLOnUIThread(); 77 void ClientRequestDrawGLOnUI();
74 void UpdateParentDrawConstraintsOnUIThread(); 78 void UpdateParentDrawConstraintsOnUI();
75 void DidSkipCommitFrameOnUI(); 79 void DidSkipCommitFrameOnUI();
80 void ReturnUnusedResourceOnUI();
81 bool IsInsideHardwareRelease() const;
76 void SetInsideHardwareRelease(bool inside); 82 void SetInsideHardwareRelease(bool inside);
77 83
84 // Accessed by UI thread.
78 scoped_refptr<base::SingleThreadTaskRunner> ui_loop_; 85 scoped_refptr<base::SingleThreadTaskRunner> ui_loop_;
79 BrowserViewRenderer* browser_view_renderer_; 86 BrowserViewRenderer* browser_view_renderer_;
80 base::WeakPtr<SharedRendererState> ui_thread_weak_ptr_; 87 base::WeakPtr<SharedRendererState> ui_thread_weak_ptr_;
81 base::CancelableClosure request_draw_gl_cancelable_closure_; 88 base::CancelableClosure request_draw_gl_cancelable_closure_;
89 GLViewRendererManager::Key renderer_manager_key_;
boliu 2014/10/28 19:49:43 This is both UI and RT Although...I think this ca
hush (inactive) 2014/10/29 19:57:04 I see. Make the pushback and removal of the key ha
90
91 // Accessed by RT thread.
92 scoped_ptr<HardwareRenderer> hardware_renderer_;
82 93
83 // Accessed by both UI and RT thread. 94 // Accessed by both UI and RT thread.
84 mutable base::Lock lock_; 95 mutable base::Lock lock_;
85 gfx::Vector2d scroll_offset_; 96 gfx::Vector2d scroll_offset_;
86 scoped_ptr<cc::CompositorFrame> compositor_frame_; 97 scoped_ptr<cc::CompositorFrame> compositor_frame_;
87 bool force_commit_; 98 bool force_commit_;
88 bool inside_hardware_release_; 99 bool inside_hardware_release_;
89 bool needs_force_invalidate_on_next_draw_gl_; 100 bool needs_force_invalidate_on_next_draw_gl_;
90 ParentCompositorDrawConstraints parent_draw_constraints_; 101 ParentCompositorDrawConstraints parent_draw_constraints_;
91 cc::ReturnedResourceArray returned_resources_; 102 cc::ReturnedResourceArray returned_resources_;
92 base::Closure request_draw_gl_closure_; 103 base::Closure request_draw_gl_closure_;
93 104
94 base::WeakPtrFactory<SharedRendererState> weak_factory_on_ui_thread_; 105 base::WeakPtrFactory<SharedRendererState> weak_factory_on_ui_thread_;
95 106
96 DISALLOW_COPY_AND_ASSIGN(SharedRendererState); 107 DISALLOW_COPY_AND_ASSIGN(SharedRendererState);
97 }; 108 };
98 109
99 class InsideHardwareReleaseReset {
100 public:
101 explicit InsideHardwareReleaseReset(
102 SharedRendererState* shared_renderer_state);
103 ~InsideHardwareReleaseReset();
104
105 private:
106 SharedRendererState* shared_renderer_state_;
107
108 DISALLOW_COPY_AND_ASSIGN(InsideHardwareReleaseReset);
109 };
110
111 } // namespace android_webview 110 } // namespace android_webview
112 111
113 #endif // ANDROID_WEBVIEW_BROWSER_SHARED_RENDERER_STATE_H_ 112 #endif // ANDROID_WEBVIEW_BROWSER_SHARED_RENDERER_STATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698