diff options
author | boliu@chromium.org <boliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-08 16:46:02 +0000 |
---|---|---|
committer | boliu@chromium.org <boliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-08 16:46:02 +0000 |
commit | 19e43c508e0b6a61a24c859b80d3a2b315a4e6f7 (patch) | |
tree | 5c398d872582e5f8adb4539f5f7cbce863108531 | |
parent | b7c90dc0a432855f614f3cca5cd85f6536b1f988 (diff) | |
download | chromium_src-19e43c508e0b6a61a24c859b80d3a2b315a4e6f7.zip chromium_src-19e43c508e0b6a61a24c859b80d3a2b315a4e6f7.tar.gz chromium_src-19e43c508e0b6a61a24c859b80d3a2b315a4e6f7.tar.bz2 |
Hook up android webview synchronous compositor GL init
BUG=230197
Review URL: https://chromiumcodereview.appspot.com/16613002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@205072 0039d316-1c4b-4281-b951-d872f2087c98
6 files changed, 64 insertions, 56 deletions
diff --git a/android_webview/browser/in_process_view_renderer.cc b/android_webview/browser/in_process_view_renderer.cc index 353d4c0..29969da 100644 --- a/android_webview/browser/in_process_view_renderer.cc +++ b/android_webview/browser/in_process_view_renderer.cc @@ -9,6 +9,7 @@ #include "android_webview/public/browser/draw_gl.h" #include "android_webview/public/browser/draw_sw.h" #include "base/android/jni_android.h" +#include "base/command_line.h" #include "base/debug/trace_event.h" #include "base/logging.h" #include "content/public/browser/android/content_view_core.h" @@ -316,8 +317,8 @@ void InProcessViewRenderer::WebContentsGone() { bool InProcessViewRenderer::PrepareDrawGL(int x, int y) { // No harm in updating |hw_rendering_scroll_| even if we return false. hw_rendering_scroll_ = gfx::Point(x, y); - return attached_to_window_ && compositor_ && compositor_->IsHwReady() && - !hardware_failed_; + return attached_to_window_ && compositor_ && !hardware_failed_ && + CommandLine::ForCurrentProcess()->HasSwitch("testing-webview-gl-mode"); } void InProcessViewRenderer::DrawGL(AwDrawGLInfo* draw_info) { @@ -334,9 +335,12 @@ void InProcessViewRenderer::DrawGL(AwDrawGLInfo* draw_info) { GLStateRestore state_restore; if (attached_to_window_ && compositor_ && !hardware_initialized_) { - // TODO(boliu): Actually initialize the compositor GL path. + hardware_failed_ = !compositor_->InitializeHwDraw(); hardware_initialized_ = true; egl_context_at_init_ = current_context; + + if (hardware_failed_) + return; } if (draw_info->mode == AwDrawGLInfo::kModeProcess) diff --git a/content/browser/android/in_process/synchronous_compositor_impl.cc b/content/browser/android/in_process/synchronous_compositor_impl.cc index 195bb8b..425788b 100644 --- a/content/browser/android/in_process/synchronous_compositor_impl.cc +++ b/content/browser/android/in_process/synchronous_compositor_impl.cc @@ -120,24 +120,16 @@ SynchronousCompositorImpl::~SynchronousCompositorImpl() { compositor_client_->DidDestroyCompositor(this); } -bool SynchronousCompositorImpl::IsHwReady() { - DCHECK(CalledOnValidThread()); - DCHECK(output_surface_); - - return output_surface_->IsHwReady(); -} - void SynchronousCompositorImpl::SetClient( SynchronousCompositorClient* compositor_client) { DCHECK(CalledOnValidThread()); compositor_client_ = compositor_client; } -bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) { +bool SynchronousCompositorImpl::InitializeHwDraw() { DCHECK(CalledOnValidThread()); DCHECK(output_surface_); - - return output_surface_->DemandDrawSw(canvas); + return output_surface_->InitializeHwDraw(); } bool SynchronousCompositorImpl::DemandDrawHw( @@ -150,6 +142,13 @@ bool SynchronousCompositorImpl::DemandDrawHw( return output_surface_->DemandDrawHw(view_size, transform, damage_area); } +bool SynchronousCompositorImpl::DemandDrawSw(SkCanvas* canvas) { + DCHECK(CalledOnValidThread()); + DCHECK(output_surface_); + + return output_surface_->DemandDrawSw(canvas); +} + void SynchronousCompositorImpl::DidBindOutputSurface( SynchronousCompositorOutputSurface* output_surface) { DCHECK(CalledOnValidThread()); diff --git a/content/browser/android/in_process/synchronous_compositor_impl.h b/content/browser/android/in_process/synchronous_compositor_impl.h index a2c2b3c..bb09ff4 100644 --- a/content/browser/android/in_process/synchronous_compositor_impl.h +++ b/content/browser/android/in_process/synchronous_compositor_impl.h @@ -38,14 +38,14 @@ class SynchronousCompositorImpl InputEventAckState HandleInputEvent(const WebKit::WebInputEvent& input_event); // SynchronousCompositor - virtual bool IsHwReady() OVERRIDE; virtual void SetClient(SynchronousCompositorClient* compositor_client) OVERRIDE; - virtual bool DemandDrawSw(SkCanvas* canvas) OVERRIDE; + virtual bool InitializeHwDraw() OVERRIDE; virtual bool DemandDrawHw( gfx::Size view_size, const gfx::Transform& transform, gfx::Rect clip) OVERRIDE; + virtual bool DemandDrawSw(SkCanvas* canvas) OVERRIDE; // SynchronousCompositorOutputSurfaceDelegate virtual void DidBindOutputSurface( diff --git a/content/browser/android/in_process/synchronous_compositor_output_surface.cc b/content/browser/android/in_process/synchronous_compositor_output_surface.cc index 4000a2c..8d25082 100644 --- a/content/browser/android/in_process/synchronous_compositor_output_surface.cc +++ b/content/browser/android/in_process/synchronous_compositor_output_surface.cc @@ -9,6 +9,7 @@ #include "base/time.h" #include "cc/output/compositor_frame.h" #include "cc/output/compositor_frame_ack.h" +#include "cc/output/context_provider.h" #include "cc/output/output_surface_client.h" #include "cc/output/software_output_device.h" #include "content/browser/android/in_process/synchronous_compositor_impl.h" @@ -34,9 +35,6 @@ namespace { // TODO(boliu): RenderThreadImpl should create in process contexts as well. scoped_ptr<WebKit::WebGraphicsContext3D> CreateWebGraphicsContext3D() { - if (!CommandLine::ForCurrentProcess()->HasSwitch("testing-webview-gl-mode")) - return scoped_ptr<WebKit::WebGraphicsContext3D>(); - WebKit::WebGraphicsContext3D::Attributes attributes; attributes.antialias = false; attributes.shareResources = true; @@ -84,7 +82,6 @@ class SynchronousCompositorOutputSurface::SoftwareDevice SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( int routing_id) : cc::OutputSurface( - CreateWebGraphicsContext3D(), scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareDevice(this))), routing_id_(routing_id), needs_begin_frame_(false), @@ -143,10 +140,6 @@ void SynchronousCompositorOutputSurface::SwapBuffers( did_swap_buffer_ = true; } -bool SynchronousCompositorOutputSurface::IsHwReady() { - return context3d() != NULL; -} - namespace { void AdjustTransformForClip(gfx::Transform* transform, gfx::Rect clip) { // The system-provided transform translates us from the screen origin to the @@ -155,35 +148,20 @@ void AdjustTransformForClip(gfx::Transform* transform, gfx::Rect clip) { } } // namespace -bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { +bool SynchronousCompositorOutputSurface::InitializeHwDraw() { DCHECK(CalledOnValidThread()); - DCHECK(canvas); - DCHECK(!current_sw_canvas_); - current_sw_canvas_ = canvas; - - SkIRect canvas_clip; - canvas->getClipDeviceBounds(&canvas_clip); - gfx::Rect clip = gfx::SkIRectToRect(canvas_clip); - - gfx::Transform transform(gfx::Transform::kSkipInitialization); - transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. - AdjustTransformForClip(&transform, clip); - - surface_size_ = gfx::Size(canvas->getDeviceSize().width(), - canvas->getDeviceSize().height()); - client_->SetExternalDrawConstraints(transform, clip); - - InvokeComposite(clip.size()); + DCHECK(client_); + DCHECK(!context3d_); - bool finished_draw = current_sw_canvas_ == NULL; - current_sw_canvas_ = NULL; - return finished_draw; + // TODO(boliu): Get a context provider in constructor and pass here. + return InitializeAndSetContext3D(CreateWebGraphicsContext3D().Pass(), + scoped_refptr<cc::ContextProvider>()); } bool SynchronousCompositorOutputSurface::DemandDrawHw( - gfx::Size surface_size, - const gfx::Transform& transform, - gfx::Rect clip) { + gfx::Size surface_size, + const gfx::Transform& transform, + gfx::Rect clip) { DCHECK(CalledOnValidThread()); DCHECK(client_); DCHECK(context3d()); @@ -204,9 +182,36 @@ bool SynchronousCompositorOutputSurface::DemandDrawHw( client_->SetExternalDrawConstraints(adjusted_transform, clip); InvokeComposite(clip.size()); + // TODO(boliu): Check if context is lost here. + return did_swap_buffer_; } +bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { + DCHECK(CalledOnValidThread()); + DCHECK(canvas); + DCHECK(!current_sw_canvas_); + current_sw_canvas_ = canvas; + + SkIRect canvas_clip; + canvas->getClipDeviceBounds(&canvas_clip); + gfx::Rect clip = gfx::SkIRectToRect(canvas_clip); + + gfx::Transform transform(gfx::Transform::kSkipInitialization); + transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. + AdjustTransformForClip(&transform, clip); + + surface_size_ = gfx::Size(canvas->getDeviceSize().width(), + canvas->getDeviceSize().height()); + client_->SetExternalDrawConstraints(transform, clip); + + InvokeComposite(clip.size()); + + bool finished_draw = current_sw_canvas_ == NULL; + current_sw_canvas_ = NULL; + return finished_draw; +} + void SynchronousCompositorOutputSurface::InvokeComposite( gfx::Size damage_size) { client_->SetNeedsRedrawRect(gfx::Rect(damage_size)); diff --git a/content/browser/android/in_process/synchronous_compositor_output_surface.h b/content/browser/android/in_process/synchronous_compositor_output_surface.h index 78672fd..508d2b4 100644 --- a/content/browser/android/in_process/synchronous_compositor_output_surface.h +++ b/content/browser/android/in_process/synchronous_compositor_output_surface.h @@ -53,11 +53,11 @@ class SynchronousCompositorOutputSurface virtual void SwapBuffers(const ui::LatencyInfo& info) OVERRIDE; // Partial SynchronousCompositor API implementation. - bool IsHwReady(); - bool DemandDrawSw(SkCanvas* canvas); + bool InitializeHwDraw(); bool DemandDrawHw(gfx::Size surface_size, const gfx::Transform& transform, gfx::Rect clip); + bool DemandDrawSw(SkCanvas* canvas); private: class SoftwareDevice; diff --git a/content/public/browser/android/synchronous_compositor.h b/content/public/browser/android/synchronous_compositor.h index f380b0e..dbc9af5 100644 --- a/content/public/browser/android/synchronous_compositor.h +++ b/content/public/browser/android/synchronous_compositor.h @@ -36,13 +36,9 @@ class SynchronousCompositor { // the caller. virtual void SetClient(SynchronousCompositorClient* client) = 0; - // Returns true if the compositor is fully initialized and ready to receive - // calls to DemandDrawHw(). - virtual bool IsHwReady() = 0; - - // "On demand" SW draw, into the supplied canvas (observing the transform - // and clip set there-in). - virtual bool DemandDrawSw(SkCanvas* canvas) = 0; + // One-time synchronously initialize compositor for hardware draw. + // It is invalid to DemandDrawHw before this returns true. + virtual bool InitializeHwDraw() = 0; // "On demand" hardware draw. The content is first clipped to |damage_area|, // then transformed through |transform|, and finally clipped to |view_size|. @@ -51,6 +47,10 @@ class SynchronousCompositor { const gfx::Transform& transform, gfx::Rect damage_area) = 0; + // "On demand" SW draw, into the supplied canvas (observing the transform + // and clip set there-in). + virtual bool DemandDrawSw(SkCanvas* canvas) = 0; + protected: virtual ~SynchronousCompositor() {} }; |