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

Side by Side Diff: android_webview/browser/in_process_renderer/in_process_view_renderer.cc

Issue 14888002: Android WebView Merged-Thread Hardware Draw (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 7 years, 7 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 (c) 2013 The Chromium Authors. All rights reserved. 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 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 #include "android_webview/browser/in_process_renderer/in_process_view_renderer.h " 5 #include "android_webview/browser/in_process_renderer/in_process_view_renderer.h "
6 6
7 #include "android_webview/public/browser/draw_gl.h"
7 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "content/public/browser/android/content_view_core.h"
10 #include "content/public/browser/render_view_host.h"
11 #include "content/public/browser/web_contents.h"
8 #include "content/public/renderer/android/synchronous_compositor.h" 12 #include "content/public/renderer/android/synchronous_compositor.h"
13 #include "ui/gl/gl_bindings.h"
9 14
10 namespace android_webview { 15 namespace android_webview {
11 16
17 namespace {
18 const void* kUserDataKey = &kUserDataKey;
19
20 class UserData : public content::WebContents::Data {
21 public:
22 UserData(InProcessViewRenderer* ptr) : instance_(ptr) {}
23 virtual ~UserData() {
24 instance_->WebContentsGone();
25 }
26
27 static InProcessViewRenderer* GetInstance(content::WebContents* contents) {
28 if (!contents)
29 return NULL;
30 UserData* data = reinterpret_cast<UserData*>(
31 contents->GetUserData(kUserDataKey));
32 return data ? data->instance_ : NULL;
33 }
34
35 private:
36 InProcessViewRenderer* instance_;
37 };
38
39 } // namespace
40
12 InProcessViewRenderer::InProcessViewRenderer( 41 InProcessViewRenderer::InProcessViewRenderer(
13 BrowserViewRenderer::Client* client, 42 BrowserViewRenderer::Client* client,
14 JavaHelper* java_helper) 43 JavaHelper* java_helper)
15 : BrowserViewRendererImpl(client, java_helper), 44 : web_contents_(NULL),
16 compositor_(NULL) { 45 compositor_(NULL),
46 client_(client),
47 view_visible_(false),
48 inside_draw_(false),
49 continuous_invalidate_(false),
50 last_frame_context_(NULL) {
17 } 51 }
18 52
19 InProcessViewRenderer::~InProcessViewRenderer() { 53 InProcessViewRenderer::~InProcessViewRenderer() {
20 if (compositor_) 54 if (compositor_)
21 compositor_->SetClient(NULL); 55 compositor_->SetClient(NULL);
56 SetContents(NULL);
57 }
58
59 // static
60 InProcessViewRenderer* InProcessViewRenderer::FromWebContents(
61 content::WebContents* contents) {
62 return UserData::GetInstance(contents);
63 }
64
65 // static
66 InProcessViewRenderer* InProcessViewRenderer::FromId(int render_process_id,
67 int render_view_id) {
68 const content::RenderViewHost* rvh =
69 content::RenderViewHost::FromID(render_process_id, render_view_id);
70 if (!rvh) return NULL;
71 return InProcessViewRenderer::FromWebContents(
72 content::WebContents::FromRenderViewHost(rvh));
22 } 73 }
23 74
24 void InProcessViewRenderer::BindSynchronousCompositor( 75 void InProcessViewRenderer::BindSynchronousCompositor(
25 content::SynchronousCompositor* compositor) { 76 content::SynchronousCompositor* compositor) {
26 DCHECK(compositor && compositor_ != compositor); 77 DCHECK(compositor && compositor_ != compositor);
27 if (compositor_) 78 if (compositor_)
28 compositor_->SetClient(NULL); 79 compositor_->SetClient(NULL);
29 compositor_ = compositor; 80 compositor_ = compositor;
30 compositor_->SetClient(this); 81 compositor_->SetClient(this);
82
83 // TODO(boliu): If attached to window, ask java_helper_ to request
84 // GL Initialization.
85 }
86
87 void InProcessViewRenderer::SetContents(
88 content::ContentViewCore* content_view_core) {
89 // First remove association from the prior ContentViewCore / WebContents.
90 if (web_contents_) {
91 web_contents_->SetUserData(kUserDataKey, NULL);
92 DCHECK(!web_contents_); // WebContentsGone should have been called.
93 }
94
95 if (!content_view_core)
96 return;
97
98 web_contents_ = content_view_core->GetWebContents();
99 web_contents_->SetUserData(kUserDataKey, new UserData(this));
100 }
101
102 void InProcessViewRenderer::WebContentsGone() {
103 web_contents_ = NULL;
31 } 104 }
32 105
33 bool InProcessViewRenderer::RenderPicture(SkCanvas* canvas) { 106 bool InProcessViewRenderer::RenderPicture(SkCanvas* canvas) {
34 return compositor_ && compositor_->DemandDrawSw(canvas); 107 return compositor_ && compositor_->DemandDrawSw(canvas);
35 } 108 }
36 109
110 void InProcessViewRenderer::DrawGL(AwDrawGLInfo* draw_info) {
111 DCHECK(view_visible_);
112 DCHECK_EQ(draw_info->mode, AwDrawGLInfo::kModeDraw);
113
114 // We need to watch if the current Android context has changed and enforce
115 // a clean-up in the compositor.
116 EGLContext current_context = eglGetCurrentContext();
117 if (!current_context) {
118 LOG(WARNING) << "No current context attached. Skipping composite.";
119 return;
120 }
121
122 if (last_frame_context_ != current_context) {
123 last_frame_context_ = current_context;
124 // TODO(boliu): Handle context lost
125 }
126
127 // TODO(boliu): Need this?
128 if (!compositor_)
129 return;
130
131 // TODO(boliu): Don't ignore other transforms and whatnot.
132 // TODO(boliu): Have a scoped var to unset this.
133 inside_draw_ = true;
134 compositor_->DemandDrawHw(gfx::Rect(draw_info->width, draw_info->height));
135 inside_draw_ = false;
136
137 // The GL functor must ensure these are set to zero before returning.
138 // Not setting them leads to graphical artifacts that can affect other apps.
139 glBindBuffer(GL_ARRAY_BUFFER, 0);
140 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
141
142 if (continuous_invalidate_)
143 Invalidate();
144 }
145
146 void InProcessViewRenderer::SetScrollForHWFrame(int x, int y) {
147 // TODO(boliu): Implement
148 }
149
150 bool InProcessViewRenderer::DrawSW(jobject java_canvas,
151 const gfx::Rect& clip) {
152 return false;
153 }
154
155 base::android::ScopedJavaLocalRef<jobject>
156 InProcessViewRenderer::CapturePicture() {
157 return base::android::ScopedJavaLocalRef<jobject>();
158 }
159
160 void InProcessViewRenderer::EnableOnNewPicture(OnNewPictureMode mode) {
161 }
162
163 void InProcessViewRenderer::OnVisibilityChanged(bool view_visible,
164 bool window_visible) {
165 view_visible_ = window_visible && view_visible;
166 // TODO(boliu): Need invalidate here if visible?
167 }
168
169 void InProcessViewRenderer::OnSizeChanged(int width, int height) {
170 }
171
172 void InProcessViewRenderer::OnAttachedToWindow(int width, int height) {
173 }
174
175 void InProcessViewRenderer::OnDetachedFromWindow() {
176 }
177
178 bool InProcessViewRenderer::IsAttachedToWindow() {
179 return false;
180 }
181
182 bool InProcessViewRenderer::IsViewVisible() {
183 return view_visible_;
184 }
185
186 gfx::Rect InProcessViewRenderer::GetScreenRect() {
187 return gfx::Rect();
188 }
189
37 void InProcessViewRenderer::DidDestroyCompositor( 190 void InProcessViewRenderer::DidDestroyCompositor(
38 content::SynchronousCompositor* compositor) { 191 content::SynchronousCompositor* compositor) {
39 // Allow for transient hand-over when two compositors may reference 192 // Allow for transient hand-over when two compositors may reference
40 // a single client. 193 // a single client.
41 if (compositor_ == compositor) 194 if (compositor_ == compositor)
42 compositor_ = NULL; 195 compositor_ = NULL;
43 } 196 }
44 197
198 void InProcessViewRenderer::SetContinuousInvalidate(bool invalidate) {
199 if (continuous_invalidate_ == invalidate)
200 return;
201
202 continuous_invalidate_ = invalidate;
203 // TODO(boliu): Handle if not attached to window case.
204 if (continuous_invalidate_ && !inside_draw_)
205 Invalidate();
206 }
207
208 void InProcessViewRenderer::Invalidate() {
209 DCHECK(view_visible_);
210 client_->Invalidate();
211 }
212
45 } // namespace android_webview 213 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698