Don't add an aura tooltip to bubble close buttons on Windows.
[chromium-blink-merge.git] / android_webview / browser / browser_view_renderer.h
blob308abd445fa9d703f03e2e322813372746d6277a
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/vector2d_f.h"
19 class SkCanvas;
20 class SkPicture;
22 namespace content {
23 class WebContents;
26 namespace android_webview {
28 class BrowserViewRendererClient;
29 class ChildFrame;
31 // Interface for all the WebView-specific content rendering operations.
32 // Provides software and hardware rendering and the Capture Picture API.
33 class BrowserViewRenderer : public content::SynchronousCompositorClient {
34 public:
35 static void CalculateTileMemoryPolicy();
36 static BrowserViewRenderer* FromWebContents(
37 content::WebContents* web_contents);
39 BrowserViewRenderer(
40 BrowserViewRendererClient* client,
41 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner);
43 ~BrowserViewRenderer() override;
45 void RegisterWithWebContents(content::WebContents* web_contents);
47 SharedRendererState* GetAwDrawGLViewContext();
48 bool RequestDrawGL(bool wait_for_completion);
50 // Called before either OnDrawHardware or OnDrawSoftware to set the view
51 // state of this frame. |scroll| is the view's current scroll offset.
52 // |global_visible_rect| is the intersection of the view size and the window
53 // in window coordinates.
54 void PrepareToDraw(const gfx::Vector2d& scroll,
55 const gfx::Rect& global_visible_rect);
57 // Main handlers for view drawing. A false return value indicates no new
58 // frame is produced.
59 bool OnDrawHardware();
60 bool OnDrawSoftware(SkCanvas* canvas);
62 // CapturePicture API methods.
63 skia::RefPtr<SkPicture> CapturePicture(int width, int height);
64 void EnableOnNewPicture(bool enabled);
66 void ClearView();
68 void SetOffscreenPreRaster(bool enabled);
70 // View update notifications.
71 void SetIsPaused(bool paused);
72 void SetViewVisibility(bool visible);
73 void SetWindowVisibility(bool visible);
74 void OnSizeChanged(int width, int height);
75 void OnAttachedToWindow(int width, int height);
76 void OnDetachedFromWindow();
78 // Sets the scale for logical<->physical pixel conversions.
79 void SetDipScale(float dip_scale);
81 // Set the root layer scroll offset to |new_value|.
82 void ScrollTo(gfx::Vector2d new_value);
84 // Android views hierarchy gluing.
85 bool IsVisible() const;
86 gfx::Rect GetScreenRect() const;
87 bool attached_to_window() const { return attached_to_window_; }
88 bool hardware_enabled() const { return hardware_enabled_; }
89 gfx::Size size() const { return size_; }
90 void ReleaseHardware();
92 void TrimMemory(const int level, const bool visible);
94 // SynchronousCompositorClient overrides.
95 void DidInitializeCompositor(
96 content::SynchronousCompositor* compositor) override;
97 void DidDestroyCompositor(
98 content::SynchronousCompositor* compositor) override;
99 void PostInvalidate() override;
100 void DidUpdateContent() override;
101 gfx::Vector2dF GetTotalRootLayerScrollOffset() override;
102 void UpdateRootLayerState(const gfx::Vector2dF& total_scroll_offset_dip,
103 const gfx::Vector2dF& max_scroll_offset_dip,
104 const gfx::SizeF& scrollable_size_dip,
105 float page_scale_factor,
106 float min_page_scale_factor,
107 float max_page_scale_factor) override;
108 bool IsExternalFlingActive() const override;
109 void DidOverscroll(gfx::Vector2dF accumulated_overscroll,
110 gfx::Vector2dF latest_overscroll_delta,
111 gfx::Vector2dF current_fling_velocity) override;
113 void UpdateParentDrawConstraints();
114 void DetachFunctorFromView();
116 private:
117 void SetTotalRootLayerScrollOffset(gfx::Vector2dF new_value_dip);
118 bool CanOnDraw();
119 // Posts an invalidate with fallback tick. All invalidates posted while an
120 // invalidate is pending will be posted as a single invalidate after the
121 // pending invalidate is done.
122 void PostInvalidateWithFallback();
123 void CancelFallbackTick();
124 void UpdateCompositorIsActive();
125 bool CompositeSW(SkCanvas* canvas);
126 scoped_refptr<base::trace_event::ConvertableToTraceFormat>
127 RootLayerStateAsValue(const gfx::Vector2dF& total_scroll_offset_dip,
128 const gfx::SizeF& scrollable_size_dip);
130 bool CompositeHw();
131 void ReturnUnusedResource(scoped_ptr<ChildFrame> frame);
132 void ReturnResourceFromParent();
134 // If we call up view invalidate and OnDraw is not called before a deadline,
135 // then we keep ticking the SynchronousCompositor so it can make progress.
136 // Do this in a two stage tick due to native MessageLoop favors delayed task,
137 // so ensure delayed task is inserted only after the draw task returns.
138 void PostFallbackTick();
139 void FallbackTickFired();
141 // Force invoke the compositor to run produce a 1x1 software frame that is
142 // immediately discarded. This is a hack to force invoke parts of the
143 // compositor that are not directly exposed here.
144 void ForceFakeCompositeSW();
146 gfx::Vector2d max_scroll_offset() const;
148 size_t CalculateDesiredMemoryPolicy();
150 // For debug tracing or logging. Return the string representation of this
151 // view renderer's state.
152 std::string ToString() const;
154 BrowserViewRendererClient* client_;
155 SharedRendererState shared_renderer_state_;
156 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
158 content::SynchronousCompositor* compositor_;
160 bool is_paused_;
161 bool view_visible_;
162 bool window_visible_; // Only applicable if |attached_to_window_| is true.
163 bool attached_to_window_;
164 bool hardware_enabled_;
165 float dip_scale_;
166 float page_scale_factor_;
167 bool on_new_picture_enable_;
168 bool clear_view_;
170 bool offscreen_pre_raster_;
172 gfx::Vector2d last_on_draw_scroll_offset_;
173 gfx::Rect last_on_draw_global_visible_rect_;
176 base::CancelableClosure post_fallback_tick_;
177 base::CancelableClosure fallback_tick_fired_;
178 bool fallback_tick_pending_;
180 gfx::Size size_;
182 // Current scroll offset in CSS pixels.
183 gfx::Vector2dF scroll_offset_dip_;
185 // Max scroll offset in CSS pixels.
186 gfx::Vector2dF max_scroll_offset_dip_;
188 // Used to prevent rounding errors from accumulating enough to generate
189 // visible skew (especially noticeable when scrolling up and down in the same
190 // spot over a period of time).
191 gfx::Vector2dF overscroll_rounding_error_;
193 DISALLOW_COPY_AND_ASSIGN(BrowserViewRenderer);
196 } // namespace android_webview
198 #endif // ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_