| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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_IN_PROCESS_VIEW_RENDERER_H_ | 5 #ifndef ANDROID_WEBVIEW_BROWSER_IN_PROCESS_VIEW_RENDERER_H_ |
| 6 #define ANDROID_WEBVIEW_BROWSER_IN_PROCESS_VIEW_RENDERER_H_ | 6 #define ANDROID_WEBVIEW_BROWSER_IN_PROCESS_VIEW_RENDERER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "android_webview/browser/browser_view_renderer.h" | 10 #include "android_webview/browser/browser_view_renderer.h" |
| 11 #include "android_webview/browser/gl_view_renderer_manager.h" | 11 #include "android_webview/browser/gl_view_renderer_manager.h" |
| 12 #include "base/cancelable_callback.h" | 12 #include "base/cancelable_callback.h" |
| 13 #include "content/public/browser/android/synchronous_compositor_client.h" | 13 #include "content/public/browser/android/synchronous_compositor_client.h" |
| 14 #include "ui/gfx/vector2d_f.h" | 14 #include "ui/gfx/vector2d_f.h" |
| 15 #include "ui/gl/android/gl_factory_android.h" |
| 15 | 16 |
| 16 namespace content { | 17 namespace content { |
| 17 class SynchronousCompositor; | 18 class SynchronousCompositor; |
| 18 class WebContents; | 19 class WebContents; |
| 19 } | 20 } |
| 20 | 21 |
| 22 namespace gfx { |
| 23 class GLSurface; |
| 24 } |
| 25 |
| 21 typedef void* EGLContext; | 26 typedef void* EGLContext; |
| 22 class SkCanvas; | 27 class SkCanvas; |
| 23 | 28 |
| 24 namespace android_webview { | 29 namespace android_webview { |
| 25 | 30 |
| 31 class AwGLSurface; |
| 32 |
| 26 // Provides RenderViewHost wrapper functionality for sending WebView-specific | 33 // Provides RenderViewHost wrapper functionality for sending WebView-specific |
| 27 // IPC messages to the renderer and from there to WebKit. | 34 // IPC messages to the renderer and from there to WebKit. |
| 28 class InProcessViewRenderer : public BrowserViewRenderer, | 35 class InProcessViewRenderer : public BrowserViewRenderer, |
| 29 public content::SynchronousCompositorClient { | 36 public content::SynchronousCompositorClient, |
| 37 public gfx::GLFactoryAndroid { |
| 30 public: | 38 public: |
| 31 InProcessViewRenderer(BrowserViewRenderer::Client* client, | 39 InProcessViewRenderer(BrowserViewRenderer::Client* client, |
| 32 JavaHelper* java_helper, | 40 JavaHelper* java_helper, |
| 33 content::WebContents* web_contents); | 41 content::WebContents* web_contents); |
| 34 virtual ~InProcessViewRenderer(); | 42 virtual ~InProcessViewRenderer(); |
| 35 | 43 |
| 36 static InProcessViewRenderer* FromWebContents( | 44 static InProcessViewRenderer* FromWebContents( |
| 37 content::WebContents* contents); | 45 content::WebContents* contents); |
| 38 | 46 |
| 39 // BrowserViewRenderer overrides | 47 // BrowserViewRenderer overrides. |
| 40 virtual bool OnDraw(jobject java_canvas, | 48 virtual bool OnDraw(jobject java_canvas, |
| 41 bool is_hardware_canvas, | 49 bool is_hardware_canvas, |
| 42 const gfx::Vector2d& scroll_, | 50 const gfx::Vector2d& scroll_, |
| 43 const gfx::Rect& clip) OVERRIDE; | 51 const gfx::Rect& clip) OVERRIDE; |
| 44 virtual void DrawGL(AwDrawGLInfo* draw_info) OVERRIDE; | 52 virtual void DrawGL(AwDrawGLInfo* draw_info) OVERRIDE; |
| 45 virtual void SetGlobalVisibleRect(const gfx::Rect& visible_rect) OVERRIDE; | 53 virtual void SetGlobalVisibleRect(const gfx::Rect& visible_rect) OVERRIDE; |
| 46 virtual base::android::ScopedJavaLocalRef<jobject> CapturePicture( | 54 virtual base::android::ScopedJavaLocalRef<jobject> CapturePicture( |
| 47 int width, | 55 int width, |
| 48 int height) OVERRIDE; | 56 int height) OVERRIDE; |
| 49 virtual void EnableOnNewPicture(bool enabled) OVERRIDE; | 57 virtual void EnableOnNewPicture(bool enabled) OVERRIDE; |
| 50 virtual void OnVisibilityChanged(bool visible) OVERRIDE; | 58 virtual void OnVisibilityChanged(bool visible) OVERRIDE; |
| 51 virtual void OnSizeChanged(int width, int height) OVERRIDE; | 59 virtual void OnSizeChanged(int width, int height) OVERRIDE; |
| 52 virtual void ScrollTo(gfx::Vector2d new_value) OVERRIDE; | 60 virtual void ScrollTo(gfx::Vector2d new_value) OVERRIDE; |
| 53 virtual void SetPageScaleFactor(float page_scale_factor) OVERRIDE; | 61 virtual void SetPageScaleFactor(float page_scale_factor) OVERRIDE; |
| 54 virtual void OnAttachedToWindow(int width, int height) OVERRIDE; | 62 virtual void OnAttachedToWindow(int width, int height) OVERRIDE; |
| 55 virtual void OnDetachedFromWindow() OVERRIDE; | 63 virtual void OnDetachedFromWindow() OVERRIDE; |
| 56 virtual void SetDipScale(float dip_scale) OVERRIDE; | 64 virtual void SetDipScale(float dip_scale) OVERRIDE; |
| 57 virtual bool IsAttachedToWindow() OVERRIDE; | 65 virtual bool IsAttachedToWindow() OVERRIDE; |
| 58 virtual bool IsViewVisible() OVERRIDE; | 66 virtual bool IsViewVisible() OVERRIDE; |
| 59 virtual gfx::Rect GetScreenRect() OVERRIDE; | 67 virtual gfx::Rect GetScreenRect() OVERRIDE; |
| 60 | 68 |
| 61 // SynchronousCompositorClient overrides | 69 // SynchronousCompositorClient overrides. |
| 62 virtual void DidInitializeCompositor( | 70 virtual void DidInitializeCompositor( |
| 63 content::SynchronousCompositor* compositor) OVERRIDE; | 71 content::SynchronousCompositor* compositor) OVERRIDE; |
| 64 virtual void DidDestroyCompositor( | 72 virtual void DidDestroyCompositor( |
| 65 content::SynchronousCompositor* compositor) OVERRIDE; | 73 content::SynchronousCompositor* compositor) OVERRIDE; |
| 66 virtual void SetContinuousInvalidate(bool invalidate) OVERRIDE; | 74 virtual void SetContinuousInvalidate(bool invalidate) OVERRIDE; |
| 67 virtual void SetTotalRootLayerScrollOffset( | 75 virtual void SetTotalRootLayerScrollOffset( |
| 68 gfx::Vector2dF new_value_css) OVERRIDE; | 76 gfx::Vector2dF new_value_css) OVERRIDE; |
| 69 virtual void DidUpdateContent() OVERRIDE; | 77 virtual void DidUpdateContent() OVERRIDE; |
| 70 virtual gfx::Vector2dF GetTotalRootLayerScrollOffset() OVERRIDE; | 78 virtual gfx::Vector2dF GetTotalRootLayerScrollOffset() OVERRIDE; |
| 71 virtual void DidOverscroll(gfx::Vector2dF latest_overscroll_delta, | 79 virtual void DidOverscroll(gfx::Vector2dF latest_overscroll_delta, |
| 72 gfx::Vector2dF current_fling_velocity) OVERRIDE; | 80 gfx::Vector2dF current_fling_velocity) OVERRIDE; |
| 73 | 81 |
| 82 // gfx::GLFactoryAndroid overrides. |
| 83 virtual scoped_refptr<gfx::GLSurface> CreateNonOwnedViewSurface() OVERRIDE; |
| 84 |
| 74 void WebContentsGone(); | 85 void WebContentsGone(); |
| 75 bool RequestProcessGL(); | 86 bool RequestProcessGL(); |
| 76 | 87 |
| 77 private: | 88 private: |
| 78 // Checks the continuous invalidate and block invalidate state, and schedule | 89 // Checks the continuous invalidate and block invalidate state, and schedule |
| 79 // invalidates appropriately. If |invalidate_ignore_compositor| is true, | 90 // invalidates appropriately. If |invalidate_ignore_compositor| is true, |
| 80 // then send a view invalidate regardless of compositor expectation. | 91 // then send a view invalidate regardless of compositor expectation. |
| 81 void EnsureContinuousInvalidation( | 92 void EnsureContinuousInvalidation( |
| 82 AwDrawGLInfo* draw_info, | 93 AwDrawGLInfo* draw_info, |
| 83 bool invalidate_ignore_compositor); | 94 bool invalidate_ignore_compositor); |
| 84 bool DrawSWInternal(jobject java_canvas, | 95 bool DrawSWInternal(jobject java_canvas, |
| 85 const gfx::Rect& clip_bounds); | 96 const gfx::Rect& clip_bounds); |
| 86 bool CompositeSW(SkCanvas* canvas); | 97 bool CompositeSW(SkCanvas* canvas); |
| 87 | 98 |
| 88 void UpdateCachedGlobalVisibleRect(); | 99 void UpdateCachedGlobalVisibleRect(); |
| 89 | 100 |
| 90 // If we call up view invalidate and OnDraw is not called before a deadline, | 101 // If we call up view invalidate and OnDraw is not called before a deadline, |
| 91 // then we keep ticking the SynchronousCompositor so it can make progress. | 102 // then we keep ticking the SynchronousCompositor so it can make progress. |
| 92 void FallbackTickFired(); | 103 void FallbackTickFired(); |
| 93 | 104 |
| 94 void NoLongerExpectsDrawGL(); | 105 void NoLongerExpectsDrawGL(); |
| 95 | 106 |
| 107 bool InitializeHwDraw(); |
| 108 |
| 96 // For debug tracing or logging. Return the string representation of this | 109 // For debug tracing or logging. Return the string representation of this |
| 97 // view renderer's state and the |draw_info| if provided. | 110 // view renderer's state and the |draw_info| if provided. |
| 98 std::string ToString(AwDrawGLInfo* draw_info) const; | 111 std::string ToString(AwDrawGLInfo* draw_info) const; |
| 99 | 112 |
| 100 BrowserViewRenderer::Client* client_; | 113 BrowserViewRenderer::Client* client_; |
| 101 BrowserViewRenderer::JavaHelper* java_helper_; | 114 BrowserViewRenderer::JavaHelper* java_helper_; |
| 102 content::WebContents* web_contents_; | 115 content::WebContents* web_contents_; |
| 103 content::SynchronousCompositor* compositor_; | 116 content::SynchronousCompositor* compositor_; |
| 104 | 117 |
| 105 bool visible_; | 118 bool visible_; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 120 | 133 |
| 121 // Holds a callback to FallbackTickFired while it is pending. | 134 // Holds a callback to FallbackTickFired while it is pending. |
| 122 base::CancelableClosure fallback_tick_; | 135 base::CancelableClosure fallback_tick_; |
| 123 | 136 |
| 124 int width_; | 137 int width_; |
| 125 int height_; | 138 int height_; |
| 126 | 139 |
| 127 bool attached_to_window_; | 140 bool attached_to_window_; |
| 128 bool hardware_initialized_; | 141 bool hardware_initialized_; |
| 129 bool hardware_failed_; | 142 bool hardware_failed_; |
| 143 scoped_refptr<AwGLSurface> gl_surface_; |
| 130 | 144 |
| 131 // Used only for detecting Android View System context changes. | 145 // Used only for detecting Android View System context changes. |
| 132 // Not to be used between draw calls. | 146 // Not to be used between draw calls. |
| 133 EGLContext last_egl_context_; | 147 EGLContext last_egl_context_; |
| 134 | 148 |
| 135 // Should always call UpdateCachedGlobalVisibleRect before using this. | 149 // Should always call UpdateCachedGlobalVisibleRect before using this. |
| 136 gfx::Rect cached_global_visible_rect_; | 150 gfx::Rect cached_global_visible_rect_; |
| 137 | 151 |
| 138 // Last View scroll when View.onDraw() was called. | 152 // Last View scroll when View.onDraw() was called. |
| 139 gfx::Vector2d scroll_at_start_of_frame_; | 153 gfx::Vector2d scroll_at_start_of_frame_; |
| 140 | 154 |
| 141 // Current scroll offset in CSS pixels. | 155 // Current scroll offset in CSS pixels. |
| 142 gfx::Vector2dF scroll_offset_css_; | 156 gfx::Vector2dF scroll_offset_css_; |
| 143 | 157 |
| 144 // Used to prevent rounding errors from accumulating enough to generate | 158 // Used to prevent rounding errors from accumulating enough to generate |
| 145 // visible skew (especially noticeable when scrolling up and down in the same | 159 // visible skew (especially noticeable when scrolling up and down in the same |
| 146 // spot over a period of time). | 160 // spot over a period of time). |
| 147 gfx::Vector2dF overscroll_rounding_error_; | 161 gfx::Vector2dF overscroll_rounding_error_; |
| 148 | 162 |
| 149 GLViewRendererManager::Key manager_key_; | 163 GLViewRendererManager::Key manager_key_; |
| 150 | 164 |
| 151 DISALLOW_COPY_AND_ASSIGN(InProcessViewRenderer); | 165 DISALLOW_COPY_AND_ASSIGN(InProcessViewRenderer); |
| 152 }; | 166 }; |
| 153 | 167 |
| 154 } // namespace android_webview | 168 } // namespace android_webview |
| 155 | 169 |
| 156 #endif // ANDROID_WEBVIEW_BROWSER_IN_PROCESS_VIEW_RENDERER_H_ | 170 #endif // ANDROID_WEBVIEW_BROWSER_IN_PROCESS_VIEW_RENDERER_H_ |
| OLD | NEW |