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

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: address Bo's comments 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 class 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:
57 BrowserViewRenderer( 61 BrowserViewRenderer(
58 BrowserViewRendererClient* client, 62 BrowserViewRendererClient* client,
59 SharedRendererState* shared_renderer_state, 63 SharedRendererState* shared_renderer_state,
60 content::WebContents* web_contents, 64 content::WebContents* web_contents,
61 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner); 65 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner);
62 66
63 virtual ~BrowserViewRenderer(); 67 virtual ~BrowserViewRenderer();
64 68
65 // Main handler for view drawing: performs a SW draw immediately, or sets up 69 // Main handler for view drawing: performs a SW draw immediately, or sets up
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 // Android views hierarchy gluing. 103 // Android views hierarchy gluing.
100 bool IsAttachedToWindow() const; 104 bool IsAttachedToWindow() const;
101 bool IsVisible() const; 105 bool IsVisible() const;
102 gfx::Rect GetScreenRect() const; 106 gfx::Rect GetScreenRect() const;
103 107
104 // Force invoke the compositor to run produce a 1x1 software frame that is 108 // Force invoke the compositor to run produce a 1x1 software frame that is
105 // immediately discarded. This is a hack to force invoke parts of the 109 // immediately discarded. This is a hack to force invoke parts of the
106 // compositor that are not directly exposed here. 110 // compositor that are not directly exposed here.
107 void ForceFakeCompositeSW(); 111 void ForceFakeCompositeSW();
108 112
113 // Set the memory policy in shared renderer state and request the tiles from
114 // GlobalTileManager. The actually amount of memory allowed by
115 // GlobalTileManager may not be equal to what's requested in |policy|.
116 void RequestMemoryPolicy(content::SynchronousCompositorMemoryPolicy& policy);
117
118 void TrimMemory(const int level, const bool visible);
119
109 // SynchronousCompositorClient overrides 120 // SynchronousCompositorClient overrides
110 virtual void DidInitializeCompositor( 121 virtual void DidInitializeCompositor(
111 content::SynchronousCompositor* compositor) OVERRIDE; 122 content::SynchronousCompositor* compositor) OVERRIDE;
112 virtual void DidDestroyCompositor(content::SynchronousCompositor* compositor) 123 virtual void DidDestroyCompositor(content::SynchronousCompositor* compositor)
113 OVERRIDE; 124 OVERRIDE;
114 virtual void SetContinuousInvalidate(bool invalidate) OVERRIDE; 125 virtual void SetContinuousInvalidate(bool invalidate) OVERRIDE;
115 virtual void SetMaxRootLayerScrollOffset(gfx::Vector2dF new_value) OVERRIDE; 126 virtual void SetMaxRootLayerScrollOffset(gfx::Vector2dF new_value) OVERRIDE;
116 virtual void SetTotalRootLayerScrollOffset(gfx::Vector2dF new_value_css) 127 virtual void SetTotalRootLayerScrollOffset(gfx::Vector2dF new_value_css)
117 OVERRIDE; 128 OVERRIDE;
118 virtual void DidUpdateContent() OVERRIDE; 129 virtual void DidUpdateContent() OVERRIDE;
119 virtual gfx::Vector2dF GetTotalRootLayerScrollOffset() OVERRIDE; 130 virtual gfx::Vector2dF GetTotalRootLayerScrollOffset() OVERRIDE;
120 virtual bool IsExternalFlingActive() const OVERRIDE; 131 virtual bool IsExternalFlingActive() const OVERRIDE;
121 virtual void SetRootLayerPageScaleFactorAndLimits(float page_scale_factor, 132 virtual void SetRootLayerPageScaleFactorAndLimits(float page_scale_factor,
122 float min_page_scale_factor, 133 float min_page_scale_factor,
123 float max_page_scale_factor) 134 float max_page_scale_factor)
124 OVERRIDE; 135 OVERRIDE;
125 virtual void SetRootLayerScrollableSize(gfx::SizeF scrollable_size) OVERRIDE; 136 virtual void SetRootLayerScrollableSize(gfx::SizeF scrollable_size) OVERRIDE;
126 virtual void DidOverscroll(gfx::Vector2dF accumulated_overscroll, 137 virtual void DidOverscroll(gfx::Vector2dF accumulated_overscroll,
127 gfx::Vector2dF latest_overscroll_delta, 138 gfx::Vector2dF latest_overscroll_delta,
128 gfx::Vector2dF current_fling_velocity) OVERRIDE; 139 gfx::Vector2dF current_fling_velocity) OVERRIDE;
129 140
141 // GlobalTileManagerClient overrides
142 virtual size_t CalculateTileRequest() const OVERRIDE;
143 virtual bool NeedsEviction() const OVERRIDE;
144 virtual size_t ForceDropTiles() OVERRIDE;
145 virtual size_t GetTilesNum() const OVERRIDE;
146
130 private: 147 private:
131 // Checks the continuous invalidate and block invalidate state, and schedule 148 // Checks the continuous invalidate and block invalidate state, and schedule
132 // invalidates appropriately. If |force_invalidate| is true, then send a view 149 // invalidates appropriately. If |force_invalidate| is true, then send a view
133 // invalidate regardless of compositor expectation. 150 // invalidate regardless of compositor expectation.
134 void EnsureContinuousInvalidation(bool force_invalidate); 151 void EnsureContinuousInvalidation(bool force_invalidate);
135 bool DrawSWInternal(jobject java_canvas, const gfx::Rect& clip_bounds); 152 bool DrawSWInternal(jobject java_canvas, const gfx::Rect& clip_bounds);
136 bool CompositeSW(SkCanvas* canvas); 153 bool CompositeSW(SkCanvas* canvas);
137 void DidComposite(bool force_invalidate); 154 void DidComposite(bool force_invalidate);
138 155
139 // If we call up view invalidate and OnDraw is not called before a deadline, 156 // 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. 157 // then we keep ticking the SynchronousCompositor so it can make progress.
141 void FallbackTickFired(); 158 void FallbackTickFired();
142 159
143 gfx::Vector2d max_scroll_offset() const; 160 gfx::Vector2d max_scroll_offset() const;
144 161
162 content::SynchronousCompositorMemoryPolicy CalculateDesiredMemoryPolicy();
145 // For debug tracing or logging. Return the string representation of this 163 // For debug tracing or logging. Return the string representation of this
146 // view renderer's state and the |draw_info| if provided. 164 // view renderer's state and the |draw_info| if provided.
147 std::string ToString(AwDrawGLInfo* draw_info) const; 165 std::string ToString(AwDrawGLInfo* draw_info) const;
148 166
149 BrowserViewRendererClient* client_; 167 BrowserViewRendererClient* client_;
150 SharedRendererState* shared_renderer_state_; 168 SharedRendererState* shared_renderer_state_;
151 content::WebContents* web_contents_; 169 content::WebContents* web_contents_;
152 // TODO(boliu): This class should only be used on the UI thread. However in 170 // TODO(boliu): This class should only be used on the UI thread. However in
153 // short term to supporting HardwareRenderer, some callbacks on 171 // short term to supporting HardwareRenderer, some callbacks on
154 // SynchronousCompositorClient may be called on non-UI thread. These are 172 // 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_; 210 gfx::Vector2dF scroll_offset_dip_;
193 211
194 // Max scroll offset in CSS pixels. 212 // Max scroll offset in CSS pixels.
195 gfx::Vector2dF max_scroll_offset_dip_; 213 gfx::Vector2dF max_scroll_offset_dip_;
196 214
197 // Used to prevent rounding errors from accumulating enough to generate 215 // Used to prevent rounding errors from accumulating enough to generate
198 // visible skew (especially noticeable when scrolling up and down in the same 216 // visible skew (especially noticeable when scrolling up and down in the same
199 // spot over a period of time). 217 // spot over a period of time).
200 gfx::Vector2dF overscroll_rounding_error_; 218 gfx::Vector2dF overscroll_rounding_error_;
201 219
220 // Number of times the BrowserViewRenderer gets the tile allocation less than
221 // kGrallocHungryLimit.
222 size_t num_consecutive_hungry_frames_;
223 GlobalTileManager::Key tile_manager_key_;
224
202 DISALLOW_COPY_AND_ASSIGN(BrowserViewRenderer); 225 DISALLOW_COPY_AND_ASSIGN(BrowserViewRenderer);
203 }; 226 };
204 227
205 } // namespace android_webview 228 } // namespace android_webview
206 229
207 #endif // ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_ 230 #endif // ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698