Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: android_webview/browser/hardware_renderer.h

Issue 176543004: aw: Split hardware rendering into HardwareRenderer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_HARDWARE_RENDERER_H_
6 #define ANDROID_WEBVIEW_BROWSER_IN_PROCESS_VIEW_RENDERER_H_ 6 #define ANDROID_WEBVIEW_BROWSER_HARDWARE_RENDERER_H_
7 7
8 #include <string> 8 #include <queue>
9 9
10 #include "android_webview/browser/browser_view_renderer.h"
11 #include "android_webview/browser/gl_view_renderer_manager.h" 10 #include "android_webview/browser/gl_view_renderer_manager.h"
12 #include "base/cancelable_callback.h" 11 #include "base/memory/ref_counted.h"
13 #include "content/public/browser/android/synchronous_compositor.h" 12 #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 13
17 namespace content { 14 struct AwDrawGLInfo;
18 class SynchronousCompositor;
19 class WebContents;
20 }
21
22 typedef void* EGLContext;
23 class SkCanvas;
24 15
25 namespace android_webview { 16 namespace android_webview {
26 17
27 class AwGLSurface; 18 class AwGLSurface;
19 class BrowserViewRendererClient;
28 20
29 // Provides RenderViewHost wrapper functionality for sending WebView-specific 21 namespace internal {
30 // IPC messages to the renderer and from there to WebKit. 22 class DeferredGpuCommandService;
31 class InProcessViewRenderer : public BrowserViewRenderer, 23 } // namespace internal
32 public content::SynchronousCompositorClient { 24
25 struct DrawGLInput {
26 gfx::Rect global_visible_rect;
27 gfx::Vector2d scroll;
28 };
29
30 struct DrawGLResult {
31 bool did_draw;
32 bool clip_contains_visible_rect;
33
34 DrawGLResult();
35 };
36
37 class HardwareRenderer {
33 public: 38 public:
39 HardwareRenderer(content::SynchronousCompositor* compositor,
40 BrowserViewRendererClient* client);
41 ~HardwareRenderer();
42
34 static void CalculateTileMemoryPolicy(); 43 static void CalculateTileMemoryPolicy();
35 44
36 InProcessViewRenderer(BrowserViewRenderer::Client* client, 45 DrawGLResult DrawGL(AwDrawGLInfo* draw_info, const DrawGLInput& input);
37 content::WebContents* web_contents); 46 bool TrimMemory(int level, bool visible);
38 virtual ~InProcessViewRenderer(); 47 void SetMemoryPolicy(content::SynchronousCompositorMemoryPolicy& new_policy);
39 48
40 static InProcessViewRenderer* FromWebContents( 49 bool RequestDrawGL();
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 50
91 private: 51 private:
92 // Checks the continuous invalidate and block invalidate state, and schedule 52 friend class internal::DeferredGpuCommandService;
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 53
102 void UpdateCachedGlobalVisibleRect(); 54 bool InitializeHardwareDraw();
103 55
104 // If we call up view invalidate and OnDraw is not called before a deadline, 56 content::SynchronousCompositor* compositor_;
105 // then we keep ticking the SynchronousCompositor so it can make progress. 57 BrowserViewRendererClient* client_;
106 void FallbackTickFired();
107 void ForceFakeCompositeSW();
108 58
109 void NoLongerExpectsDrawGL(); 59 typedef void* EGLContext;
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_; 60 EGLContext last_egl_context_;
158 61
159 // Should always call UpdateCachedGlobalVisibleRect before using this. 62 scoped_refptr<AwGLSurface> gl_surface_;
160 gfx::Rect cached_global_visible_rect_; 63 content::SynchronousCompositorMemoryPolicy memory_policy_;
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 64
176 GLViewRendererManager::Key manager_key_; 65 GLViewRendererManager::Key manager_key_;
177 66
178 content::SynchronousCompositorMemoryPolicy memory_policy_; 67 DISALLOW_COPY_AND_ASSIGN(HardwareRenderer);
68 };
179 69
180 DISALLOW_COPY_AND_ASSIGN(InProcessViewRenderer); 70 namespace internal {
71
72 class ScopedAllowGL {
73 public:
74 ScopedAllowGL();
75 ~ScopedAllowGL();
76
77 static bool IsAllowed();
78
79 private:
80 static bool allow_gl;
81
82 DISALLOW_COPY_AND_ASSIGN(ScopedAllowGL);
181 }; 83 };
182 84
85 class DeferredGpuCommandService
86 : public gpu::InProcessCommandBuffer::Service,
87 public base::RefCountedThreadSafe<DeferredGpuCommandService> {
88 public:
89 DeferredGpuCommandService();
90
91 virtual void ScheduleTask(const base::Closure& task) OVERRIDE;
92 virtual void ScheduleIdleWork(const base::Closure& task) OVERRIDE;
93 virtual bool UseVirtualizedGLContexts() OVERRIDE;
94
95 void RunTasks();
96
97 virtual void AddRef() const OVERRIDE;
98 virtual void Release() const OVERRIDE;
99
100 protected:
101 virtual ~DeferredGpuCommandService();
102 friend class base::RefCountedThreadSafe<DeferredGpuCommandService>;
103
104 private:
105 static void RequestProcessGLOnUIThread();
106
107 base::Lock tasks_lock_;
108 std::queue<base::Closure> tasks_;
109 DISALLOW_COPY_AND_ASSIGN(DeferredGpuCommandService);
110 };
111
112 } // namespace internal
113
183 } // namespace android_webview 114 } // namespace android_webview
184 115
185 #endif // ANDROID_WEBVIEW_BROWSER_IN_PROCESS_VIEW_RENDERER_H_ 116 #endif // ANDROID_WEBVIEW_BROWSER_HARDWARE_RENDERER_H_
OLDNEW
« no previous file with comments | « android_webview/browser/gl_view_renderer_manager.cc ('k') | android_webview/browser/hardware_renderer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698