Chromium Code Reviews| Index: android_webview/browser/in_process_renderer/in_process_view_renderer.cc |
| diff --git a/android_webview/browser/in_process_renderer/in_process_view_renderer.cc b/android_webview/browser/in_process_renderer/in_process_view_renderer.cc |
| index 63ac22372889cb63e7ecac4d929a280b5a1b30ab..ec0f9ba83043b9b6ef076c1b423c0e2e3ea56287 100644 |
| --- a/android_webview/browser/in_process_renderer/in_process_view_renderer.cc |
| +++ b/android_webview/browser/in_process_renderer/in_process_view_renderer.cc |
| @@ -4,21 +4,91 @@ |
| #include "android_webview/browser/in_process_renderer/in_process_view_renderer.h" |
| +#include "android_webview/public/browser/draw_gl.h" |
| #include "base/logging.h" |
| +#include "content/public/browser/android/content_view_core.h" |
| +#include "content/public/browser/render_view_host.h" |
| +#include "content/public/browser/web_contents.h" |
| #include "content/public/renderer/android/synchronous_compositor.h" |
| +#include "ui/gl/gl_bindings.h" |
| namespace android_webview { |
| +namespace { |
| +const void* kUserDataKey = &kUserDataKey; |
| + |
| +class UserData : public content::WebContents::Data { |
| + public: |
| + UserData(InProcessViewRenderer* ptr) : instance_(ptr) {} |
| + virtual ~UserData() { |
| + instance_->WebContentsGone(); |
| + } |
| + |
| + static InProcessViewRenderer* GetInstance(content::WebContents* contents) { |
| + if (!contents) |
| + return NULL; |
| + UserData* data = reinterpret_cast<UserData*>( |
| + contents->GetUserData(kUserDataKey)); |
| + return data ? data->instance_ : NULL; |
| + } |
| + |
| + private: |
| + InProcessViewRenderer* instance_; |
| +}; |
| + |
| +} // namespace |
| + |
| InProcessViewRenderer::InProcessViewRenderer( |
| BrowserViewRenderer::Client* client, |
| JavaHelper* java_helper) |
| - : BrowserViewRendererImpl(client, java_helper), |
| - compositor_(NULL) { |
| + : web_contents_(NULL), |
| + compositor_(NULL), |
| + client_(client), |
| + view_visible_(false), |
| + about_to_hardware_draw_(false), |
| + continuous_invalidate_(false), |
| + last_frame_context_(NULL) { |
| } |
| InProcessViewRenderer::~InProcessViewRenderer() { |
| if (compositor_) |
| compositor_->SetClient(NULL); |
| + SetContents(NULL); |
| +} |
| + |
| +// static |
| +InProcessViewRenderer* InProcessViewRenderer::FromWebContents( |
| + content::WebContents* contents) { |
| + return UserData::GetInstance(contents); |
| +} |
| + |
| +// static |
| +BrowserViewRenderer* BrowserViewRenderer::FromId(int render_process_id, |
| + int render_view_id) { |
| + const content::RenderViewHost* rvh = |
| + content::RenderViewHost::FromID(render_process_id, render_view_id); |
| + if (!rvh) return NULL; |
| + return InProcessViewRenderer::FromWebContents( |
| + content::WebContents::FromRenderViewHost(rvh)); |
| +} |
| + |
| +void InProcessViewRenderer::SetContents( |
| + content::ContentViewCore* content_view_core) { |
| + // First remove association from the prior ContentViewCore / WebContents. |
| + if (web_contents_) { |
| + web_contents_->SetUserData(kUserDataKey, NULL); |
| + DCHECK(!web_contents_); // WebContentsGone should have been called. |
| + } |
| + |
| + if (!content_view_core) |
| + return; |
| + |
| + web_contents_ = content_view_core->GetWebContents(); |
| + web_contents_->SetUserData(kUserDataKey, new UserData(this)); |
| +} |
| + |
| +void InProcessViewRenderer::WebContentsGone() { |
| + web_contents_ = NULL; |
| } |
| void InProcessViewRenderer::BindSynchronousCompositor( |
| @@ -34,6 +104,84 @@ bool InProcessViewRenderer::RenderPicture(SkCanvas* canvas) { |
| return compositor_ && compositor_->DemandDrawSw(canvas); |
| } |
| +void InProcessViewRenderer::DrawGL(AwDrawGLInfo* draw_info) { |
| + DCHECK(view_visible_); // TODO(boliu): This can't be false, right..? |
| + DCHECK_EQ(draw_info->mode, AwDrawGLInfo::kModeDraw); |
| + |
| + // We need to watch if the current Android context has changed and enforce |
| + // a clean-up in the compositor. |
| + EGLContext current_context = eglGetCurrentContext(); |
| + if (!current_context) { |
| + LOG(WARNING) << "No current context attached. Skipping composite."; |
| + return; |
| + } |
| + |
| + if (last_frame_context_ != current_context) { |
| + last_frame_context_ = current_context; |
| + // TODO(boliu): Handle context lost |
| + } |
| + |
| + if (!compositor_) |
| + return; // TODO(boliu): Draw background or checkerboard or something? |
|
joth
2013/05/03 01:26:26
this shouldn't be possible, we should only request
boliu
2013/05/03 05:25:50
Do we ever have to worry about the compositor chan
|
| + |
| + // TODO(boliu): Don't ignore other transforms and whatnot. |
|
joth
2013/05/03 01:26:26
:)
|
| + about_to_hardware_draw_ = true; |
| + compositor_->DemandDrawHw(gfx::Rect(draw_info->width, draw_info->height)); |
| + about_to_hardware_draw_ = false; |
| + |
| + // The GL functor must ensure these are set to zero before returning. |
| + // Not setting them leads to graphical artifacts that can affect other apps. |
| + glBindBuffer(GL_ARRAY_BUFFER, 0); |
| + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
| + |
| + if (continuous_invalidate_) |
| + Invalidate(); |
| +} |
| + |
| +void InProcessViewRenderer::SetScrollForHWFrame(int x, int y) { |
| + // TODO(boliu): Implement |
| +} |
| + |
| +bool InProcessViewRenderer::DrawSW(jobject java_canvas, |
| + const gfx::Rect& clip) { |
| + return false; |
| +} |
| + |
| +base::android::ScopedJavaLocalRef<jobject> |
| +InProcessViewRenderer::CapturePicture() { |
| + return base::android::ScopedJavaLocalRef<jobject>(); |
| +} |
| + |
| +void InProcessViewRenderer::EnableOnNewPicture(OnNewPictureMode mode) { |
| +} |
| + |
| +void InProcessViewRenderer::OnVisibilityChanged(bool view_visible, |
| + bool window_visible) { |
| + view_visible_ = window_visible && view_visible; |
| + // TODO(boliu): Need invalidate here if visible? |
| +} |
| + |
| +void InProcessViewRenderer::OnSizeChanged(int width, int height) { |
| +} |
| + |
| +void InProcessViewRenderer::OnAttachedToWindow(int width, int height) { |
|
joth
2013/05/03 01:26:26
likewise TODO , if we have a compositor, and iff t
|
| +} |
| + |
| +void InProcessViewRenderer::OnDetachedFromWindow() { |
| +} |
| + |
| +bool InProcessViewRenderer::IsAttachedToWindow() { |
| + return false; |
| +} |
| + |
| +bool InProcessViewRenderer::IsViewVisible() { |
| + return view_visible_; |
| +} |
| + |
| +gfx::Rect InProcessViewRenderer::GetScreenRect() { |
| + return gfx::Rect(); |
| +} |
| + |
| void InProcessViewRenderer::DidDestroyCompositor( |
| content::SynchronousCompositor* compositor) { |
| // Allow for transient hand-over when two compositors may reference |
| @@ -42,4 +190,18 @@ void InProcessViewRenderer::DidDestroyCompositor( |
| compositor_ = NULL; |
| } |
| +void InProcessViewRenderer::SetContinuousInvalidate(bool invalidate) { |
| + if (continuous_invalidate_ == invalidate) |
| + return; |
| + |
| + continuous_invalidate_ = invalidate; |
| + if (continuous_invalidate_ && !about_to_hardware_draw_) |
|
joth
2013/05/03 01:26:26
I don't think 'hardware' is important for this. I'
|
| + Invalidate(); |
|
joth
2013/05/03 01:26:26
TODO - handle not attached to window scenario?
|
| +} |
| + |
| +void InProcessViewRenderer::Invalidate() { |
| + DCHECK(view_visible_); |
| + client_->Invalidate(); |
| +} |
| + |
| } // namespace android_webview |