| Index: android_webview/browser/browser_view_renderer.cc
|
| diff --git a/android_webview/browser/in_process_view_renderer.cc b/android_webview/browser/browser_view_renderer.cc
|
| similarity index 43%
|
| copy from android_webview/browser/in_process_view_renderer.cc
|
| copy to android_webview/browser/browser_view_renderer.cc
|
| index 48a43e18e2fe10854385d1750dadb52790790b99..3bf87bffcb37dc9909f71eb367fcbf2c490fab83 100644
|
| --- a/android_webview/browser/in_process_view_renderer.cc
|
| +++ b/android_webview/browser/browser_view_renderer.cc
|
| @@ -1,30 +1,23 @@
|
| -// Copyright 2013 The Chromium Authors. All rights reserved.
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "android_webview/browser/in_process_view_renderer.h"
|
| +#include "android_webview/browser/browser_view_renderer.h"
|
|
|
| -#include "android_webview/browser/aw_gl_surface.h"
|
| -#include "android_webview/browser/scoped_app_gl_state_restore.h"
|
| -#include "android_webview/common/aw_switches.h"
|
| +#include "android_webview/browser/hardware_renderer.h"
|
| #include "android_webview/public/browser/draw_gl.h"
|
| #include "base/android/jni_android.h"
|
| #include "base/auto_reset.h"
|
| -#include "base/command_line.h"
|
| #include "base/debug/trace_event.h"
|
| -#include "base/lazy_instance.h"
|
| #include "base/logging.h"
|
| -#include "base/strings/string_number_conversions.h"
|
| #include "base/strings/stringprintf.h"
|
| +#include "content/public/browser/android/synchronous_compositor.h"
|
| #include "content/public/browser/browser_thread.h"
|
| #include "content/public/browser/web_contents.h"
|
| -#include "content/public/common/content_switches.h"
|
| -#include "gpu/command_buffer/service/in_process_command_buffer.h"
|
| #include "third_party/skia/include/core/SkBitmap.h"
|
| #include "third_party/skia/include/core/SkBitmapDevice.h"
|
| #include "third_party/skia/include/core/SkCanvas.h"
|
| #include "third_party/skia/include/core/SkPicture.h"
|
| -#include "ui/gfx/transform.h"
|
| #include "ui/gfx/vector2d_conversions.h"
|
|
|
| using base::android::AttachCurrentThread;
|
| @@ -36,173 +29,12 @@ 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_;
|
| -};
|
| -
|
| -bool HardwareEnabled() {
|
| - static bool g_hw_enabled = !CommandLine::ForCurrentProcess()->HasSwitch(
|
| - switches::kDisableWebViewGLMode);
|
| - return g_hw_enabled;
|
| -}
|
| -
|
| const int64 kFallbackTickTimeoutInMilliseconds = 20;
|
|
|
| -// Used to calculate memory and resource allocation. Determined experimentally.
|
| -size_t g_memory_multiplier = 10;
|
| -size_t g_num_gralloc_limit = 150;
|
| -const size_t kBytesPerPixel = 4;
|
| -const size_t kMemoryAllocationStep = 5 * 1024 * 1024;
|
| -
|
| -base::LazyInstance<GLViewRendererManager>::Leaky g_view_renderer_manager =
|
| - LAZY_INSTANCE_INITIALIZER;
|
| -
|
| -class ScopedAllowGL {
|
| - public:
|
| - ScopedAllowGL();
|
| - ~ScopedAllowGL();
|
| -
|
| - static bool IsAllowed() {
|
| - return g_view_renderer_manager.Get().OnRenderThread() && allow_gl;
|
| - }
|
| -
|
| - private:
|
| - static bool allow_gl;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(ScopedAllowGL);
|
| -};
|
| -
|
| -ScopedAllowGL::ScopedAllowGL() {
|
| - DCHECK(g_view_renderer_manager.Get().OnRenderThread());
|
| - DCHECK(!allow_gl);
|
| - allow_gl = true;
|
| -}
|
| -
|
| -ScopedAllowGL::~ScopedAllowGL() {
|
| - allow_gl = false;
|
| -}
|
| -
|
| -bool ScopedAllowGL::allow_gl = false;
|
| -
|
| -void RequestProcessGLOnUIThread() {
|
| - if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
|
| - BrowserThread::PostTask(
|
| - BrowserThread::UI, FROM_HERE, base::Bind(&RequestProcessGLOnUIThread));
|
| - return;
|
| - }
|
| -
|
| - InProcessViewRenderer* renderer = static_cast<InProcessViewRenderer*>(
|
| - g_view_renderer_manager.Get().GetMostRecentlyDrawn());
|
| - if (!renderer || !renderer->RequestProcessGL()) {
|
| - LOG(ERROR) << "Failed to request GL process. Deadlock likely: "
|
| - << !!renderer;
|
| - }
|
| -}
|
| -
|
| -class DeferredGpuCommandService
|
| - : public gpu::InProcessCommandBuffer::Service,
|
| - public base::RefCountedThreadSafe<DeferredGpuCommandService> {
|
| - public:
|
| - DeferredGpuCommandService();
|
| -
|
| - virtual void ScheduleTask(const base::Closure& task) OVERRIDE;
|
| - virtual void ScheduleIdleWork(const base::Closure& task) OVERRIDE;
|
| - virtual bool UseVirtualizedGLContexts() OVERRIDE;
|
| -
|
| - void RunTasks();
|
| -
|
| - virtual void AddRef() const OVERRIDE {
|
| - base::RefCountedThreadSafe<DeferredGpuCommandService>::AddRef();
|
| - }
|
| - virtual void Release() const OVERRIDE {
|
| - base::RefCountedThreadSafe<DeferredGpuCommandService>::Release();
|
| - }
|
| -
|
| - protected:
|
| - virtual ~DeferredGpuCommandService();
|
| - friend class base::RefCountedThreadSafe<DeferredGpuCommandService>;
|
| -
|
| - private:
|
| - base::Lock tasks_lock_;
|
| - std::queue<base::Closure> tasks_;
|
| - DISALLOW_COPY_AND_ASSIGN(DeferredGpuCommandService);
|
| -};
|
| -
|
| -DeferredGpuCommandService::DeferredGpuCommandService() {}
|
| -
|
| -DeferredGpuCommandService::~DeferredGpuCommandService() {
|
| - base::AutoLock lock(tasks_lock_);
|
| - DCHECK(tasks_.empty());
|
| -}
|
| -
|
| -// Called from different threads!
|
| -void DeferredGpuCommandService::ScheduleTask(const base::Closure& task) {
|
| - {
|
| - base::AutoLock lock(tasks_lock_);
|
| - tasks_.push(task);
|
| - }
|
| - if (ScopedAllowGL::IsAllowed()) {
|
| - RunTasks();
|
| - } else {
|
| - RequestProcessGLOnUIThread();
|
| - }
|
| -}
|
| -
|
| -void DeferredGpuCommandService::ScheduleIdleWork(
|
| - const base::Closure& callback) {
|
| - // TODO(sievers): Should this do anything?
|
| -}
|
| -
|
| -bool DeferredGpuCommandService::UseVirtualizedGLContexts() { return true; }
|
| -
|
| -void DeferredGpuCommandService::RunTasks() {
|
| - bool has_more_tasks;
|
| - {
|
| - base::AutoLock lock(tasks_lock_);
|
| - has_more_tasks = tasks_.size() > 0;
|
| - }
|
| -
|
| - while (has_more_tasks) {
|
| - base::Closure task;
|
| - {
|
| - base::AutoLock lock(tasks_lock_);
|
| - task = tasks_.front();
|
| - tasks_.pop();
|
| - }
|
| - task.Run();
|
| - {
|
| - base::AutoLock lock(tasks_lock_);
|
| - has_more_tasks = tasks_.size() > 0;
|
| - }
|
| -
|
| - }
|
| -}
|
| -
|
| -base::LazyInstance<scoped_refptr<DeferredGpuCommandService> > g_service =
|
| - LAZY_INSTANCE_INITIALIZER;
|
| -
|
| } // namespace
|
|
|
| -InProcessViewRenderer::InProcessViewRenderer(
|
| - BrowserViewRenderer::Client* client,
|
| - content::WebContents* web_contents)
|
| +BrowserViewRenderer::BrowserViewRenderer(BrowserViewRendererClient* client,
|
| + content::WebContents* web_contents)
|
| : client_(client),
|
| web_contents_(web_contents),
|
| compositor_(NULL),
|
| @@ -217,301 +49,80 @@ InProcessViewRenderer::InProcessViewRenderer(
|
| compositor_needs_continuous_invalidate_(false),
|
| block_invalidates_(false),
|
| width_(0),
|
| - height_(0),
|
| - hardware_initialized_(false),
|
| - hardware_failed_(false),
|
| - last_egl_context_(NULL),
|
| - manager_key_(g_view_renderer_manager.Get().NullKey()) {
|
| + height_(0) {
|
| CHECK(web_contents_);
|
| - web_contents_->SetUserData(kUserDataKey, new UserData(this));
|
| content::SynchronousCompositor::SetClientForWebContents(web_contents_, this);
|
|
|
| // Currently the logic in this class relies on |compositor_| remaining NULL
|
| // until the DidInitializeCompositor() call, hence it is not set here.
|
| }
|
|
|
| -InProcessViewRenderer::~InProcessViewRenderer() {
|
| - CHECK(web_contents_);
|
| +BrowserViewRenderer::~BrowserViewRenderer() {
|
| content::SynchronousCompositor::SetClientForWebContents(web_contents_, NULL);
|
| - web_contents_->SetUserData(kUserDataKey, NULL);
|
| - NoLongerExpectsDrawGL();
|
| - DCHECK(web_contents_ == NULL); // WebContentsGone should have been called.
|
| }
|
|
|
| -void InProcessViewRenderer::NoLongerExpectsDrawGL() {
|
| - GLViewRendererManager& mru = g_view_renderer_manager.Get();
|
| - if (manager_key_ != mru.NullKey()) {
|
| - mru.NoLongerExpectsDrawGL(manager_key_);
|
| - manager_key_ = mru.NullKey();
|
| - }
|
| -}
|
| -
|
| -// static
|
| -InProcessViewRenderer* InProcessViewRenderer::FromWebContents(
|
| - content::WebContents* contents) {
|
| - return UserData::GetInstance(contents);
|
| -}
|
| -
|
| -void InProcessViewRenderer::WebContentsGone() {
|
| - web_contents_ = NULL;
|
| - compositor_ = NULL;
|
| -}
|
| -
|
| -// static
|
| -void InProcessViewRenderer::CalculateTileMemoryPolicy() {
|
| - CommandLine* cl = CommandLine::ForCurrentProcess();
|
| - if (cl->HasSwitch(switches::kTileMemoryMultiplier)) {
|
| - std::string string_value =
|
| - cl->GetSwitchValueASCII(switches::kTileMemoryMultiplier);
|
| - int int_value = 0;
|
| - if (base::StringToInt(string_value, &int_value) &&
|
| - int_value >= 2 && int_value <= 50) {
|
| - g_memory_multiplier = int_value;
|
| - }
|
| - }
|
| -
|
| - if (cl->HasSwitch(switches::kNumGrallocBuffersPerWebview)) {
|
| - std::string string_value =
|
| - cl->GetSwitchValueASCII(switches::kNumGrallocBuffersPerWebview);
|
| - int int_value = 0;
|
| - if (base::StringToInt(string_value, &int_value) &&
|
| - int_value >= 50 && int_value <= 500) {
|
| - g_num_gralloc_limit = int_value;
|
| - }
|
| - }
|
| -
|
| - const char kDefaultTileSize[] = "384";
|
| - if (!cl->HasSwitch(switches::kDefaultTileWidth))
|
| - cl->AppendSwitchASCII(switches::kDefaultTileWidth, kDefaultTileSize);
|
| -
|
| - if (!cl->HasSwitch(switches::kDefaultTileHeight))
|
| - cl->AppendSwitchASCII(switches::kDefaultTileHeight, kDefaultTileSize);
|
| -}
|
| -
|
| -bool InProcessViewRenderer::RequestProcessGL() {
|
| - return client_->RequestDrawGL(NULL);
|
| -}
|
| -
|
| -void InProcessViewRenderer::TrimMemory(int level) {
|
| - // Constants from Android ComponentCallbacks2.
|
| - enum {
|
| - TRIM_MEMORY_RUNNING_LOW = 10,
|
| - TRIM_MEMORY_UI_HIDDEN = 20,
|
| - TRIM_MEMORY_BACKGROUND = 40,
|
| - };
|
| -
|
| - // Not urgent enough. TRIM_MEMORY_UI_HIDDEN is treated specially because
|
| - // it does not indicate memory pressure, but merely that the app is
|
| - // backgrounded.
|
| - if (level < TRIM_MEMORY_RUNNING_LOW || level == TRIM_MEMORY_UI_HIDDEN)
|
| - return;
|
| -
|
| - // Nothing to drop.
|
| - if (!attached_to_window_ || !hardware_initialized_ || !compositor_)
|
| - return;
|
| -
|
| - // Do not release resources on view we expect to get DrawGL soon.
|
| - if (level < TRIM_MEMORY_BACKGROUND) {
|
| +void BrowserViewRenderer::TrimMemory(int level) {
|
| + if (hardware_renderer_) {
|
| client_->UpdateGlobalVisibleRect();
|
| - if (view_visible_ && window_visible_ &&
|
| - !cached_global_visible_rect_.IsEmpty()) {
|
| - return;
|
| + bool visible = view_visible_ && window_visible_ &&
|
| + !cached_global_visible_rect_.IsEmpty();
|
| + if (hardware_renderer_->TrimMemory(level, visible)) {
|
| + // Force a draw for compositor to drop tiles synchronously.
|
| + ForceFakeCompositeSW();
|
| }
|
| }
|
| -
|
| - if (!eglGetCurrentContext()) {
|
| - NOTREACHED();
|
| - return;
|
| - }
|
| -
|
| - // Just set the memory limit to 0 and drop all tiles. This will be reset to
|
| - // normal levels in the next DrawGL call.
|
| - content::SynchronousCompositorMemoryPolicy policy;
|
| - policy.bytes_limit = 0;
|
| - policy.num_resources_limit = 0;
|
| - if (memory_policy_ == policy)
|
| - return;
|
| -
|
| - TRACE_EVENT0("android_webview", "InProcessViewRenderer::TrimMemory");
|
| - ScopedAppGLStateRestore state_restore(
|
| - ScopedAppGLStateRestore::MODE_RESOURCE_MANAGEMENT);
|
| - g_service.Get()->RunTasks();
|
| - ScopedAllowGL allow_gl;
|
| -
|
| - SetMemoryPolicy(policy);
|
| - ForceFakeCompositeSW();
|
| -}
|
| -
|
| -void InProcessViewRenderer::SetMemoryPolicy(
|
| - content::SynchronousCompositorMemoryPolicy& new_policy) {
|
| - if (memory_policy_ == new_policy)
|
| - return;
|
| -
|
| - memory_policy_ = new_policy;
|
| - compositor_->SetMemoryPolicy(memory_policy_);
|
| -}
|
| -
|
| -void InProcessViewRenderer::UpdateCachedGlobalVisibleRect() {
|
| - client_->UpdateGlobalVisibleRect();
|
| }
|
|
|
| -bool InProcessViewRenderer::OnDraw(jobject java_canvas,
|
| - bool is_hardware_canvas,
|
| - const gfx::Vector2d& scroll,
|
| - const gfx::Rect& clip) {
|
| - scroll_at_start_of_frame_ = scroll;
|
| +bool BrowserViewRenderer::OnDraw(jobject java_canvas,
|
| + bool is_hardware_canvas,
|
| + const gfx::Vector2d& scroll,
|
| + const gfx::Rect& clip) {
|
| + scroll_at_start_of_frame_ = scroll;
|
| if (clear_view_)
|
| return false;
|
| - if (is_hardware_canvas && attached_to_window_ && HardwareEnabled()) {
|
| + if (is_hardware_canvas && attached_to_window_) {
|
| // We should be performing a hardware draw here. If we don't have the
|
| - // comositor yet or if RequestDrawGL fails, it means we failed this draw and
|
| - // thus return false here to clear to background color for this draw.
|
| + // compositor yet or if RequestDrawGL fails, it means we failed this draw
|
| + // and thus return false here to clear to background color for this draw.
|
| return compositor_ && client_->RequestDrawGL(java_canvas);
|
| }
|
| // Perform a software draw
|
| return DrawSWInternal(java_canvas, clip);
|
| }
|
|
|
| -bool InProcessViewRenderer::InitializeHwDraw() {
|
| - TRACE_EVENT0("android_webview", "InitializeHwDraw");
|
| - DCHECK(!gl_surface_);
|
| - gl_surface_ = new AwGLSurface;
|
| - if (!g_service.Get()) {
|
| - g_service.Get() = new DeferredGpuCommandService;
|
| - content::SynchronousCompositor::SetGpuService(g_service.Get());
|
| - }
|
| - hardware_failed_ = !compositor_->InitializeHwDraw(gl_surface_);
|
| - hardware_initialized_ = true;
|
| -
|
| - if (hardware_failed_)
|
| - gl_surface_ = NULL;
|
| -
|
| - return !hardware_failed_;
|
| -}
|
| -
|
| -void InProcessViewRenderer::DrawGL(AwDrawGLInfo* draw_info) {
|
| - TRACE_EVENT0("android_webview", "InProcessViewRenderer::DrawGL");
|
| -
|
| - manager_key_ = g_view_renderer_manager.Get().DidDrawGL(manager_key_, this);
|
| -
|
| - // 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) {
|
| - TRACE_EVENT_INSTANT0(
|
| - "android_webview", "EarlyOut_NullEGLContext", TRACE_EVENT_SCOPE_THREAD);
|
| - return;
|
| - }
|
| -
|
| - ScopedAppGLStateRestore state_restore(ScopedAppGLStateRestore::MODE_DRAW);
|
| - if (g_service.Get())
|
| - g_service.Get()->RunTasks();
|
| - ScopedAllowGL allow_gl;
|
| -
|
| - if (!attached_to_window_) {
|
| - TRACE_EVENT_INSTANT0(
|
| - "android_webview", "EarlyOut_NotAttached", TRACE_EVENT_SCOPE_THREAD);
|
| +void BrowserViewRenderer::DrawGL(AwDrawGLInfo* draw_info) {
|
| + if (!attached_to_window_ || !compositor_)
|
| return;
|
| - }
|
|
|
| - if (draw_info->mode == AwDrawGLInfo::kModeProcess) {
|
| - TRACE_EVENT_INSTANT0(
|
| - "android_webview", "EarlyOut_ModeProcess", TRACE_EVENT_SCOPE_THREAD);
|
| - return;
|
| - }
|
| -
|
| - if (compositor_ && !hardware_initialized_) {
|
| - if (InitializeHwDraw()) {
|
| - last_egl_context_ = current_context;
|
| - } else {
|
| - TRACE_EVENT_INSTANT0(
|
| - "android_webview", "EarlyOut_HwInitFail", TRACE_EVENT_SCOPE_THREAD);
|
| - LOG(ERROR) << "WebView hardware initialization failed";
|
| - return;
|
| - }
|
| - }
|
| -
|
| - UpdateCachedGlobalVisibleRect();
|
| - if (cached_global_visible_rect_.IsEmpty()) {
|
| - TRACE_EVENT_INSTANT0("android_webview",
|
| - "EarlyOut_EmptyVisibleRect",
|
| - TRACE_EVENT_SCOPE_THREAD);
|
| + client_->UpdateGlobalVisibleRect();
|
| + if (cached_global_visible_rect_.IsEmpty())
|
| return;
|
| - }
|
|
|
| - if (last_egl_context_ != current_context) {
|
| - // TODO(boliu): Handle context lost
|
| - TRACE_EVENT_INSTANT0(
|
| - "android_webview", "EGLContextChanged", TRACE_EVENT_SCOPE_THREAD);
|
| - }
|
| + if (!hardware_renderer_)
|
| + hardware_renderer_.reset(new HardwareRenderer(compositor_, client_));
|
|
|
| - if (!compositor_) {
|
| - TRACE_EVENT_INSTANT0(
|
| - "android_webview", "EarlyOut_NoCompositor", TRACE_EVENT_SCOPE_THREAD);
|
| - return;
|
| + DrawGLInput input;
|
| + input.global_visible_rect = cached_global_visible_rect_;
|
| + input.scroll = scroll_at_start_of_frame_;
|
| + DrawGLResult result;
|
| + {
|
| + base::AutoReset<bool> auto_reset(&block_invalidates_, true);
|
| + result = hardware_renderer_->DrawGL(draw_info, input);
|
| }
|
|
|
| - // DrawGL may be called without OnDraw, so cancel |fallback_tick_| here as
|
| - // well just to be safe.
|
| - fallback_tick_.Cancel();
|
| -
|
| - // Update memory budget. This will no-op in compositor if the policy has not
|
| - // changed since last draw.
|
| - content::SynchronousCompositorMemoryPolicy policy;
|
| - policy.bytes_limit = g_memory_multiplier * kBytesPerPixel *
|
| - cached_global_visible_rect_.width() *
|
| - cached_global_visible_rect_.height();
|
| - // Round up to a multiple of kMemoryAllocationStep.
|
| - policy.bytes_limit =
|
| - (policy.bytes_limit / kMemoryAllocationStep + 1) * kMemoryAllocationStep;
|
| - policy.num_resources_limit = g_num_gralloc_limit;
|
| - SetMemoryPolicy(policy);
|
| -
|
| - DCHECK(gl_surface_);
|
| - gl_surface_->SetBackingFrameBufferObject(
|
| - state_restore.framebuffer_binding_ext());
|
| -
|
| - gfx::Transform transform;
|
| - transform.matrix().setColMajorf(draw_info->transform);
|
| - transform.Translate(scroll_at_start_of_frame_.x(),
|
| - scroll_at_start_of_frame_.y());
|
| - gfx::Rect clip_rect(draw_info->clip_left,
|
| - draw_info->clip_top,
|
| - draw_info->clip_right - draw_info->clip_left,
|
| - draw_info->clip_bottom - draw_info->clip_top);
|
| -
|
| - // Assume we always draw the full visible rect if we are drawing into a layer.
|
| - bool drew_full_visible_rect = true;
|
| -
|
| - gfx::Rect viewport_rect;
|
| - if (!draw_info->is_layer) {
|
| - viewport_rect = cached_global_visible_rect_;
|
| - clip_rect.Intersect(viewport_rect);
|
| - drew_full_visible_rect = clip_rect.Contains(viewport_rect);
|
| - } else {
|
| - viewport_rect = clip_rect;
|
| + if (result.did_draw) {
|
| + fallback_tick_.Cancel();
|
| + block_invalidates_ = false;
|
| + EnsureContinuousInvalidation(draw_info, !result.clip_contains_visible_rect);
|
| }
|
| -
|
| - block_invalidates_ = true;
|
| - // TODO(joth): Check return value.
|
| - compositor_->DemandDrawHw(gfx::Size(draw_info->width, draw_info->height),
|
| - transform,
|
| - viewport_rect,
|
| - clip_rect,
|
| - state_restore.stencil_enabled());
|
| - block_invalidates_ = false;
|
| - gl_surface_->ResetBackingFrameBufferObject();
|
| -
|
| - EnsureContinuousInvalidation(draw_info, !drew_full_visible_rect);
|
| }
|
|
|
| -void InProcessViewRenderer::SetGlobalVisibleRect(
|
| - const gfx::Rect& visible_rect) {
|
| +void BrowserViewRenderer::SetGlobalVisibleRect(const gfx::Rect& visible_rect) {
|
| cached_global_visible_rect_ = visible_rect;
|
| }
|
|
|
| -bool InProcessViewRenderer::DrawSWInternal(jobject java_canvas,
|
| - const gfx::Rect& clip) {
|
| +bool BrowserViewRenderer::DrawSWInternal(jobject java_canvas,
|
| + const gfx::Rect& clip) {
|
| if (clip.IsEmpty()) {
|
| TRACE_EVENT_INSTANT0(
|
| "android_webview", "EarlyOut_EmptyClip", TRACE_EVENT_SCOPE_THREAD);
|
| @@ -524,16 +135,18 @@ bool InProcessViewRenderer::DrawSWInternal(jobject java_canvas,
|
| return false;
|
| }
|
|
|
| - return JavaHelper::GetInstance()->RenderViaAuxilaryBitmapIfNeeded(
|
| - java_canvas,
|
| - scroll_at_start_of_frame_,
|
| - clip,
|
| - base::Bind(&InProcessViewRenderer::CompositeSW, base::Unretained(this)));
|
| + return BrowserViewRendererJavaHelper::GetInstance()
|
| + ->RenderViaAuxilaryBitmapIfNeeded(
|
| + java_canvas,
|
| + scroll_at_start_of_frame_,
|
| + clip,
|
| + base::Bind(&BrowserViewRenderer::CompositeSW,
|
| + base::Unretained(this)));
|
| }
|
|
|
| -skia::RefPtr<SkPicture> InProcessViewRenderer::CapturePicture(int width,
|
| - int height) {
|
| - TRACE_EVENT0("android_webview", "InProcessViewRenderer::CapturePicture");
|
| +skia::RefPtr<SkPicture> BrowserViewRenderer::CapturePicture(int width,
|
| + int height) {
|
| + TRACE_EVENT0("android_webview", "BrowserViewRenderer::CapturePicture");
|
|
|
| // Return empty Picture objects for empty SkPictures.
|
| skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture);
|
| @@ -553,14 +166,14 @@ skia::RefPtr<SkPicture> InProcessViewRenderer::CapturePicture(int width,
|
| return picture;
|
| }
|
|
|
| -void InProcessViewRenderer::EnableOnNewPicture(bool enabled) {
|
| +void BrowserViewRenderer::EnableOnNewPicture(bool enabled) {
|
| on_new_picture_enable_ = enabled;
|
| EnsureContinuousInvalidation(NULL, false);
|
| }
|
|
|
| -void InProcessViewRenderer::ClearView() {
|
| +void BrowserViewRenderer::ClearView() {
|
| TRACE_EVENT_INSTANT0("android_webview",
|
| - "InProcessViewRenderer::ClearView",
|
| + "BrowserViewRenderer::ClearView",
|
| TRACE_EVENT_SCOPE_THREAD);
|
| if (clear_view_)
|
| return;
|
| @@ -570,9 +183,9 @@ void InProcessViewRenderer::ClearView() {
|
| EnsureContinuousInvalidation(NULL, true);
|
| }
|
|
|
| -void InProcessViewRenderer::SetIsPaused(bool paused) {
|
| +void BrowserViewRenderer::SetIsPaused(bool paused) {
|
| TRACE_EVENT_INSTANT1("android_webview",
|
| - "InProcessViewRenderer::SetIsPaused",
|
| + "BrowserViewRenderer::SetIsPaused",
|
| TRACE_EVENT_SCOPE_THREAD,
|
| "paused",
|
| paused);
|
| @@ -580,18 +193,18 @@ void InProcessViewRenderer::SetIsPaused(bool paused) {
|
| EnsureContinuousInvalidation(NULL, false);
|
| }
|
|
|
| -void InProcessViewRenderer::SetViewVisibility(bool view_visible) {
|
| +void BrowserViewRenderer::SetViewVisibility(bool view_visible) {
|
| TRACE_EVENT_INSTANT1("android_webview",
|
| - "InProcessViewRenderer::SetViewVisibility",
|
| + "BrowserViewRenderer::SetViewVisibility",
|
| TRACE_EVENT_SCOPE_THREAD,
|
| "view_visible",
|
| view_visible);
|
| view_visible_ = view_visible;
|
| }
|
|
|
| -void InProcessViewRenderer::SetWindowVisibility(bool window_visible) {
|
| +void BrowserViewRenderer::SetWindowVisibility(bool window_visible) {
|
| TRACE_EVENT_INSTANT1("android_webview",
|
| - "InProcessViewRenderer::SetWindowVisibility",
|
| + "BrowserViewRenderer::SetWindowVisibility",
|
| TRACE_EVENT_SCOPE_THREAD,
|
| "window_visible",
|
| window_visible);
|
| @@ -599,9 +212,9 @@ void InProcessViewRenderer::SetWindowVisibility(bool window_visible) {
|
| EnsureContinuousInvalidation(NULL, false);
|
| }
|
|
|
| -void InProcessViewRenderer::OnSizeChanged(int width, int height) {
|
| +void BrowserViewRenderer::OnSizeChanged(int width, int height) {
|
| TRACE_EVENT_INSTANT2("android_webview",
|
| - "InProcessViewRenderer::OnSizeChanged",
|
| + "BrowserViewRenderer::OnSizeChanged",
|
| TRACE_EVENT_SCOPE_THREAD,
|
| "width",
|
| width,
|
| @@ -611,9 +224,9 @@ void InProcessViewRenderer::OnSizeChanged(int width, int height) {
|
| height_ = height;
|
| }
|
|
|
| -void InProcessViewRenderer::OnAttachedToWindow(int width, int height) {
|
| +void BrowserViewRenderer::OnAttachedToWindow(int width, int height) {
|
| TRACE_EVENT2("android_webview",
|
| - "InProcessViewRenderer::OnAttachedToWindow",
|
| + "BrowserViewRenderer::OnAttachedToWindow",
|
| "width",
|
| width,
|
| "height",
|
| @@ -623,69 +236,47 @@ void InProcessViewRenderer::OnAttachedToWindow(int width, int height) {
|
| height_ = height;
|
| }
|
|
|
| -void InProcessViewRenderer::OnDetachedFromWindow() {
|
| - TRACE_EVENT0("android_webview",
|
| - "InProcessViewRenderer::OnDetachedFromWindow");
|
| -
|
| - NoLongerExpectsDrawGL();
|
| - if (hardware_initialized_) {
|
| - DCHECK(compositor_);
|
| -
|
| - ScopedAppGLStateRestore state_restore(
|
| - ScopedAppGLStateRestore::MODE_RESOURCE_MANAGEMENT);
|
| - g_service.Get()->RunTasks();
|
| - ScopedAllowGL allow_gl;
|
| - compositor_->ReleaseHwDraw();
|
| - hardware_initialized_ = false;
|
| - }
|
| -
|
| - gl_surface_ = NULL;
|
| +void BrowserViewRenderer::OnDetachedFromWindow() {
|
| + TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDetachedFromWindow");
|
| attached_to_window_ = false;
|
| + hardware_renderer_.reset();
|
| }
|
|
|
| -bool InProcessViewRenderer::IsAttachedToWindow() {
|
| +bool BrowserViewRenderer::IsAttachedToWindow() const {
|
| return attached_to_window_;
|
| }
|
|
|
| -bool InProcessViewRenderer::IsVisible() {
|
| +bool BrowserViewRenderer::IsVisible() const {
|
| // Ignore |window_visible_| if |attached_to_window_| is false.
|
| return view_visible_ && (!attached_to_window_ || window_visible_);
|
| }
|
|
|
| -gfx::Rect InProcessViewRenderer::GetScreenRect() {
|
| +gfx::Rect BrowserViewRenderer::GetScreenRect() const {
|
| return gfx::Rect(client_->GetLocationOnScreen(), gfx::Size(width_, height_));
|
| }
|
|
|
| -void InProcessViewRenderer::DidInitializeCompositor(
|
| +void BrowserViewRenderer::DidInitializeCompositor(
|
| content::SynchronousCompositor* compositor) {
|
| TRACE_EVENT0("android_webview",
|
| - "InProcessViewRenderer::DidInitializeCompositor");
|
| + "BrowserViewRenderer::DidInitializeCompositor");
|
| DCHECK(compositor && compositor_ == NULL);
|
| compositor_ = compositor;
|
| - hardware_initialized_ = false;
|
| - hardware_failed_ = false;
|
| }
|
|
|
| -void InProcessViewRenderer::DidDestroyCompositor(
|
| +void BrowserViewRenderer::DidDestroyCompositor(
|
| content::SynchronousCompositor* compositor) {
|
| - TRACE_EVENT0("android_webview",
|
| - "InProcessViewRenderer::DidDestroyCompositor");
|
| + TRACE_EVENT0("android_webview", "BrowserViewRenderer::DidDestroyCompositor");
|
| DCHECK(compositor_ == compositor);
|
| -
|
| - // This can fail if Apps call destroy while the webview is still attached
|
| - // to the view tree. This is an illegal operation that will lead to leaks.
|
| - // Log for now. Consider a proper fix if this becomes a problem.
|
| - LOG_IF(ERROR, hardware_initialized_)
|
| - << "Destroy called before OnDetachedFromWindow. May Leak GL resources";
|
| + DCHECK(!hardware_renderer_.get());
|
| compositor_ = NULL;
|
| }
|
|
|
| -void InProcessViewRenderer::SetContinuousInvalidate(bool invalidate) {
|
| +void BrowserViewRenderer::SetContinuousInvalidate(bool invalidate) {
|
| if (compositor_needs_continuous_invalidate_ == invalidate)
|
| return;
|
|
|
| TRACE_EVENT_INSTANT1("android_webview",
|
| - "InProcessViewRenderer::SetContinuousInvalidate",
|
| + "BrowserViewRenderer::SetContinuousInvalidate",
|
| TRACE_EVENT_SCOPE_THREAD,
|
| "invalidate",
|
| invalidate);
|
| @@ -693,18 +284,18 @@ void InProcessViewRenderer::SetContinuousInvalidate(bool invalidate) {
|
| EnsureContinuousInvalidation(NULL, false);
|
| }
|
|
|
| -void InProcessViewRenderer::SetDipScale(float dip_scale) {
|
| +void BrowserViewRenderer::SetDipScale(float dip_scale) {
|
| dip_scale_ = dip_scale;
|
| CHECK(dip_scale_ > 0);
|
| }
|
|
|
| -gfx::Vector2d InProcessViewRenderer::max_scroll_offset() const {
|
| +gfx::Vector2d BrowserViewRenderer::max_scroll_offset() const {
|
| DCHECK_GT(dip_scale_, 0);
|
| return gfx::ToCeiledVector2d(gfx::ScaleVector2d(
|
| max_scroll_offset_dip_, dip_scale_ * page_scale_factor_));
|
| }
|
|
|
| -void InProcessViewRenderer::ScrollTo(gfx::Vector2d scroll_offset) {
|
| +void BrowserViewRenderer::ScrollTo(gfx::Vector2d scroll_offset) {
|
| gfx::Vector2d max_offset = max_scroll_offset();
|
| gfx::Vector2dF scroll_offset_dip;
|
| // To preserve the invariant that scrolling to the maximum physical pixel
|
| @@ -734,9 +325,9 @@ void InProcessViewRenderer::ScrollTo(gfx::Vector2d scroll_offset) {
|
| compositor_->DidChangeRootLayerScrollOffset();
|
| }
|
|
|
| -void InProcessViewRenderer::DidUpdateContent() {
|
| +void BrowserViewRenderer::DidUpdateContent() {
|
| TRACE_EVENT_INSTANT0("android_webview",
|
| - "InProcessViewRenderer::DidUpdateContent",
|
| + "BrowserViewRenderer::DidUpdateContent",
|
| TRACE_EVENT_SCOPE_THREAD);
|
| clear_view_ = false;
|
| EnsureContinuousInvalidation(NULL, false);
|
| @@ -744,7 +335,7 @@ void InProcessViewRenderer::DidUpdateContent() {
|
| client_->OnNewPicture();
|
| }
|
|
|
| -void InProcessViewRenderer::SetMaxRootLayerScrollOffset(
|
| +void BrowserViewRenderer::SetMaxRootLayerScrollOffset(
|
| gfx::Vector2dF new_value_dip) {
|
| DCHECK_GT(dip_scale_, 0);
|
|
|
| @@ -755,7 +346,7 @@ void InProcessViewRenderer::SetMaxRootLayerScrollOffset(
|
| client_->SetMaxContainerViewScrollOffset(max_scroll_offset());
|
| }
|
|
|
| -void InProcessViewRenderer::SetTotalRootLayerScrollOffset(
|
| +void BrowserViewRenderer::SetTotalRootLayerScrollOffset(
|
| gfx::Vector2dF scroll_offset_dip) {
|
| // TOOD(mkosiba): Add a DCHECK to say that this does _not_ get called during
|
| // DrawGl when http://crbug.com/249972 is fixed.
|
| @@ -767,7 +358,7 @@ void InProcessViewRenderer::SetTotalRootLayerScrollOffset(
|
| gfx::Vector2d max_offset = max_scroll_offset();
|
| gfx::Vector2d scroll_offset;
|
| // For an explanation as to why this is done this way see the comment in
|
| - // InProcessViewRenderer::ScrollTo.
|
| + // BrowserViewRenderer::ScrollTo.
|
| if (max_scroll_offset_dip_.x()) {
|
| scroll_offset.set_x((scroll_offset_dip.x() * max_offset.x()) /
|
| max_scroll_offset_dip_.x());
|
| @@ -788,15 +379,15 @@ void InProcessViewRenderer::SetTotalRootLayerScrollOffset(
|
| client_->ScrollContainerViewTo(scroll_offset);
|
| }
|
|
|
| -gfx::Vector2dF InProcessViewRenderer::GetTotalRootLayerScrollOffset() {
|
| +gfx::Vector2dF BrowserViewRenderer::GetTotalRootLayerScrollOffset() {
|
| return scroll_offset_dip_;
|
| }
|
|
|
| -bool InProcessViewRenderer::IsExternalFlingActive() const {
|
| +bool BrowserViewRenderer::IsExternalFlingActive() const {
|
| return client_->IsFlingActive();
|
| }
|
|
|
| -void InProcessViewRenderer::SetRootLayerPageScaleFactorAndLimits(
|
| +void BrowserViewRenderer::SetRootLayerPageScaleFactorAndLimits(
|
| float page_scale_factor,
|
| float min_page_scale_factor,
|
| float max_page_scale_factor) {
|
| @@ -806,15 +397,14 @@ void InProcessViewRenderer::SetRootLayerPageScaleFactorAndLimits(
|
| page_scale_factor, min_page_scale_factor, max_page_scale_factor);
|
| }
|
|
|
| -void InProcessViewRenderer::SetRootLayerScrollableSize(
|
| +void BrowserViewRenderer::SetRootLayerScrollableSize(
|
| gfx::SizeF scrollable_size) {
|
| client_->SetContentsSize(scrollable_size);
|
| }
|
|
|
| -void InProcessViewRenderer::DidOverscroll(
|
| - gfx::Vector2dF accumulated_overscroll,
|
| - gfx::Vector2dF latest_overscroll_delta,
|
| - gfx::Vector2dF current_fling_velocity) {
|
| +void BrowserViewRenderer::DidOverscroll(gfx::Vector2dF accumulated_overscroll,
|
| + gfx::Vector2dF latest_overscroll_delta,
|
| + gfx::Vector2dF current_fling_velocity) {
|
| const float physical_pixel_scale = dip_scale_ * page_scale_factor_;
|
| if (accumulated_overscroll == latest_overscroll_delta)
|
| overscroll_rounding_error_ = gfx::Vector2dF();
|
| @@ -827,7 +417,7 @@ void InProcessViewRenderer::DidOverscroll(
|
| client_->DidOverscroll(rounded_overscroll_delta);
|
| }
|
|
|
| -void InProcessViewRenderer::EnsureContinuousInvalidation(
|
| +void BrowserViewRenderer::EnsureContinuousInvalidation(
|
| AwDrawGLInfo* draw_info,
|
| bool invalidate_ignore_compositor) {
|
| // This method should be called again when any of these conditions change.
|
| @@ -863,7 +453,7 @@ void InProcessViewRenderer::EnsureContinuousInvalidation(
|
|
|
| // Unretained here is safe because the callback is cancelled when
|
| // |fallback_tick_| is destroyed.
|
| - fallback_tick_.Reset(base::Bind(&InProcessViewRenderer::FallbackTickFired,
|
| + fallback_tick_.Reset(base::Bind(&BrowserViewRenderer::FallbackTickFired,
|
| base::Unretained(this)));
|
|
|
| // No need to reschedule fallback tick if compositor does not need to be
|
| @@ -874,14 +464,13 @@ void InProcessViewRenderer::EnsureContinuousInvalidation(
|
| BrowserThread::UI,
|
| FROM_HERE,
|
| fallback_tick_.callback(),
|
| - base::TimeDelta::FromMilliseconds(
|
| - kFallbackTickTimeoutInMilliseconds));
|
| + base::TimeDelta::FromMilliseconds(kFallbackTickTimeoutInMilliseconds));
|
| }
|
| }
|
|
|
| -void InProcessViewRenderer::FallbackTickFired() {
|
| +void BrowserViewRenderer::FallbackTickFired() {
|
| TRACE_EVENT1("android_webview",
|
| - "InProcessViewRenderer::FallbackTickFired",
|
| + "BrowserViewRenderer::FallbackTickFired",
|
| "compositor_needs_continuous_invalidate_",
|
| compositor_needs_continuous_invalidate_);
|
|
|
| @@ -892,14 +481,14 @@ void InProcessViewRenderer::FallbackTickFired() {
|
| ForceFakeCompositeSW();
|
| }
|
|
|
| -void InProcessViewRenderer::ForceFakeCompositeSW() {
|
| +void BrowserViewRenderer::ForceFakeCompositeSW() {
|
| DCHECK(compositor_);
|
| SkBitmapDevice device(SkBitmap::kARGB_8888_Config, 1, 1);
|
| SkCanvas canvas(&device);
|
| CompositeSW(&canvas);
|
| }
|
|
|
| -bool InProcessViewRenderer::CompositeSW(SkCanvas* canvas) {
|
| +bool BrowserViewRenderer::CompositeSW(SkCanvas* canvas) {
|
| DCHECK(compositor_);
|
|
|
| fallback_tick_.Cancel();
|
| @@ -910,7 +499,7 @@ bool InProcessViewRenderer::CompositeSW(SkCanvas* canvas) {
|
| return result;
|
| }
|
|
|
| -std::string InProcessViewRenderer::ToString(AwDrawGLInfo* draw_info) const {
|
| +std::string BrowserViewRenderer::ToString(AwDrawGLInfo* draw_info) const {
|
| std::string str;
|
| base::StringAppendF(&str, "is_paused: %d ", is_paused_);
|
| base::StringAppendF(&str, "view_visible: %d ", view_visible_);
|
| @@ -923,8 +512,6 @@ std::string InProcessViewRenderer::ToString(AwDrawGLInfo* draw_info) const {
|
| base::StringAppendF(&str, "block_invalidates: %d ", block_invalidates_);
|
| base::StringAppendF(&str, "view width height: [%d %d] ", width_, height_);
|
| base::StringAppendF(&str, "attached_to_window: %d ", attached_to_window_);
|
| - base::StringAppendF(&str, "hardware_initialized: %d ", hardware_initialized_);
|
| - base::StringAppendF(&str, "hardware_failed: %d ", hardware_failed_);
|
| base::StringAppendF(&str,
|
| "global visible rect: %s ",
|
| cached_global_visible_rect_.ToString().c_str());
|
|
|