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