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

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

Issue 226363004: Global GPU memory manager for android webview (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Type casts and private methods in BVR. Created 6 years, 7 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_ 5 #ifndef ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_
6 #define ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_ 6 #define ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_
7 7
8 #include "android_webview/browser/global_tile_manager.h"
9 #include "android_webview/browser/global_tile_manager_client.h"
8 #include "android_webview/browser/shared_renderer_state.h" 10 #include "android_webview/browser/shared_renderer_state.h"
9 #include "base/android/scoped_java_ref.h" 11 #include "base/android/scoped_java_ref.h"
10 #include "base/callback.h" 12 #include "base/callback.h"
11 #include "base/cancelable_callback.h" 13 #include "base/cancelable_callback.h"
12 #include "content/public/browser/android/synchronous_compositor_client.h" 14 #include "content/public/browser/android/synchronous_compositor_client.h"
13 #include "skia/ext/refptr.h" 15 #include "skia/ext/refptr.h"
14 #include "ui/gfx/rect.h" 16 #include "ui/gfx/rect.h"
15 #include "ui/gfx/vector2d_f.h" 17 #include "ui/gfx/vector2d_f.h"
16 18
17 class SkCanvas; 19 class SkCanvas;
18 class SkPicture; 20 class SkPicture;
19 struct AwDrawGLInfo; 21 struct AwDrawGLInfo;
20 struct AwDrawSWFunctionTable; 22 struct AwDrawSWFunctionTable;
21 23
22 namespace content { 24 namespace content {
23 class ContentViewCore; 25 class ContentViewCore;
24 class SynchronousCompositor; 26 class SynchronousCompositor;
27 struct SynchronousCompositorMemoryPolicy;
25 class WebContents; 28 class WebContents;
26 } 29 }
27 30
28 namespace android_webview { 31 namespace android_webview {
29 32
30 class BrowserViewRendererClient; 33 class BrowserViewRendererClient;
31 34
32 // Delegate to perform rendering actions involving Java objects. 35 // Delegate to perform rendering actions involving Java objects.
33 class BrowserViewRendererJavaHelper { 36 class BrowserViewRendererJavaHelper {
34 public: 37 public:
(...skipping 10 matching lines...) Expand all
45 const gfx::Vector2d& scroll_correction, 48 const gfx::Vector2d& scroll_correction,
46 const gfx::Rect& clip, 49 const gfx::Rect& clip,
47 RenderMethod render_source) = 0; 50 RenderMethod render_source) = 0;
48 51
49 protected: 52 protected:
50 virtual ~BrowserViewRendererJavaHelper() {} 53 virtual ~BrowserViewRendererJavaHelper() {}
51 }; 54 };
52 55
53 // Interface for all the WebView-specific content rendering operations. 56 // Interface for all the WebView-specific content rendering operations.
54 // Provides software and hardware rendering and the Capture Picture API. 57 // Provides software and hardware rendering and the Capture Picture API.
55 class BrowserViewRenderer : public content::SynchronousCompositorClient { 58 class BrowserViewRenderer : public content::SynchronousCompositorClient,
59 public GlobalTileManagerClient {
56 public: 60 public:
61 static void CalculateTileMemoryPolicy();
62
57 BrowserViewRenderer( 63 BrowserViewRenderer(
58 BrowserViewRendererClient* client, 64 BrowserViewRendererClient* client,
59 SharedRendererState* shared_renderer_state, 65 SharedRendererState* shared_renderer_state,
60 content::WebContents* web_contents, 66 content::WebContents* web_contents,
61 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner); 67 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner);
62 68
63 virtual ~BrowserViewRenderer(); 69 virtual ~BrowserViewRenderer();
64 70
65 // Main handler for view drawing: performs a SW draw immediately, or sets up 71 // Main handler for view drawing: performs a SW draw immediately, or sets up
66 // a subsequent GL Draw (via BrowserViewRendererClient::RequestDrawGL) and 72 // a subsequent GL Draw (via BrowserViewRendererClient::RequestDrawGL) and
(...skipping 27 matching lines...) Expand all
94 void SetDipScale(float dip_scale); 100 void SetDipScale(float dip_scale);
95 101
96 // Set the root layer scroll offset to |new_value|. 102 // Set the root layer scroll offset to |new_value|.
97 void ScrollTo(gfx::Vector2d new_value); 103 void ScrollTo(gfx::Vector2d new_value);
98 104
99 // Android views hierarchy gluing. 105 // Android views hierarchy gluing.
100 bool IsAttachedToWindow() const; 106 bool IsAttachedToWindow() const;
101 bool IsVisible() const; 107 bool IsVisible() const;
102 gfx::Rect GetScreenRect() const; 108 gfx::Rect GetScreenRect() const;
103 109
104 // Force invoke the compositor to run produce a 1x1 software frame that is 110 // Set the memory policy in shared renderer state and request the tiles from
105 // immediately discarded. This is a hack to force invoke parts of the 111 // GlobalTileManager. The actually amount of memory allowed by
106 // compositor that are not directly exposed here. 112 // GlobalTileManager may not be equal to what's requested in |policy|.
107 void ForceFakeCompositeSW(); 113 void RequestMemoryPolicy(content::SynchronousCompositorMemoryPolicy& policy);
114
115 void TrimMemory(const int level, const bool visible);
108 116
109 // SynchronousCompositorClient overrides 117 // SynchronousCompositorClient overrides
110 virtual void DidInitializeCompositor( 118 virtual void DidInitializeCompositor(
111 content::SynchronousCompositor* compositor) OVERRIDE; 119 content::SynchronousCompositor* compositor) OVERRIDE;
112 virtual void DidDestroyCompositor(content::SynchronousCompositor* compositor) 120 virtual void DidDestroyCompositor(content::SynchronousCompositor* compositor)
113 OVERRIDE; 121 OVERRIDE;
114 virtual void SetContinuousInvalidate(bool invalidate) OVERRIDE; 122 virtual void SetContinuousInvalidate(bool invalidate) OVERRIDE;
115 virtual void SetMaxRootLayerScrollOffset(gfx::Vector2dF new_value) OVERRIDE; 123 virtual void SetMaxRootLayerScrollOffset(gfx::Vector2dF new_value) OVERRIDE;
116 virtual void SetTotalRootLayerScrollOffset(gfx::Vector2dF new_value_css) 124 virtual void SetTotalRootLayerScrollOffset(gfx::Vector2dF new_value_css)
117 OVERRIDE; 125 OVERRIDE;
118 virtual void DidUpdateContent() OVERRIDE; 126 virtual void DidUpdateContent() OVERRIDE;
119 virtual gfx::Vector2dF GetTotalRootLayerScrollOffset() OVERRIDE; 127 virtual gfx::Vector2dF GetTotalRootLayerScrollOffset() OVERRIDE;
120 virtual bool IsExternalFlingActive() const OVERRIDE; 128 virtual bool IsExternalFlingActive() const OVERRIDE;
121 virtual void SetRootLayerPageScaleFactorAndLimits(float page_scale_factor, 129 virtual void SetRootLayerPageScaleFactorAndLimits(float page_scale_factor,
122 float min_page_scale_factor, 130 float min_page_scale_factor,
123 float max_page_scale_factor) 131 float max_page_scale_factor)
124 OVERRIDE; 132 OVERRIDE;
125 virtual void SetRootLayerScrollableSize(gfx::SizeF scrollable_size) OVERRIDE; 133 virtual void SetRootLayerScrollableSize(gfx::SizeF scrollable_size) OVERRIDE;
126 virtual void DidOverscroll(gfx::Vector2dF accumulated_overscroll, 134 virtual void DidOverscroll(gfx::Vector2dF accumulated_overscroll,
127 gfx::Vector2dF latest_overscroll_delta, 135 gfx::Vector2dF latest_overscroll_delta,
128 gfx::Vector2dF current_fling_velocity) OVERRIDE; 136 gfx::Vector2dF current_fling_velocity) OVERRIDE;
129 137
138 // GlobalTileManagerClient overrides
139 virtual size_t GetNumTiles() const OVERRIDE;
140 virtual void SetNumTiles(size_t num_tiles,
141 bool effective_immediately) OVERRIDE;
142
130 private: 143 private:
131 // Checks the continuous invalidate and block invalidate state, and schedule 144 // Checks the continuous invalidate and block invalidate state, and schedule
132 // invalidates appropriately. If |force_invalidate| is true, then send a view 145 // invalidates appropriately. If |force_invalidate| is true, then send a view
133 // invalidate regardless of compositor expectation. 146 // invalidate regardless of compositor expectation.
134 void EnsureContinuousInvalidation(bool force_invalidate); 147 void EnsureContinuousInvalidation(bool force_invalidate);
135 bool DrawSWInternal(jobject java_canvas, const gfx::Rect& clip_bounds); 148 bool DrawSWInternal(jobject java_canvas, const gfx::Rect& clip_bounds);
136 bool CompositeSW(SkCanvas* canvas); 149 bool CompositeSW(SkCanvas* canvas);
137 void DidComposite(bool force_invalidate); 150 void DidComposite(bool force_invalidate);
138 151
139 // If we call up view invalidate and OnDraw is not called before a deadline, 152 // If we call up view invalidate and OnDraw is not called before a deadline,
140 // then we keep ticking the SynchronousCompositor so it can make progress. 153 // then we keep ticking the SynchronousCompositor so it can make progress.
141 void FallbackTickFired(); 154 void FallbackTickFired();
142 155
156 // Force invoke the compositor to run produce a 1x1 software frame that is
157 // immediately discarded. This is a hack to force invoke parts of the
158 // compositor that are not directly exposed here.
159 void ForceFakeCompositeSW();
160
161 void EnforceMemoryPolicyImmediately(
162 content::SynchronousCompositorMemoryPolicy policy);
163
143 gfx::Vector2d max_scroll_offset() const; 164 gfx::Vector2d max_scroll_offset() const;
144 165
166 content::SynchronousCompositorMemoryPolicy CalculateDesiredMemoryPolicy();
145 // For debug tracing or logging. Return the string representation of this 167 // For debug tracing or logging. Return the string representation of this
146 // view renderer's state and the |draw_info| if provided. 168 // view renderer's state and the |draw_info| if provided.
147 std::string ToString(AwDrawGLInfo* draw_info) const; 169 std::string ToString(AwDrawGLInfo* draw_info) const;
148 170
149 BrowserViewRendererClient* client_; 171 BrowserViewRendererClient* client_;
150 SharedRendererState* shared_renderer_state_; 172 SharedRendererState* shared_renderer_state_;
151 content::WebContents* web_contents_; 173 content::WebContents* web_contents_;
152 // TODO(boliu): This class should only be used on the UI thread. However in 174 // TODO(boliu): This class should only be used on the UI thread. However in
153 // short term to supporting HardwareRenderer, some callbacks on 175 // short term to supporting HardwareRenderer, some callbacks on
154 // SynchronousCompositorClient may be called on non-UI thread. These are 176 // SynchronousCompositorClient may be called on non-UI thread. These are
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 gfx::Vector2dF scroll_offset_dip_; 214 gfx::Vector2dF scroll_offset_dip_;
193 215
194 // Max scroll offset in CSS pixels. 216 // Max scroll offset in CSS pixels.
195 gfx::Vector2dF max_scroll_offset_dip_; 217 gfx::Vector2dF max_scroll_offset_dip_;
196 218
197 // Used to prevent rounding errors from accumulating enough to generate 219 // Used to prevent rounding errors from accumulating enough to generate
198 // visible skew (especially noticeable when scrolling up and down in the same 220 // visible skew (especially noticeable when scrolling up and down in the same
199 // spot over a period of time). 221 // spot over a period of time).
200 gfx::Vector2dF overscroll_rounding_error_; 222 gfx::Vector2dF overscroll_rounding_error_;
201 223
224 GlobalTileManager::Key tile_manager_key_;
225
226 // The following 2 are used to construct a memory policy and set the memory
227 // policy on the shared_renderer_state_ atomically.
228 size_t num_tiles_;
229 size_t num_bytes_;
230
202 DISALLOW_COPY_AND_ASSIGN(BrowserViewRenderer); 231 DISALLOW_COPY_AND_ASSIGN(BrowserViewRenderer);
203 }; 232 };
204 233
205 } // namespace android_webview 234 } // namespace android_webview
206 235
207 #endif // ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_ 236 #endif // ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_
OLDNEW
« no previous file with comments | « android_webview/android_webview_tests.gypi ('k') | android_webview/browser/browser_view_renderer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698