Clean up check for dependency_info.
[chromium-blink-merge.git] / android_webview / browser / browser_view_renderer.h
blob97737aa246ff2bc5f2d130bf20fef4a90b38d96d
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
3 // found in the LICENSE file.
5 #ifndef ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_
6 #define ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_
8 #include "android_webview/browser/parent_compositor_draw_constraints.h"
9 #include "android_webview/browser/shared_renderer_state.h"
10 #include "base/callback.h"
11 #include "base/cancelable_callback.h"
12 #include "base/trace_event/trace_event.h"
13 #include "content/public/browser/android/synchronous_compositor.h"
14 #include "content/public/browser/android/synchronous_compositor_client.h"
15 #include "skia/ext/refptr.h"
16 #include "ui/gfx/geometry/rect.h"
17 #include "ui/gfx/geometry/size_f.h"
18 #include "ui/gfx/geometry/vector2d_f.h"
20 class SkCanvas;
21 class SkPicture;
23 namespace content {
24 class WebContents;
27 namespace android_webview {
29 class BrowserViewRendererClient;
30 class ChildFrame;
32 // Interface for all the WebView-specific content rendering operations.
33 // Provides software and hardware rendering and the Capture Picture API.
34 class BrowserViewRenderer : public content::SynchronousCompositorClient {
35 public:
36 static void CalculateTileMemoryPolicy();
37 static BrowserViewRenderer* FromWebContents(
38 content::WebContents* web_contents);
40 BrowserViewRenderer(
41 BrowserViewRendererClient* client,
42 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner);
44 ~BrowserViewRenderer() override;
46 void RegisterWithWebContents(content::WebContents* web_contents);
48 SharedRendererState* GetAwDrawGLViewContext();
49 bool RequestDrawGL(bool wait_for_completion);
51 // Called before either OnDrawHardware or OnDrawSoftware to set the view
52 // state of this frame. |scroll| is the view's current scroll offset.
53 // |global_visible_rect| is the intersection of the view size and the window
54 // in window coordinates.
55 void PrepareToDraw(const gfx::Vector2d& scroll,
56 const gfx::Rect& global_visible_rect);
58 // Main handlers for view drawing. A false return value indicates no new
59 // frame is produced.
60 bool OnDrawHardware();
61 bool OnDrawSoftware(SkCanvas* canvas);
63 // CapturePicture API methods.
64 skia::RefPtr<SkPicture> CapturePicture(int width, int height);
65 void EnableOnNewPicture(bool enabled);
67 void ClearView();
69 void SetOffscreenPreRaster(bool enabled);
71 // View update notifications.
72 void SetIsPaused(bool paused);
73 void SetViewVisibility(bool visible);
74 void SetWindowVisibility(bool visible);
75 void OnSizeChanged(int width, int height);
76 void OnAttachedToWindow(int width, int height);
77 void OnDetachedFromWindow();
78 void OnComputeScroll(base::TimeTicks animation_time);
80 // Sets the scale for logical<->physical pixel conversions.
81 void SetDipScale(float dip_scale);
82 float dip_scale() const { return dip_scale_; }
83 float page_scale_factor() const { return page_scale_factor_; }
85 // Set the root layer scroll offset to |new_value|.
86 void ScrollTo(gfx::Vector2d new_value);
88 // Android views hierarchy gluing.
89 bool IsVisible() const;
90 gfx::Rect GetScreenRect() const;
91 bool attached_to_window() const { return attached_to_window_; }
92 bool hardware_enabled() const { return hardware_enabled_; }
93 gfx::Size size() const { return size_; }
94 void ReleaseHardware();
96 void TrimMemory(const int level, const bool visible);
98 // SynchronousCompositorClient overrides.
99 void DidInitializeCompositor(
100 content::SynchronousCompositor* compositor) override;
101 void DidDestroyCompositor(
102 content::SynchronousCompositor* compositor) override;
103 void PostInvalidate() override;
104 void DidUpdateContent() override;
105 void UpdateRootLayerState(const gfx::Vector2dF& total_scroll_offset_dip,
106 const gfx::Vector2dF& max_scroll_offset_dip,
107 const gfx::SizeF& scrollable_size_dip,
108 float page_scale_factor,
109 float min_page_scale_factor,
110 float max_page_scale_factor) override;
111 void DidOverscroll(gfx::Vector2dF accumulated_overscroll,
112 gfx::Vector2dF latest_overscroll_delta,
113 gfx::Vector2dF current_fling_velocity) override;
115 void UpdateParentDrawConstraints();
116 void DetachFunctorFromView();
118 private:
119 void SetTotalRootLayerScrollOffset(gfx::Vector2dF new_value_dip);
120 bool CanOnDraw();
121 // Posts an invalidate with fallback tick. All invalidates posted while an
122 // invalidate is pending will be posted as a single invalidate after the
123 // pending invalidate is done.
124 void PostInvalidateWithFallback();
125 void CancelFallbackTick();
126 void UpdateCompositorIsActive();
127 bool CompositeSW(SkCanvas* canvas);
128 scoped_refptr<base::trace_event::ConvertableToTraceFormat>
129 RootLayerStateAsValue(const gfx::Vector2dF& total_scroll_offset_dip,
130 const gfx::SizeF& scrollable_size_dip);
132 bool CompositeHw();
133 void ReturnUnusedResource(scoped_ptr<ChildFrame> frame);
134 void ReturnResourceFromParent();
136 // If we call up view invalidate and OnDraw is not called before a deadline,
137 // then we keep ticking the SynchronousCompositor so it can make progress.
138 // Do this in a two stage tick due to native MessageLoop favors delayed task,
139 // so ensure delayed task is inserted only after the draw task returns.
140 void PostFallbackTick();
141 void FallbackTickFired();
143 // Force invoke the compositor to run produce a 1x1 software frame that is
144 // immediately discarded. This is a hack to force invoke parts of the
145 // compositor that are not directly exposed here.
146 void ForceFakeCompositeSW();
148 gfx::Vector2d max_scroll_offset() const;
150 void UpdateMemoryPolicy();
152 // For debug tracing or logging. Return the string representation of this
153 // view renderer's state.
154 std::string ToString() const;
156 BrowserViewRendererClient* client_;
157 SharedRendererState shared_renderer_state_;
158 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
160 content::SynchronousCompositor* compositor_;
162 bool is_paused_;
163 bool view_visible_;
164 bool window_visible_; // Only applicable if |attached_to_window_| is true.
165 bool attached_to_window_;
166 bool hardware_enabled_;
167 float dip_scale_;
168 float page_scale_factor_;
169 float min_page_scale_factor_;
170 float max_page_scale_factor_;
171 bool on_new_picture_enable_;
172 bool clear_view_;
174 bool offscreen_pre_raster_;
176 gfx::Vector2d last_on_draw_scroll_offset_;
177 gfx::Rect last_on_draw_global_visible_rect_;
179 base::CancelableClosure post_fallback_tick_;
180 base::CancelableClosure fallback_tick_fired_;
181 bool fallback_tick_pending_;
183 gfx::Size size_;
185 gfx::SizeF scrollable_size_dip_;
187 // Current scroll offset in CSS pixels.
188 // TODO(miletus): Make scroll_offset_dip_ a gfx::ScrollOffset.
189 gfx::Vector2dF scroll_offset_dip_;
191 // Max scroll offset in CSS pixels.
192 // TODO(miletus): Make max_scroll_offset_dip_ a gfx::ScrollOffset.
193 gfx::Vector2dF max_scroll_offset_dip_;
195 // Used to prevent rounding errors from accumulating enough to generate
196 // visible skew (especially noticeable when scrolling up and down in the same
197 // spot over a period of time).
198 // TODO(miletus): Make overscroll_rounding_error_ a gfx::ScrollOffset.
199 gfx::Vector2dF overscroll_rounding_error_;
201 DISALLOW_COPY_AND_ASSIGN(BrowserViewRenderer);
204 } // namespace android_webview
206 #endif // ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_