• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "android_webview/browser/parent_compositor_draw_constraints.h"
9 #include "base/cancelable_callback.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/message_loop/message_loop_proxy.h"
12 #include "base/synchronization/lock.h"
13 #include "cc/output/compositor_frame.h"
14 #include "cc/output/compositor_frame_ack.h"
15 #include "ui/gfx/geometry/rect.h"
16 #include "ui/gfx/geometry/vector2d.h"
17 
18 namespace android_webview {
19 
20 namespace internal {
21 class RequestDrawGLTracker;
22 }
23 
24 class BrowserViewRendererClient;
25 class InsideHardwareReleaseReset;
26 
27 // This class is used to pass data between UI thread and RenderThread.
28 class SharedRendererState {
29  public:
30   SharedRendererState(scoped_refptr<base::MessageLoopProxy> ui_loop,
31                       BrowserViewRendererClient* client);
32   ~SharedRendererState();
33 
34   void ClientRequestDrawGL();
35   void DidDrawGLProcess();
36 
37   void SetScrollOffset(gfx::Vector2d scroll_offset);
38   gfx::Vector2d GetScrollOffset();
39 
40   bool HasCompositorFrame() const;
41   void SetCompositorFrame(scoped_ptr<cc::CompositorFrame> frame,
42                           bool force_commit);
43   scoped_ptr<cc::CompositorFrame> PassCompositorFrame();
44   bool ForceCommit() const;
45 
46   bool IsInsideHardwareRelease() const;
47   // Returns true if the draw constraints are updated.
48   bool UpdateDrawConstraints(
49       const ParentCompositorDrawConstraints& parent_draw_constraints);
50   void PostExternalDrawConstraintsToChildCompositor(
51       const ParentCompositorDrawConstraints& parent_draw_constraints);
52   void DidSkipCommitFrame();
53 
54   const ParentCompositorDrawConstraints ParentDrawConstraints() const;
55 
56   void SetForceInvalidateOnNextDrawGL(
57       bool needs_force_invalidate_on_next_draw_gl);
58   bool NeedsForceInvalidateOnNextDrawGL() const;
59 
60   void InsertReturnedResources(const cc::ReturnedResourceArray& resources);
61   void SwapReturnedResources(cc::ReturnedResourceArray* resources);
62   bool ReturnedResourcesEmpty() const;
63 
64  private:
65   friend class InsideHardwareReleaseReset;
66   friend class internal::RequestDrawGLTracker;
67 
68   void ResetRequestDrawGLCallback();
69   void ClientRequestDrawGLOnUIThread();
70   void UpdateParentDrawConstraintsOnUIThread();
71   void DidSkipCommitFrameOnUIThread();
72   void SetInsideHardwareRelease(bool inside);
73 
74   scoped_refptr<base::MessageLoopProxy> ui_loop_;
75   BrowserViewRendererClient* client_on_ui_;
76   base::WeakPtr<SharedRendererState> ui_thread_weak_ptr_;
77   base::CancelableClosure request_draw_gl_cancelable_closure_;
78 
79   // Accessed by both UI and RT thread.
80   mutable base::Lock lock_;
81   gfx::Vector2d scroll_offset_;
82   scoped_ptr<cc::CompositorFrame> compositor_frame_;
83   bool force_commit_;
84   bool inside_hardware_release_;
85   bool needs_force_invalidate_on_next_draw_gl_;
86   ParentCompositorDrawConstraints parent_draw_constraints_;
87   cc::ReturnedResourceArray returned_resources_;
88   base::Closure request_draw_gl_closure_;
89 
90   base::WeakPtrFactory<SharedRendererState> weak_factory_on_ui_thread_;
91 
92   DISALLOW_COPY_AND_ASSIGN(SharedRendererState);
93 };
94 
95 class InsideHardwareReleaseReset {
96  public:
97   explicit InsideHardwareReleaseReset(
98       SharedRendererState* shared_renderer_state);
99   ~InsideHardwareReleaseReset();
100 
101  private:
102   SharedRendererState* shared_renderer_state_;
103 
104   DISALLOW_COPY_AND_ASSIGN(InsideHardwareReleaseReset);
105 };
106 
107 }  // namespace android_webview
108 
109 #endif  // ANDROID_WEBVIEW_BROWSER_SHARED_RENDERER_STATE_H_
110