Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 // 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 | 111 // immediately discarded. This is a hack to force invoke parts of the |
| 106 // compositor that are not directly exposed here. | 112 // compositor that are not directly exposed here. |
| 107 void ForceFakeCompositeSW(); | 113 void ForceFakeCompositeSW(); |
| 114 void EnforceMemoryPolicyImmediately( | |
| 115 content::SynchronousCompositorMemoryPolicy policy); | |
|
boliu
2014/05/02 22:39:17
I think these two methods can become private now.
| |
| 116 | |
| 117 // Set the memory policy in shared renderer state and request the tiles from | |
| 118 // GlobalTileManager. The actually amount of memory allowed by | |
| 119 // GlobalTileManager may not be equal to what's requested in |policy|. | |
| 120 void RequestMemoryPolicy(content::SynchronousCompositorMemoryPolicy& policy); | |
| 121 | |
| 122 void TrimMemory(const int level, const bool visible); | |
| 108 | 123 |
| 109 // SynchronousCompositorClient overrides | 124 // SynchronousCompositorClient overrides |
| 110 virtual void DidInitializeCompositor( | 125 virtual void DidInitializeCompositor( |
| 111 content::SynchronousCompositor* compositor) OVERRIDE; | 126 content::SynchronousCompositor* compositor) OVERRIDE; |
| 112 virtual void DidDestroyCompositor(content::SynchronousCompositor* compositor) | 127 virtual void DidDestroyCompositor(content::SynchronousCompositor* compositor) |
| 113 OVERRIDE; | 128 OVERRIDE; |
| 114 virtual void SetContinuousInvalidate(bool invalidate) OVERRIDE; | 129 virtual void SetContinuousInvalidate(bool invalidate) OVERRIDE; |
| 115 virtual void SetMaxRootLayerScrollOffset(gfx::Vector2dF new_value) OVERRIDE; | 130 virtual void SetMaxRootLayerScrollOffset(gfx::Vector2dF new_value) OVERRIDE; |
| 116 virtual void SetTotalRootLayerScrollOffset(gfx::Vector2dF new_value_css) | 131 virtual void SetTotalRootLayerScrollOffset(gfx::Vector2dF new_value_css) |
| 117 OVERRIDE; | 132 OVERRIDE; |
| 118 virtual void DidUpdateContent() OVERRIDE; | 133 virtual void DidUpdateContent() OVERRIDE; |
| 119 virtual gfx::Vector2dF GetTotalRootLayerScrollOffset() OVERRIDE; | 134 virtual gfx::Vector2dF GetTotalRootLayerScrollOffset() OVERRIDE; |
| 120 virtual bool IsExternalFlingActive() const OVERRIDE; | 135 virtual bool IsExternalFlingActive() const OVERRIDE; |
| 121 virtual void SetRootLayerPageScaleFactorAndLimits(float page_scale_factor, | 136 virtual void SetRootLayerPageScaleFactorAndLimits(float page_scale_factor, |
| 122 float min_page_scale_factor, | 137 float min_page_scale_factor, |
| 123 float max_page_scale_factor) | 138 float max_page_scale_factor) |
| 124 OVERRIDE; | 139 OVERRIDE; |
| 125 virtual void SetRootLayerScrollableSize(gfx::SizeF scrollable_size) OVERRIDE; | 140 virtual void SetRootLayerScrollableSize(gfx::SizeF scrollable_size) OVERRIDE; |
| 126 virtual void DidOverscroll(gfx::Vector2dF accumulated_overscroll, | 141 virtual void DidOverscroll(gfx::Vector2dF accumulated_overscroll, |
| 127 gfx::Vector2dF latest_overscroll_delta, | 142 gfx::Vector2dF latest_overscroll_delta, |
| 128 gfx::Vector2dF current_fling_velocity) OVERRIDE; | 143 gfx::Vector2dF current_fling_velocity) OVERRIDE; |
| 129 | 144 |
| 145 // GlobalTileManagerClient overrides | |
| 146 virtual size_t GetNumTiles() const OVERRIDE; | |
| 147 virtual void SetNumTiles(size_t num_tiles, | |
| 148 bool effective_immediately) OVERRIDE; | |
| 149 | |
| 130 private: | 150 private: |
| 131 // Checks the continuous invalidate and block invalidate state, and schedule | 151 // Checks the continuous invalidate and block invalidate state, and schedule |
| 132 // invalidates appropriately. If |force_invalidate| is true, then send a view | 152 // invalidates appropriately. If |force_invalidate| is true, then send a view |
| 133 // invalidate regardless of compositor expectation. | 153 // invalidate regardless of compositor expectation. |
| 134 void EnsureContinuousInvalidation(bool force_invalidate); | 154 void EnsureContinuousInvalidation(bool force_invalidate); |
| 135 bool DrawSWInternal(jobject java_canvas, const gfx::Rect& clip_bounds); | 155 bool DrawSWInternal(jobject java_canvas, const gfx::Rect& clip_bounds); |
| 136 bool CompositeSW(SkCanvas* canvas); | 156 bool CompositeSW(SkCanvas* canvas); |
| 137 void DidComposite(bool force_invalidate); | 157 void DidComposite(bool force_invalidate); |
| 138 | 158 |
| 139 // If we call up view invalidate and OnDraw is not called before a deadline, | 159 // 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. | 160 // then we keep ticking the SynchronousCompositor so it can make progress. |
| 141 void FallbackTickFired(); | 161 void FallbackTickFired(); |
| 142 | 162 |
| 143 gfx::Vector2d max_scroll_offset() const; | 163 gfx::Vector2d max_scroll_offset() const; |
| 144 | 164 |
| 165 content::SynchronousCompositorMemoryPolicy CalculateDesiredMemoryPolicy(); | |
| 145 // For debug tracing or logging. Return the string representation of this | 166 // For debug tracing or logging. Return the string representation of this |
| 146 // view renderer's state and the |draw_info| if provided. | 167 // view renderer's state and the |draw_info| if provided. |
| 147 std::string ToString(AwDrawGLInfo* draw_info) const; | 168 std::string ToString(AwDrawGLInfo* draw_info) const; |
| 148 | 169 |
| 149 BrowserViewRendererClient* client_; | 170 BrowserViewRendererClient* client_; |
| 150 SharedRendererState* shared_renderer_state_; | 171 SharedRendererState* shared_renderer_state_; |
| 151 content::WebContents* web_contents_; | 172 content::WebContents* web_contents_; |
| 152 // TODO(boliu): This class should only be used on the UI thread. However in | 173 // TODO(boliu): This class should only be used on the UI thread. However in |
| 153 // short term to supporting HardwareRenderer, some callbacks on | 174 // short term to supporting HardwareRenderer, some callbacks on |
| 154 // SynchronousCompositorClient may be called on non-UI thread. These are | 175 // SynchronousCompositorClient may be called on non-UI thread. These are |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 gfx::Vector2dF scroll_offset_dip_; | 213 gfx::Vector2dF scroll_offset_dip_; |
| 193 | 214 |
| 194 // Max scroll offset in CSS pixels. | 215 // Max scroll offset in CSS pixels. |
| 195 gfx::Vector2dF max_scroll_offset_dip_; | 216 gfx::Vector2dF max_scroll_offset_dip_; |
| 196 | 217 |
| 197 // Used to prevent rounding errors from accumulating enough to generate | 218 // Used to prevent rounding errors from accumulating enough to generate |
| 198 // visible skew (especially noticeable when scrolling up and down in the same | 219 // visible skew (especially noticeable when scrolling up and down in the same |
| 199 // spot over a period of time). | 220 // spot over a period of time). |
| 200 gfx::Vector2dF overscroll_rounding_error_; | 221 gfx::Vector2dF overscroll_rounding_error_; |
| 201 | 222 |
| 223 GlobalTileManager::Key tile_manager_key_; | |
| 224 | |
| 225 // The following 2 are used to construct a memory policy and set the memory | |
| 226 // policy on the shared_renderer_state_ atomically. | |
| 227 size_t num_tiles_; | |
| 228 size_t num_bytes_; | |
| 229 | |
| 202 DISALLOW_COPY_AND_ASSIGN(BrowserViewRenderer); | 230 DISALLOW_COPY_AND_ASSIGN(BrowserViewRenderer); |
| 203 }; | 231 }; |
| 204 | 232 |
| 205 } // namespace android_webview | 233 } // namespace android_webview |
| 206 | 234 |
| 207 #endif // ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_ | 235 #endif // ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_ |
| OLD | NEW |