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