89554ac8e12aea4648a4aac5b2a84a8a74030056
[platform/framework/web/crosswalk.git] / src / android_webview / browser / shared_renderer_state.h
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.
4
5 #ifndef ANDROID_WEBVIEW_BROWSER_SHARED_RENDERER_STATE_H_
6 #define ANDROID_WEBVIEW_BROWSER_SHARED_RENDERER_STATE_H_
7
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"
15
16 namespace cc {
17 class CompositorFrameAck;
18 }
19
20 namespace gpu {
21 class GLInProcessContext;
22 }
23
24 namespace android_webview {
25
26 class BrowserViewRendererClient;
27
28 // Set by BrowserViewRenderer and read by HardwareRenderer.
29 struct DrawGLInput {
30   gfx::Vector2d scroll_offset;
31   int width;
32   int height;
33   cc::CompositorFrame frame;
34
35   DrawGLInput();
36   ~DrawGLInput();
37 };
38
39 // This class is used to pass data between UI thread and RenderThread.
40 class SharedRendererState {
41  public:
42   SharedRendererState(scoped_refptr<base::MessageLoopProxy> ui_loop,
43                       BrowserViewRendererClient* client);
44   ~SharedRendererState();
45
46   void ClientRequestDrawGL();
47
48   void SetDrawGLInput(scoped_ptr<DrawGLInput> input);
49   scoped_ptr<DrawGLInput> PassDrawGLInput();
50
51   // Set by UI and read by RT.
52   void SetHardwareAllowed(bool allowed);
53   bool IsHardwareAllowed() const;
54
55   void SetSharedContext(gpu::GLInProcessContext* context);
56   gpu::GLInProcessContext* GetSharedContext() const;
57
58   void InsertReturnedResources(const cc::ReturnedResourceArray& resources);
59   void SwapReturnedResources(cc::ReturnedResourceArray* resources);
60   bool ReturnedResourcesEmpty() const;
61
62  private:
63   void ClientRequestDrawGLOnUIThread();
64
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_;
69
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_;
76 };
77
78 }  // namespace android_webview
79
80 #endif  // ANDROID_WEBVIEW_BROWSER_SHARED_RENDERER_STATE_H_