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 #ifndef ANDROID_WEBVIEW_BROWSER_SHARED_RENDERER_STATE_H_
6 #define ANDROID_WEBVIEW_BROWSER_SHARED_RENDERER_STATE_H_
8 #include "base/memory/weak_ptr.h"
9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/synchronization/lock.h"
11 #include "cc/output/compositor_frame.h"
12 #include "cc/output/compositor_frame_ack.h"
13 #include "ui/gfx/geometry/rect.h"
14 #include "ui/gfx/geometry/vector2d.h"
17 class CompositorFrameAck
;
21 class GLInProcessContext
;
24 namespace android_webview
{
26 class BrowserViewRendererClient
;
28 // Set by BrowserViewRenderer and read by HardwareRenderer.
30 gfx::Vector2d scroll_offset
;
33 cc::CompositorFrame frame
;
39 // This class holds renderer state that is shared between UI and RT threads.
40 // Android framework will block the UI thread when RT is drawing, so no locking
41 // is needed in this class. In the interim, this class is also responsible for
42 // thread hopping that should eventually be removed once RT support work is
44 class SharedRendererState
{
46 SharedRendererState(scoped_refptr
<base::MessageLoopProxy
> ui_loop
,
47 BrowserViewRendererClient
* client
);
48 ~SharedRendererState();
50 void ClientRequestDrawGL();
52 void SetDrawGLInput(scoped_ptr
<DrawGLInput
> input
);
53 scoped_ptr
<DrawGLInput
> PassDrawGLInput();
55 // Set by UI and read by RT.
56 void SetHardwareAllowed(bool allowed
);
57 bool IsHardwareAllowed() const;
59 // Set by RT and read by UI.
60 void SetHardwareInitialized(bool initialized
);
61 bool IsHardwareInitialized() const;
63 void SetSharedContext(gpu::GLInProcessContext
* context
);
64 gpu::GLInProcessContext
* GetSharedContext() const;
66 void ReturnResources(const cc::TransferableResourceArray
& input
);
67 void InsertReturnedResources(const cc::ReturnedResourceArray
& resources
);
68 void SwapReturnedResources(cc::ReturnedResourceArray
* resources
);
69 bool ReturnedResourcesEmpty() const;
72 void ClientRequestDrawGLOnUIThread();
74 scoped_refptr
<base::MessageLoopProxy
> ui_loop_
;
75 // TODO(boliu): Remove |client_on_ui_| from shared state.
76 BrowserViewRendererClient
* client_on_ui_
;
77 base::WeakPtrFactory
<SharedRendererState
> weak_factory_on_ui_thread_
;
78 base::WeakPtr
<SharedRendererState
> ui_thread_weak_ptr_
;
80 // Accessed by both UI and RT thread.
81 mutable base::Lock lock_
;
82 scoped_ptr
<DrawGLInput
> draw_gl_input_
;
83 bool hardware_allowed_
;
84 bool hardware_initialized_
;
85 gpu::GLInProcessContext
* share_context_
;
86 cc::ReturnedResourceArray returned_resources_
;
89 } // namespace android_webview
91 #endif // ANDROID_WEBVIEW_BROWSER_SHARED_RENDERER_STATE_H_