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 #include "content/browser/renderer_host/render_widget_host_view_android.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
6 | 6 |
7 #include <android/bitmap.h> | 7 #include <android/bitmap.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "cc/output/copy_output_request.h" | 27 #include "cc/output/copy_output_request.h" |
28 #include "cc/output/copy_output_result.h" | 28 #include "cc/output/copy_output_result.h" |
29 #include "cc/output/latency_info_swap_promise.h" | 29 #include "cc/output/latency_info_swap_promise.h" |
30 #include "cc/output/viewport_selection_bound.h" | 30 #include "cc/output/viewport_selection_bound.h" |
31 #include "cc/resources/single_release_callback.h" | 31 #include "cc/resources/single_release_callback.h" |
32 #include "cc/surfaces/surface.h" | 32 #include "cc/surfaces/surface.h" |
33 #include "cc/surfaces/surface_factory.h" | 33 #include "cc/surfaces/surface_factory.h" |
34 #include "cc/surfaces/surface_id_allocator.h" | 34 #include "cc/surfaces/surface_id_allocator.h" |
35 #include "cc/surfaces/surface_manager.h" | 35 #include "cc/surfaces/surface_manager.h" |
36 #include "cc/trees/layer_tree_host.h" | 36 #include "cc/trees/layer_tree_host.h" |
37 #include "components/display_compositor/gl_helper.h" | |
38 #include "content/browser/accessibility/browser_accessibility_manager_android.h" | 37 #include "content/browser/accessibility/browser_accessibility_manager_android.h" |
39 #include "content/browser/android/composited_touch_handle_drawable.h" | 38 #include "content/browser/android/composited_touch_handle_drawable.h" |
40 #include "content/browser/android/content_view_core_impl.h" | 39 #include "content/browser/android/content_view_core_impl.h" |
41 #include "content/browser/android/overscroll_controller_android.h" | 40 #include "content/browser/android/overscroll_controller_android.h" |
42 #include "content/browser/android/popup_touch_handle_drawable.h" | 41 #include "content/browser/android/popup_touch_handle_drawable.h" |
43 #include "content/browser/android/synchronous_compositor_base.h" | 42 #include "content/browser/android/synchronous_compositor_base.h" |
| 43 #include "content/browser/compositor/gl_helper.h" |
44 #include "content/browser/devtools/render_frame_devtools_agent_host.h" | 44 #include "content/browser/devtools/render_frame_devtools_agent_host.h" |
45 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | 45 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
46 #include "content/browser/gpu/compositor_util.h" | 46 #include "content/browser/gpu/compositor_util.h" |
47 #include "content/browser/gpu/gpu_data_manager_impl.h" | 47 #include "content/browser/gpu/gpu_data_manager_impl.h" |
48 #include "content/browser/gpu/gpu_process_host_ui_shim.h" | 48 #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
49 #include "content/browser/media/android/media_web_contents_observer_android.h" | 49 #include "content/browser/media/android/media_web_contents_observer_android.h" |
50 #include "content/browser/renderer_host/compositor_impl_android.h" | 50 #include "content/browser/renderer_host/compositor_impl_android.h" |
51 #include "content/browser/renderer_host/dip_util.h" | 51 #include "content/browser/renderer_host/dip_util.h" |
52 #include "content/browser/renderer_host/frame_metadata_util.h" | 52 #include "content/browser/renderer_host/frame_metadata_util.h" |
53 #include "content/browser/renderer_host/input/synthetic_gesture_target_android.h
" | 53 #include "content/browser/renderer_host/input/synthetic_gesture_target_android.h
" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 } | 115 } |
116 | 116 |
117 const int kUndefinedOutputSurfaceId = -1; | 117 const int kUndefinedOutputSurfaceId = -1; |
118 | 118 |
119 static const char kAsyncReadBackString[] = "Compositing.CopyFromSurfaceTime"; | 119 static const char kAsyncReadBackString[] = "Compositing.CopyFromSurfaceTime"; |
120 | 120 |
121 class GLHelperHolder { | 121 class GLHelperHolder { |
122 public: | 122 public: |
123 static GLHelperHolder* Create(); | 123 static GLHelperHolder* Create(); |
124 | 124 |
125 display_compositor::GLHelper* gl_helper() { return gl_helper_.get(); } | 125 GLHelper* gl_helper() { return gl_helper_.get(); } |
126 bool IsLost() { | 126 bool IsLost() { |
127 if (!gl_helper_) | 127 if (!gl_helper_) |
128 return true; | 128 return true; |
129 return provider_->ContextGL()->GetGraphicsResetStatusKHR() != GL_NO_ERROR; | 129 return provider_->ContextGL()->GetGraphicsResetStatusKHR() != GL_NO_ERROR; |
130 } | 130 } |
131 | 131 |
132 private: | 132 private: |
133 GLHelperHolder() = default; | 133 GLHelperHolder() = default; |
134 void Initialize(); | 134 void Initialize(); |
135 void OnContextLost(); | 135 void OnContextLost(); |
136 | 136 |
137 scoped_refptr<ContextProviderCommandBuffer> provider_; | 137 scoped_refptr<ContextProviderCommandBuffer> provider_; |
138 std::unique_ptr<display_compositor::GLHelper> gl_helper_; | 138 std::unique_ptr<GLHelper> gl_helper_; |
139 | 139 |
140 DISALLOW_COPY_AND_ASSIGN(GLHelperHolder); | 140 DISALLOW_COPY_AND_ASSIGN(GLHelperHolder); |
141 }; | 141 }; |
142 | 142 |
143 GLHelperHolder* GLHelperHolder::Create() { | 143 GLHelperHolder* GLHelperHolder::Create() { |
144 GLHelperHolder* holder = new GLHelperHolder; | 144 GLHelperHolder* holder = new GLHelperHolder; |
145 holder->Initialize(); | 145 holder->Initialize(); |
146 return holder; | 146 return holder; |
147 } | 147 } |
148 | 148 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 provider_ = new ContextProviderCommandBuffer( | 193 provider_ = new ContextProviderCommandBuffer( |
194 std::move(context), BROWSER_OFFSCREEN_MAINTHREAD_CONTEXT); | 194 std::move(context), BROWSER_OFFSCREEN_MAINTHREAD_CONTEXT); |
195 if (!provider_->BindToCurrentThread()) | 195 if (!provider_->BindToCurrentThread()) |
196 return; | 196 return; |
197 provider_->ContextGL()->TraceBeginCHROMIUM( | 197 provider_->ContextGL()->TraceBeginCHROMIUM( |
198 "gpu_toplevel", | 198 "gpu_toplevel", |
199 base::StringPrintf("CmdBufferImageTransportFactory-%p", provider_.get()) | 199 base::StringPrintf("CmdBufferImageTransportFactory-%p", provider_.get()) |
200 .c_str()); | 200 .c_str()); |
201 provider_->SetLostContextCallback( | 201 provider_->SetLostContextCallback( |
202 base::Bind(&GLHelperHolder::OnContextLost, base::Unretained(this))); | 202 base::Bind(&GLHelperHolder::OnContextLost, base::Unretained(this))); |
203 gl_helper_.reset(new display_compositor::GLHelper( | 203 gl_helper_.reset( |
204 provider_->ContextGL(), provider_->ContextSupport())); | 204 new GLHelper(provider_->ContextGL(), provider_->ContextSupport())); |
205 } | 205 } |
206 | 206 |
207 void GLHelperHolder::OnContextLost() { | 207 void GLHelperHolder::OnContextLost() { |
208 // Need to post a task because the command buffer client cannot be deleted | 208 // Need to post a task because the command buffer client cannot be deleted |
209 // from within this callback. | 209 // from within this callback. |
210 base::MessageLoop::current()->PostTask( | 210 base::MessageLoop::current()->PostTask( |
211 FROM_HERE, base::Bind(&RenderWidgetHostViewAndroid::OnContextLost)); | 211 FROM_HERE, base::Bind(&RenderWidgetHostViewAndroid::OnContextLost)); |
212 } | 212 } |
213 | 213 |
214 // This can only be used for readback postprocessing. It may return null if the | 214 // This can only be used for readback postprocessing. It may return null if the |
215 // channel was lost and not reestablished yet. | 215 // channel was lost and not reestablished yet. |
216 display_compositor::GLHelper* GetPostReadbackGLHelper() { | 216 GLHelper* GetPostReadbackGLHelper() { |
217 static GLHelperHolder* g_readback_helper_holder = nullptr; | 217 static GLHelperHolder* g_readback_helper_holder = nullptr; |
218 | 218 |
219 if (g_readback_helper_holder && g_readback_helper_holder->IsLost()) { | 219 if (g_readback_helper_holder && g_readback_helper_holder->IsLost()) { |
220 delete g_readback_helper_holder; | 220 delete g_readback_helper_holder; |
221 g_readback_helper_holder = nullptr; | 221 g_readback_helper_holder = nullptr; |
222 } | 222 } |
223 | 223 |
224 if (!g_readback_helper_holder) | 224 if (!g_readback_helper_holder) |
225 g_readback_helper_holder = GLHelperHolder::Create(); | 225 g_readback_helper_holder = GLHelperHolder::Create(); |
226 | 226 |
227 return g_readback_helper_holder->gl_helper(); | 227 return g_readback_helper_holder->gl_helper(); |
228 } | 228 } |
229 | 229 |
230 void CopyFromCompositingSurfaceFinished( | 230 void CopyFromCompositingSurfaceFinished( |
231 const ReadbackRequestCallback& callback, | 231 const ReadbackRequestCallback& callback, |
232 std::unique_ptr<cc::SingleReleaseCallback> release_callback, | 232 std::unique_ptr<cc::SingleReleaseCallback> release_callback, |
233 std::unique_ptr<SkBitmap> bitmap, | 233 std::unique_ptr<SkBitmap> bitmap, |
234 const base::TimeTicks& start_time, | 234 const base::TimeTicks& start_time, |
235 std::unique_ptr<SkAutoLockPixels> bitmap_pixels_lock, | 235 std::unique_ptr<SkAutoLockPixels> bitmap_pixels_lock, |
236 bool result) { | 236 bool result) { |
237 TRACE_EVENT0( | 237 TRACE_EVENT0( |
238 "cc", "RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceFinished"); | 238 "cc", "RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceFinished"); |
239 bitmap_pixels_lock.reset(); | 239 bitmap_pixels_lock.reset(); |
240 gpu::SyncToken sync_token; | 240 gpu::SyncToken sync_token; |
241 if (result) { | 241 if (result) { |
242 display_compositor::GLHelper* gl_helper = GetPostReadbackGLHelper(); | 242 GLHelper* gl_helper = GetPostReadbackGLHelper(); |
243 if (gl_helper) | 243 if (gl_helper) |
244 gl_helper->GenerateSyncToken(&sync_token); | 244 gl_helper->GenerateSyncToken(&sync_token); |
245 } | 245 } |
246 const bool lost_resource = !sync_token.HasData(); | 246 const bool lost_resource = !sync_token.HasData(); |
247 release_callback->Run(sync_token, lost_resource); | 247 release_callback->Run(sync_token, lost_resource); |
248 UMA_HISTOGRAM_TIMES(kAsyncReadBackString, | 248 UMA_HISTOGRAM_TIMES(kAsyncReadBackString, |
249 base::TimeTicks::Now() - start_time); | 249 base::TimeTicks::Now() - start_time); |
250 ReadbackResponse response = result ? READBACK_SUCCESS : READBACK_FAILED; | 250 ReadbackResponse response = result ? READBACK_SUCCESS : READBACK_FAILED; |
251 callback.Run(*bitmap, response); | 251 callback.Run(*bitmap, response); |
252 } | 252 } |
(...skipping 1683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1936 | 1936 |
1937 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) | 1937 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) |
1938 return; | 1938 return; |
1939 | 1939 |
1940 gfx::Size output_size_in_pixel; | 1940 gfx::Size output_size_in_pixel; |
1941 if (dst_size_in_pixel.IsEmpty()) | 1941 if (dst_size_in_pixel.IsEmpty()) |
1942 output_size_in_pixel = result->size(); | 1942 output_size_in_pixel = result->size(); |
1943 else | 1943 else |
1944 output_size_in_pixel = dst_size_in_pixel; | 1944 output_size_in_pixel = dst_size_in_pixel; |
1945 | 1945 |
1946 display_compositor::GLHelper* gl_helper = GetPostReadbackGLHelper(); | 1946 GLHelper* gl_helper = GetPostReadbackGLHelper(); |
1947 if (!gl_helper) | 1947 if (!gl_helper) |
1948 return; | 1948 return; |
1949 if (!gl_helper->IsReadbackConfigSupported(color_type)) | 1949 if (!gl_helper->IsReadbackConfigSupported(color_type)) |
1950 color_type = kRGBA_8888_SkColorType; | 1950 color_type = kRGBA_8888_SkColorType; |
1951 std::unique_ptr<SkBitmap> bitmap(new SkBitmap); | 1951 std::unique_ptr<SkBitmap> bitmap(new SkBitmap); |
1952 if (!bitmap->tryAllocPixels(SkImageInfo::Make(output_size_in_pixel.width(), | 1952 if (!bitmap->tryAllocPixels(SkImageInfo::Make(output_size_in_pixel.width(), |
1953 output_size_in_pixel.height(), | 1953 output_size_in_pixel.height(), |
1954 color_type, | 1954 color_type, |
1955 kOpaque_SkAlphaType))) { | 1955 kOpaque_SkAlphaType))) { |
1956 scoped_callback_runner.Reset( | 1956 scoped_callback_runner.Reset( |
(...skipping 13 matching lines...) Expand all Loading... |
1970 return; | 1970 return; |
1971 | 1971 |
1972 ignore_result(scoped_callback_runner.Release()); | 1972 ignore_result(scoped_callback_runner.Release()); |
1973 | 1973 |
1974 gl_helper->CropScaleReadbackAndCleanMailbox( | 1974 gl_helper->CropScaleReadbackAndCleanMailbox( |
1975 texture_mailbox.mailbox(), texture_mailbox.sync_token(), result->size(), | 1975 texture_mailbox.mailbox(), texture_mailbox.sync_token(), result->size(), |
1976 gfx::Rect(result->size()), output_size_in_pixel, pixels, color_type, | 1976 gfx::Rect(result->size()), output_size_in_pixel, pixels, color_type, |
1977 base::Bind(&CopyFromCompositingSurfaceFinished, callback, | 1977 base::Bind(&CopyFromCompositingSurfaceFinished, callback, |
1978 base::Passed(&release_callback), base::Passed(&bitmap), | 1978 base::Passed(&release_callback), base::Passed(&bitmap), |
1979 start_time, base::Passed(&bitmap_pixels_lock)), | 1979 start_time, base::Passed(&bitmap_pixels_lock)), |
1980 display_compositor::GLHelper::SCALER_QUALITY_GOOD); | 1980 GLHelper::SCALER_QUALITY_GOOD); |
1981 } | 1981 } |
1982 | 1982 |
1983 void RenderWidgetHostViewAndroid::OnStylusSelectBegin(float x0, | 1983 void RenderWidgetHostViewAndroid::OnStylusSelectBegin(float x0, |
1984 float y0, | 1984 float y0, |
1985 float x1, | 1985 float x1, |
1986 float y1) { | 1986 float y1) { |
1987 SelectBetweenCoordinates(gfx::PointF(x0, y0), gfx::PointF(x1, y1)); | 1987 SelectBetweenCoordinates(gfx::PointF(x0, y0), gfx::PointF(x1, y1)); |
1988 } | 1988 } |
1989 | 1989 |
1990 void RenderWidgetHostViewAndroid::OnStylusSelectUpdate(float x, float y) { | 1990 void RenderWidgetHostViewAndroid::OnStylusSelectUpdate(float x, float y) { |
(...skipping 27 matching lines...) Expand all Loading... |
2018 results->orientationAngle = display.RotationAsDegree(); | 2018 results->orientationAngle = display.RotationAsDegree(); |
2019 results->orientationType = | 2019 results->orientationType = |
2020 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); | 2020 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); |
2021 gfx::DeviceDisplayInfo info; | 2021 gfx::DeviceDisplayInfo info; |
2022 results->depth = info.GetBitsPerPixel(); | 2022 results->depth = info.GetBitsPerPixel(); |
2023 results->depthPerComponent = info.GetBitsPerComponent(); | 2023 results->depthPerComponent = info.GetBitsPerComponent(); |
2024 results->isMonochrome = (results->depthPerComponent == 0); | 2024 results->isMonochrome = (results->depthPerComponent == 0); |
2025 } | 2025 } |
2026 | 2026 |
2027 } // namespace content | 2027 } // namespace content |
OLD | NEW |