OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_COMPOSITOR_IMPL_ANDROID_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_COMPOSITOR_IMPL_ANDROID_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_COMPOSITOR_IMPL_ANDROID_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_COMPOSITOR_IMPL_ANDROID_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/containers/scoped_ptr_hash_map.h" | 10 #include "base/containers/scoped_ptr_hash_map.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" |
12 #include "cc/resources/ui_resource_client.h" | 13 #include "cc/resources/ui_resource_client.h" |
13 #include "cc/trees/layer_tree_host_client.h" | 14 #include "cc/trees/layer_tree_host_client.h" |
14 #include "cc/trees/layer_tree_host_single_thread_client.h" | 15 #include "cc/trees/layer_tree_host_single_thread_client.h" |
15 #include "content/browser/renderer_host/image_transport_factory_android.h" | 16 #include "content/browser/renderer_host/image_transport_factory_android.h" |
16 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
17 #include "content/public/browser/android/compositor.h" | 18 #include "content/public/browser/android/compositor.h" |
18 #include "third_party/khronos/GLES2/gl2.h" | 19 #include "third_party/khronos/GLES2/gl2.h" |
19 #include "ui/base/android/window_android_compositor.h" | 20 #include "ui/base/android/window_android_compositor.h" |
20 | 21 |
21 class SkBitmap; | 22 class SkBitmap; |
(...skipping 24 matching lines...) Expand all Loading... |
46 | 47 |
47 static bool IsInitialized(); | 48 static bool IsInitialized(); |
48 | 49 |
49 // Creates a surface texture and returns a surface texture id. Returns -1 on | 50 // Creates a surface texture and returns a surface texture id. Returns -1 on |
50 // failure. | 51 // failure. |
51 static int CreateSurfaceTexture(int child_process_id); | 52 static int CreateSurfaceTexture(int child_process_id); |
52 | 53 |
53 // Destroy all surface textures associated with |child_process_id|. | 54 // Destroy all surface textures associated with |child_process_id|. |
54 static void DestroyAllSurfaceTextures(int child_process_id); | 55 static void DestroyAllSurfaceTextures(int child_process_id); |
55 | 56 |
| 57 private: |
56 // Compositor implementation. | 58 // Compositor implementation. |
57 virtual void SetRootLayer(scoped_refptr<cc::Layer> root) OVERRIDE; | 59 virtual void SetRootLayer(scoped_refptr<cc::Layer> root) OVERRIDE; |
58 virtual void SetWindowSurface(ANativeWindow* window) OVERRIDE; | 60 virtual void SetWindowSurface(ANativeWindow* window) OVERRIDE; |
59 virtual void SetSurface(jobject surface) OVERRIDE; | 61 virtual void SetSurface(jobject surface) OVERRIDE; |
60 virtual void SetVisible(bool visible) OVERRIDE; | 62 virtual void SetVisible(bool visible) OVERRIDE; |
61 virtual void setDeviceScaleFactor(float factor) OVERRIDE; | 63 virtual void setDeviceScaleFactor(float factor) OVERRIDE; |
62 virtual void SetWindowBounds(const gfx::Size& size) OVERRIDE; | 64 virtual void SetWindowBounds(const gfx::Size& size) OVERRIDE; |
63 virtual void SetHasTransparentBackground(bool flag) OVERRIDE; | 65 virtual void SetHasTransparentBackground(bool flag) OVERRIDE; |
64 virtual bool CompositeAndReadback( | 66 virtual bool CompositeAndReadback( |
65 void *pixels, const gfx::Rect& rect) OVERRIDE; | 67 void *pixels, const gfx::Rect& rect) OVERRIDE; |
66 virtual void Composite() OVERRIDE; | 68 virtual void SetNeedsComposite() OVERRIDE; |
67 virtual cc::UIResourceId GenerateUIResource(const SkBitmap& bitmap, | 69 virtual cc::UIResourceId GenerateUIResource(const SkBitmap& bitmap, |
68 bool is_transient) OVERRIDE; | 70 bool is_transient) OVERRIDE; |
69 virtual cc::UIResourceId GenerateCompressedUIResource(const gfx::Size& size, | 71 virtual cc::UIResourceId GenerateCompressedUIResource(const gfx::Size& size, |
70 void* pixels, | 72 void* pixels, |
71 bool is_transient) | 73 bool is_transient) |
72 OVERRIDE; | 74 OVERRIDE; |
73 virtual void DeleteUIResource(cc::UIResourceId resource_id) OVERRIDE; | 75 virtual void DeleteUIResource(cc::UIResourceId resource_id) OVERRIDE; |
74 | 76 |
75 // LayerTreeHostClient implementation. | 77 // LayerTreeHostClient implementation. |
76 virtual void WillBeginMainFrame(int frame_id) OVERRIDE {} | 78 virtual void WillBeginMainFrame(int frame_id) OVERRIDE {} |
77 virtual void DidBeginMainFrame() OVERRIDE {} | 79 virtual void DidBeginMainFrame() OVERRIDE {} |
78 virtual void Animate(base::TimeTicks frame_begin_time) OVERRIDE {} | 80 virtual void Animate(base::TimeTicks frame_begin_time) OVERRIDE {} |
79 virtual void Layout() OVERRIDE {} | 81 virtual void Layout() OVERRIDE; |
80 virtual void ApplyScrollAndScale(const gfx::Vector2d& scroll_delta, | 82 virtual void ApplyScrollAndScale(const gfx::Vector2d& scroll_delta, |
81 float page_scale) OVERRIDE {} | 83 float page_scale) OVERRIDE {} |
82 virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface(bool fallback) | 84 virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface(bool fallback) |
83 OVERRIDE; | 85 OVERRIDE; |
84 virtual void DidInitializeOutputSurface() OVERRIDE {} | 86 virtual void DidInitializeOutputSurface() OVERRIDE {} |
85 virtual void WillCommit() OVERRIDE {} | 87 virtual void WillCommit() OVERRIDE {} |
86 virtual void DidCommit() OVERRIDE; | 88 virtual void DidCommit() OVERRIDE; |
87 virtual void DidCommitAndDrawFrame() OVERRIDE {} | 89 virtual void DidCommitAndDrawFrame() OVERRIDE {} |
88 virtual void DidCompleteSwapBuffers() OVERRIDE; | 90 virtual void DidCompleteSwapBuffers() OVERRIDE; |
89 | 91 |
90 // LayerTreeHostSingleThreadClient implementation. | 92 // LayerTreeHostSingleThreadClient implementation. |
91 virtual void ScheduleComposite() OVERRIDE; | 93 virtual void ScheduleComposite() OVERRIDE; |
92 virtual void ScheduleAnimation() OVERRIDE; | 94 virtual void ScheduleAnimation() OVERRIDE; |
93 virtual void DidPostSwapBuffers() OVERRIDE; | 95 virtual void DidPostSwapBuffers() OVERRIDE; |
94 virtual void DidAbortSwapBuffers() OVERRIDE; | 96 virtual void DidAbortSwapBuffers() OVERRIDE; |
95 | 97 |
96 // ImageTransportFactoryAndroidObserver implementation. | 98 // ImageTransportFactoryAndroidObserver implementation. |
97 virtual void OnLostResources() OVERRIDE; | 99 virtual void OnLostResources() OVERRIDE; |
98 | 100 |
99 // WindowAndroidCompositor implementation. | 101 // WindowAndroidCompositor implementation. |
100 virtual void AttachLayerForReadback(scoped_refptr<cc::Layer> layer) OVERRIDE; | 102 virtual void AttachLayerForReadback(scoped_refptr<cc::Layer> layer) OVERRIDE; |
| 103 virtual void OnVSync(base::TimeTicks frame_time, |
| 104 base::TimeDelta vsync_period) OVERRIDE; |
101 | 105 |
102 private: | 106 void PostComposite(base::TimeDelta delay); |
| 107 enum CompositingTrigger { |
| 108 COMPOSITE_IMMEDIATELY, |
| 109 COMPOSITE_ON_VSYNC |
| 110 }; |
| 111 void Composite(CompositingTrigger trigger); |
103 cc::UIResourceId GenerateUIResourceFromUIResourceBitmap( | 112 cc::UIResourceId GenerateUIResourceFromUIResourceBitmap( |
104 const cc::UIResourceBitmap& bitmap, | 113 const cc::UIResourceBitmap& bitmap, |
105 bool is_transient); | 114 bool is_transient); |
106 | 115 |
107 scoped_refptr<cc::Layer> root_layer_; | 116 scoped_refptr<cc::Layer> root_layer_; |
108 scoped_ptr<cc::LayerTreeHost> host_; | 117 scoped_ptr<cc::LayerTreeHost> host_; |
109 | 118 |
110 gfx::Size size_; | 119 gfx::Size size_; |
111 bool has_transparent_background_; | 120 bool has_transparent_background_; |
112 float device_scale_factor_; | 121 float device_scale_factor_; |
113 | 122 |
114 ANativeWindow* window_; | 123 ANativeWindow* window_; |
115 int surface_id_; | 124 int surface_id_; |
116 | 125 |
117 CompositorClient* client_; | 126 CompositorClient* client_; |
118 | 127 |
119 typedef base::ScopedPtrHashMap<cc::UIResourceId, cc::UIResourceClient> | 128 typedef base::ScopedPtrHashMap<cc::UIResourceId, cc::UIResourceClient> |
120 UIResourceMap; | 129 UIResourceMap; |
121 UIResourceMap ui_resource_map_; | 130 UIResourceMap ui_resource_map_; |
122 | 131 |
123 gfx::NativeWindow root_window_; | 132 gfx::NativeWindow root_window_; |
124 | 133 |
| 134 // Used locally to track whether a call to LTH::Composite() did result in |
| 135 // a posted SwapBuffers(). |
| 136 bool did_post_swapbuffers_; |
| 137 |
| 138 // Used locally to inhibit ScheduleComposite() during Layout(). |
| 139 bool ignore_schedule_composite_; |
| 140 |
| 141 // Whether we need to composite in general because of any invalidation or |
| 142 // explicit request. |
| 143 bool needs_composite_; |
| 144 |
| 145 // When SetNeedsComposite() is getting called, we will try to schedule |
| 146 // regularly during vsync. |
| 147 bool should_composite_on_vsync_; |
| 148 |
| 149 // Whether we composited already in the current vsync interval. |
| 150 bool did_composite_this_frame_; |
| 151 |
| 152 // The number of SwapBuffer calls that have not returned and ACK'd from |
| 153 // the GPU thread. |
| 154 unsigned int pending_swapbuffers_; |
| 155 |
| 156 base::TimeDelta vsync_period_; |
| 157 |
| 158 base::WeakPtrFactory<CompositorImpl> weak_factory_; |
| 159 |
125 DISALLOW_COPY_AND_ASSIGN(CompositorImpl); | 160 DISALLOW_COPY_AND_ASSIGN(CompositorImpl); |
126 }; | 161 }; |
127 | 162 |
128 } // namespace content | 163 } // namespace content |
129 | 164 |
130 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITOR_IMPL_ANDROID_H_ | 165 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITOR_IMPL_ANDROID_H_ |
OLD | NEW |