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 is used to pass data between UI thread and RenderThread.
40 class SharedRendererState {
42 SharedRendererState(scoped_refptr<base::MessageLoopProxy> ui_loop,
43 BrowserViewRendererClient* client);
44 ~SharedRendererState();
46 void ClientRequestDrawGL();
48 void SetDrawGLInput(scoped_ptr<DrawGLInput> input);
49 scoped_ptr<DrawGLInput> PassDrawGLInput();
51 // Set by UI and read by RT.
52 void SetHardwareAllowed(bool allowed);
53 bool IsHardwareAllowed() const;
55 void SetSharedContext(gpu::GLInProcessContext* context);
56 gpu::GLInProcessContext* GetSharedContext() const;
58 void InsertReturnedResources(const cc::ReturnedResourceArray& resources);
59 void SwapReturnedResources(cc::ReturnedResourceArray* resources);
60 bool ReturnedResourcesEmpty() const;
63 void ClientRequestDrawGLOnUIThread();
65 scoped_refptr<base::MessageLoopProxy> ui_loop_;
66 BrowserViewRendererClient* client_on_ui_;
67 base::WeakPtrFactory<SharedRendererState> weak_factory_on_ui_thread_;
68 base::WeakPtr<SharedRendererState> ui_thread_weak_ptr_;
70 // Accessed by both UI and RT thread.
71 mutable base::Lock lock_;
72 scoped_ptr<DrawGLInput> draw_gl_input_;
73 bool hardware_allowed_;
74 gpu::GLInProcessContext* share_context_;
75 cc::ReturnedResourceArray returned_resources_;
78 } // namespace android_webview
80 #endif // ANDROID_WEBVIEW_BROWSER_SHARED_RENDERER_STATE_H_