aw: ReturnResource on draw and clean ups
[chromium-blink-merge.git] / android_webview / browser / shared_renderer_state.cc
blob8845b761cd252c16592d4480003288e53b07de09
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
3 // found in the LICENSE file.
5 #include "android_webview/browser/shared_renderer_state.h"
7 #include "android_webview/browser/browser_view_renderer_client.h"
8 #include "base/bind.h"
9 #include "base/location.h"
11 namespace android_webview {
13 DrawGLInput::DrawGLInput() : width(0), height(0) {
16 DrawGLInput::~DrawGLInput() {
19 SharedRendererState::SharedRendererState(
20 scoped_refptr<base::MessageLoopProxy> ui_loop,
21 BrowserViewRendererClient* client)
22 : ui_loop_(ui_loop),
23 client_on_ui_(client),
24 weak_factory_on_ui_thread_(this),
25 ui_thread_weak_ptr_(weak_factory_on_ui_thread_.GetWeakPtr()),
26 hardware_allowed_(false),
27 share_context_(NULL) {
28 DCHECK(ui_loop_->BelongsToCurrentThread());
29 DCHECK(client_on_ui_);
32 SharedRendererState::~SharedRendererState() {
33 DCHECK(ui_loop_->BelongsToCurrentThread());
36 void SharedRendererState::ClientRequestDrawGL() {
37 if (ui_loop_->BelongsToCurrentThread()) {
38 ClientRequestDrawGLOnUIThread();
39 } else {
40 ui_loop_->PostTask(
41 FROM_HERE,
42 base::Bind(&SharedRendererState::ClientRequestDrawGLOnUIThread,
43 ui_thread_weak_ptr_));
47 void SharedRendererState::ClientRequestDrawGLOnUIThread() {
48 DCHECK(ui_loop_->BelongsToCurrentThread());
49 if (!client_on_ui_->RequestDrawGL(NULL, false)) {
50 LOG(ERROR) << "Failed to request GL process. Deadlock likely";
54 void SharedRendererState::SetDrawGLInput(scoped_ptr<DrawGLInput> input) {
55 base::AutoLock lock(lock_);
56 DCHECK(!draw_gl_input_.get());
57 draw_gl_input_ = input.Pass();
60 scoped_ptr<DrawGLInput> SharedRendererState::PassDrawGLInput() {
61 base::AutoLock lock(lock_);
62 return draw_gl_input_.Pass();
65 void SharedRendererState::SetHardwareAllowed(bool allowed) {
66 base::AutoLock lock(lock_);
67 hardware_allowed_ = allowed;
70 bool SharedRendererState::IsHardwareAllowed() const {
71 base::AutoLock lock(lock_);
72 return hardware_allowed_;
75 void SharedRendererState::SetSharedContext(gpu::GLInProcessContext* context) {
76 base::AutoLock lock(lock_);
77 DCHECK(!share_context_ || !context);
78 share_context_ = context;
81 gpu::GLInProcessContext* SharedRendererState::GetSharedContext() const {
82 base::AutoLock lock(lock_);
83 DCHECK(share_context_);
84 return share_context_;
87 void SharedRendererState::InsertReturnedResources(
88 const cc::ReturnedResourceArray& resources) {
89 base::AutoLock lock(lock_);
90 returned_resources_.insert(
91 returned_resources_.end(), resources.begin(), resources.end());
94 void SharedRendererState::SwapReturnedResources(
95 cc::ReturnedResourceArray* resources) {
96 DCHECK(resources->empty());
97 base::AutoLock lock(lock_);
98 resources->swap(returned_resources_);
101 bool SharedRendererState::ReturnedResourcesEmpty() const {
102 base::AutoLock lock(lock_);
103 return returned_resources_.empty();
106 } // namespace android_webview