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

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: Remove unnecessary code 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"
8 #include "android_webview/browser/shared_renderer_state.h" 9 #include "android_webview/browser/shared_renderer_state.h"
10 #include "android_webview/browser/tile_resource_consumer.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:
35 static BrowserViewRendererJavaHelper* GetInstance(); 38 static BrowserViewRendererJavaHelper* GetInstance();
36 39
37 typedef base::Callback<bool(SkCanvas*)> RenderMethod; 40 typedef base::Callback<bool(SkCanvas*)> RenderMethod;
38
boliu 2014/04/28 22:22:15 spurious delete
hush (inactive) 2014/04/30 20:50:17 Done.
39 // Try obtaining the native SkCanvas from |java_canvas| and call 41 // Try obtaining the native SkCanvas from |java_canvas| and call
40 // |render_source| with it. If that fails, allocate an auxilary bitmap 42 // |render_source| with it. If that fails, allocate an auxilary bitmap
41 // for |render_source| to render into, then copy the bitmap into 43 // for |render_source| to render into, then copy the bitmap into
42 // |java_canvas|. 44 // |java_canvas|.
43 virtual bool RenderViaAuxilaryBitmapIfNeeded( 45 virtual bool RenderViaAuxilaryBitmapIfNeeded(
44 jobject java_canvas, 46 jobject java_canvas,
45 const gfx::Vector2d& scroll_correction, 47 const gfx::Vector2d& scroll_correction,
46 const gfx::Rect& clip, 48 const gfx::Rect& clip,
47 RenderMethod render_source) = 0; 49 RenderMethod render_source) = 0;
48 50
49 protected: 51 protected:
50 virtual ~BrowserViewRendererJavaHelper() {} 52 virtual ~BrowserViewRendererJavaHelper() {}
51 }; 53 };
52 54
53 // Interface for all the WebView-specific content rendering operations. 55 // Interface for all the WebView-specific content rendering operations.
54 // Provides software and hardware rendering and the Capture Picture API. 56 // Provides software and hardware rendering and the Capture Picture API.
55 class BrowserViewRenderer : public content::SynchronousCompositorClient { 57 class BrowserViewRenderer : public content::SynchronousCompositorClient,
58 public TileResourceConsumer {
56 public: 59 public:
57 BrowserViewRenderer( 60 BrowserViewRenderer(
58 BrowserViewRendererClient* client, 61 BrowserViewRendererClient* client,
59 SharedRendererState* shared_renderer_state, 62 SharedRendererState* shared_renderer_state,
60 content::WebContents* web_contents, 63 content::WebContents* web_contents,
61 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner); 64 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner);
62 65
63 virtual ~BrowserViewRenderer(); 66 virtual ~BrowserViewRenderer();
64 67
65 // Main handler for view drawing: performs a SW draw immediately, or sets up 68 // Main handler for view drawing: performs a SW draw immediately, or sets up
(...skipping 28 matching lines...) Expand all
94 void SetDipScale(float dip_scale); 97 void SetDipScale(float dip_scale);
95 98
96 // Set the root layer scroll offset to |new_value|. 99 // Set the root layer scroll offset to |new_value|.
97 void ScrollTo(gfx::Vector2d new_value); 100 void ScrollTo(gfx::Vector2d new_value);
98 101
99 // Android views hierarchy gluing. 102 // Android views hierarchy gluing.
100 bool IsAttachedToWindow() const; 103 bool IsAttachedToWindow() const;
101 bool IsVisible() const; 104 bool IsVisible() const;
102 gfx::Rect GetScreenRect() const; 105 gfx::Rect GetScreenRect() const;
103 106
107
boliu 2014/04/28 22:22:15 spurious new line
hush (inactive) 2014/04/30 20:50:17 Done.
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 // Request memory from GLViewRendererManager. The actually amount of memory
114 // allowed by GLViewRendererManager may not be equal to what's requested in
115 // |policy|.
116 void SetMemoryPolicy(content::SynchronousCompositorMemoryPolicy& policy);
boliu 2014/04/28 22:22:15 Comment does not match function at all
hush (inactive) 2014/04/30 20:50:17 Changed comments On 2014/04/28 22:22:15, boliu wro
117
118 void TrimMemory();
109 // SynchronousCompositorClient overrides 119 // SynchronousCompositorClient overrides
110 virtual void DidInitializeCompositor( 120 virtual void DidInitializeCompositor(
111 content::SynchronousCompositor* compositor) OVERRIDE; 121 content::SynchronousCompositor* compositor) OVERRIDE;
112 virtual void DidDestroyCompositor(content::SynchronousCompositor* compositor) 122 virtual void DidDestroyCompositor(content::SynchronousCompositor* compositor)
113 OVERRIDE; 123 OVERRIDE;
114 virtual void SetContinuousInvalidate(bool invalidate) OVERRIDE; 124 virtual void SetContinuousInvalidate(bool invalidate) OVERRIDE;
115 virtual void SetMaxRootLayerScrollOffset(gfx::Vector2dF new_value) OVERRIDE; 125 virtual void SetMaxRootLayerScrollOffset(gfx::Vector2dF new_value) OVERRIDE;
116 virtual void SetTotalRootLayerScrollOffset(gfx::Vector2dF new_value_css) 126 virtual void SetTotalRootLayerScrollOffset(gfx::Vector2dF new_value_css)
117 OVERRIDE; 127 OVERRIDE;
118 virtual void DidUpdateContent() OVERRIDE; 128 virtual void DidUpdateContent() OVERRIDE;
119 virtual gfx::Vector2dF GetTotalRootLayerScrollOffset() OVERRIDE; 129 virtual gfx::Vector2dF GetTotalRootLayerScrollOffset() OVERRIDE;
120 virtual bool IsExternalFlingActive() const OVERRIDE; 130 virtual bool IsExternalFlingActive() const OVERRIDE;
121 virtual void SetRootLayerPageScaleFactorAndLimits(float page_scale_factor, 131 virtual void SetRootLayerPageScaleFactorAndLimits(float page_scale_factor,
122 float min_page_scale_factor, 132 float min_page_scale_factor,
123 float max_page_scale_factor) 133 float max_page_scale_factor)
124 OVERRIDE; 134 OVERRIDE;
125 virtual void SetRootLayerScrollableSize(gfx::SizeF scrollable_size) OVERRIDE; 135 virtual void SetRootLayerScrollableSize(gfx::SizeF scrollable_size) OVERRIDE;
126 virtual void DidOverscroll(gfx::Vector2dF accumulated_overscroll, 136 virtual void DidOverscroll(gfx::Vector2dF accumulated_overscroll,
127 gfx::Vector2dF latest_overscroll_delta, 137 gfx::Vector2dF latest_overscroll_delta,
128 gfx::Vector2dF current_fling_velocity) OVERRIDE; 138 gfx::Vector2dF current_fling_velocity) OVERRIDE;
129 139
140 // TileResourceConsumer overrides
141 // Calculate how many tiles are needed.
142 size_t CalculateTileRequest() OVERRIDE;
boliu 2014/04/28 22:22:15 virtual, and move comments to the interface
hush (inactive) 2014/04/30 20:50:17 Done.
143 // Force drop the hardware tiles in gpu.
144 size_t ForceDropTiles() OVERRIDE;
145 // If the BrowserViewRenderer gets hungry for more than kStarvedTimes in a
146 // row, it becomes starved.
147 bool IsStarved() OVERRIDE;
148
130 private: 149 private:
131 // Checks the continuous invalidate and block invalidate state, and schedule 150 // Checks the continuous invalidate and block invalidate state, and schedule
132 // invalidates appropriately. If |force_invalidate| is true, then send a view 151 // invalidates appropriately. If |force_invalidate| is true, then send a view
133 // invalidate regardless of compositor expectation. 152 // invalidate regardless of compositor expectation.
134 void EnsureContinuousInvalidation(bool force_invalidate); 153 void EnsureContinuousInvalidation(bool force_invalidate);
135 bool DrawSWInternal(jobject java_canvas, const gfx::Rect& clip_bounds); 154 bool DrawSWInternal(jobject java_canvas, const gfx::Rect& clip_bounds);
136 bool CompositeSW(SkCanvas* canvas); 155 bool CompositeSW(SkCanvas* canvas);
137 void DidComposite(bool force_invalidate); 156 void DidComposite(bool force_invalidate);
138 157
139 // If we call up view invalidate and OnDraw is not called before a deadline, 158 // 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. 159 // then we keep ticking the SynchronousCompositor so it can make progress.
141 void FallbackTickFired(); 160 void FallbackTickFired();
142 161
143 gfx::Vector2d max_scroll_offset() const; 162 gfx::Vector2d max_scroll_offset() const;
144 163
164 content::SynchronousCompositorMemoryPolicy CalculateMemoryPolicy();
145 // For debug tracing or logging. Return the string representation of this 165 // For debug tracing or logging. Return the string representation of this
146 // view renderer's state and the |draw_info| if provided. 166 // view renderer's state and the |draw_info| if provided.
147 std::string ToString(AwDrawGLInfo* draw_info) const; 167 std::string ToString(AwDrawGLInfo* draw_info) const;
148 168
149 BrowserViewRendererClient* client_; 169 BrowserViewRendererClient* client_;
150 SharedRendererState* shared_renderer_state_; 170 SharedRendererState* shared_renderer_state_;
151 content::WebContents* web_contents_; 171 content::WebContents* web_contents_;
152 // TODO(boliu): This class should only be used on the UI thread. However in 172 // TODO(boliu): This class should only be used on the UI thread. However in
153 // short term to supporting HardwareRenderer, some callbacks on 173 // short term to supporting HardwareRenderer, some callbacks on
154 // SynchronousCompositorClient may be called on non-UI thread. These are 174 // 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_; 212 gfx::Vector2dF scroll_offset_dip_;
193 213
194 // Max scroll offset in CSS pixels. 214 // Max scroll offset in CSS pixels.
195 gfx::Vector2dF max_scroll_offset_dip_; 215 gfx::Vector2dF max_scroll_offset_dip_;
196 216
197 // Used to prevent rounding errors from accumulating enough to generate 217 // Used to prevent rounding errors from accumulating enough to generate
198 // visible skew (especially noticeable when scrolling up and down in the same 218 // visible skew (especially noticeable when scrolling up and down in the same
199 // spot over a period of time). 219 // spot over a period of time).
200 gfx::Vector2dF overscroll_rounding_error_; 220 gfx::Vector2dF overscroll_rounding_error_;
201 221
222 // Number of times the BrowserViewRenderer gets the tile allocation less than
223 // kGrallocHungryLimit.
boliu 2014/04/28 22:22:15 s/kGrallocHungryLimit/CalculateTileRequest/
hush (inactive) 2014/04/30 20:50:17 CalculateTileRequest returns kNumGrallocLimit (150
224 size_t num_hungry_;
boliu 2014/04/28 22:22:15 num_consecutive_hungry_frames_?
hush (inactive) 2014/04/30 20:50:17 Done.
225 GlobalTileManager::Key tile_manager_key_;
226
202 DISALLOW_COPY_AND_ASSIGN(BrowserViewRenderer); 227 DISALLOW_COPY_AND_ASSIGN(BrowserViewRenderer);
203 }; 228 };
204 229
205 } // namespace android_webview 230 } // namespace android_webview
206 231
207 #endif // ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_ 232 #endif // ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698