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"
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
)
21 client_on_ui_(client
),
22 weak_factory_on_ui_thread_(this),
23 ui_thread_weak_ptr_(weak_factory_on_ui_thread_
.GetWeakPtr()),
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();
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_
);
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();
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