Add default implementations for AppWindowRegistry::Observer notifications.
[chromium-blink-merge.git] / android_webview / browser / shared_renderer_state.cc
blob3483d630e7cb1eafbc02f812d0998902487aae1c
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() : frame_id(0), width(0), height(0) {}
15 DrawGLResult::DrawGLResult() : frame_id(0), clip_contains_visible_rect(false) {}
17 SharedRendererState::SharedRendererState(
18 scoped_refptr<base::MessageLoopProxy> ui_loop,
19 BrowserViewRendererClient* client)
20 : ui_loop_(ui_loop),
21 client_on_ui_(client),
22 weak_factory_on_ui_thread_(this),
23 ui_thread_weak_ptr_(weak_factory_on_ui_thread_.GetWeakPtr()),
24 compositor_(NULL),
25 memory_policy_dirty_(false),
26 hardware_initialized_(false) {
27 DCHECK(ui_loop_->BelongsToCurrentThread());
28 DCHECK(client_on_ui_);
31 SharedRendererState::~SharedRendererState() {}
33 void SharedRendererState::ClientRequestDrawGL() {
34 if (ui_loop_->BelongsToCurrentThread()) {
35 ClientRequestDrawGLOnUIThread();
36 } else {
37 ui_loop_->PostTask(
38 FROM_HERE,
39 base::Bind(&SharedRendererState::ClientRequestDrawGLOnUIThread,
40 ui_thread_weak_ptr_));
44 void SharedRendererState::ClientRequestDrawGLOnUIThread() {
45 DCHECK(ui_loop_->BelongsToCurrentThread());
46 if (!client_on_ui_->RequestDrawGL(NULL, false)) {
47 LOG(ERROR) << "Failed to request GL process. Deadlock likely";
51 void SharedRendererState::SetCompositorOnUiThread(
52 content::SynchronousCompositor* compositor) {
53 base::AutoLock lock(lock_);
54 DCHECK(ui_loop_->BelongsToCurrentThread());
55 compositor_ = compositor;
58 content::SynchronousCompositor* SharedRendererState::GetCompositor() {
59 base::AutoLock lock(lock_);
60 DCHECK(compositor_);
61 return compositor_;
64 void SharedRendererState::SetMemoryPolicy(
65 const content::SynchronousCompositorMemoryPolicy new_policy) {
66 base::AutoLock lock(lock_);
67 if (memory_policy_ != new_policy) {
68 memory_policy_ = new_policy;
69 memory_policy_dirty_ = true;
73 content::SynchronousCompositorMemoryPolicy
74 SharedRendererState::GetMemoryPolicy() const {
75 base::AutoLock lock(lock_);
76 return memory_policy_;
79 void SharedRendererState::SetDrawGLInput(const DrawGLInput& input) {
80 base::AutoLock lock(lock_);
81 draw_gl_input_ = input;
84 DrawGLInput SharedRendererState::GetDrawGLInput() const {
85 base::AutoLock lock(lock_);
86 return draw_gl_input_;
89 void SharedRendererState::ClearClosureQueue() {
90 base::AutoLock lock(lock_);
91 std::queue<base::Closure> empty;
92 std::swap(closure_queue_, empty);
95 void SharedRendererState::AppendClosure(const base::Closure& closure) {
96 base::AutoLock lock(lock_);
97 closure_queue_.push(closure);
100 base::Closure SharedRendererState::PopFrontClosure() {
101 base::Closure closure;
103 base::AutoLock lock(lock_);
104 if (!closure_queue_.empty()) {
105 closure = closure_queue_.front();
106 closure_queue_.pop();
109 return closure;
112 void SharedRendererState::SetHardwareInitialized(bool initialized) {
113 base::AutoLock lock(lock_);
114 hardware_initialized_ = initialized;
117 bool SharedRendererState::IsHardwareInitialized() const {
118 base::AutoLock lock(lock_);
119 return hardware_initialized_;
122 void SharedRendererState::SetMemoryPolicyDirty(bool is_dirty) {
123 base::AutoLock lock(lock_);
124 memory_policy_dirty_ = is_dirty;
127 bool SharedRendererState::IsMemoryPolicyDirty() const {
128 base::AutoLock lock(lock_);
129 return memory_policy_dirty_;
132 } // namespace android_webview