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 "base/android/build_info.h" | 9 #include "base/android/build_info.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 static const char kAsyncReadBackString[] = "Compositing.CopyFromSurfaceTime"; | 117 static const char kAsyncReadBackString[] = "Compositing.CopyFromSurfaceTime"; |
118 | 118 |
119 // Sends an acknowledgement to the renderer of a processed IME event. | 119 // Sends an acknowledgement to the renderer of a processed IME event. |
120 void SendImeEventAck(RenderWidgetHostImpl* host) { | 120 void SendImeEventAck(RenderWidgetHostImpl* host) { |
121 host->Send(new ViewMsg_ImeEventAck(host->GetRoutingID())); | 121 host->Send(new ViewMsg_ImeEventAck(host->GetRoutingID())); |
122 } | 122 } |
123 | 123 |
124 class GLHelperHolder | 124 class GLHelperHolder |
125 : public blink::WebGraphicsContext3D::WebGraphicsContextLostCallback { | 125 : public blink::WebGraphicsContext3D::WebGraphicsContextLostCallback { |
126 public: | 126 public: |
127 static GLHelperHolder* Create(); | 127 static GLHelperHolder* Create(gfx::NativeWindow nativeWindow); |
128 ~GLHelperHolder() override; | 128 ~GLHelperHolder() override; |
129 | 129 |
130 void Initialize(); | 130 void Initialize(gfx::NativeWindow nativeWindow); |
131 | 131 |
132 // WebGraphicsContextLostCallback implementation. | 132 // WebGraphicsContextLostCallback implementation. |
133 void onContextLost() override; | 133 void onContextLost() override; |
134 | 134 |
135 GLHelper* GetGLHelper() { return gl_helper_.get(); } | 135 GLHelper* GetGLHelper() { return gl_helper_.get(); } |
136 bool IsLost() { return !context_.get() || context_->isContextLost(); } | 136 bool IsLost() { return !context_.get() || context_->isContextLost(); } |
137 | 137 |
138 private: | 138 private: |
139 GLHelperHolder(); | 139 GLHelperHolder(); |
140 static scoped_ptr<WebGraphicsContext3DCommandBufferImpl> CreateContext3D(); | 140 static scoped_ptr<WebGraphicsContext3DCommandBufferImpl> |
141 CreateContext3D(gfx::NativeWindow nativeWindow); | |
141 | 142 |
142 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context_; | 143 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context_; |
143 scoped_ptr<GLHelper> gl_helper_; | 144 scoped_ptr<GLHelper> gl_helper_; |
144 | 145 |
145 DISALLOW_COPY_AND_ASSIGN(GLHelperHolder); | 146 DISALLOW_COPY_AND_ASSIGN(GLHelperHolder); |
146 }; | 147 }; |
147 | 148 |
148 GLHelperHolder* GLHelperHolder::Create() { | 149 GLHelperHolder* GLHelperHolder::Create(gfx::NativeWindow nativeWindow) { |
149 GLHelperHolder* holder = new GLHelperHolder; | 150 GLHelperHolder* holder = new GLHelperHolder; |
150 holder->Initialize(); | 151 holder->Initialize(nativeWindow); |
151 | 152 |
152 return holder; | 153 return holder; |
153 } | 154 } |
154 | 155 |
155 GLHelperHolder::GLHelperHolder() { | 156 GLHelperHolder::GLHelperHolder() { |
156 } | 157 } |
157 | 158 |
158 GLHelperHolder::~GLHelperHolder() { | 159 GLHelperHolder::~GLHelperHolder() { |
159 } | 160 } |
160 | 161 |
161 void GLHelperHolder::Initialize() { | 162 void GLHelperHolder::Initialize(gfx::NativeWindow nativeWindow) { |
162 context_ = CreateContext3D(); | 163 context_ = CreateContext3D(nativeWindow); |
163 if (context_) { | 164 if (context_) { |
164 context_->setContextLostCallback(this); | 165 context_->setContextLostCallback(this); |
165 gl_helper_.reset(new GLHelper(context_->GetImplementation(), | 166 gl_helper_.reset(new GLHelper(context_->GetImplementation(), |
166 context_->GetContextSupport())); | 167 context_->GetContextSupport())); |
167 } | 168 } |
168 } | 169 } |
169 | 170 |
170 void GLHelperHolder::onContextLost() { | 171 void GLHelperHolder::onContextLost() { |
171 // Need to post a task because the command buffer client cannot be deleted | 172 // Need to post a task because the command buffer client cannot be deleted |
172 // from within this callback. | 173 // from within this callback. |
173 LOG(ERROR) << "Context lost."; | 174 LOG(ERROR) << "Context lost."; |
174 base::MessageLoop::current()->PostTask( | 175 base::MessageLoop::current()->PostTask( |
175 FROM_HERE, | 176 FROM_HERE, |
176 base::Bind(&RenderWidgetHostViewAndroid::OnContextLost)); | 177 base::Bind(&RenderWidgetHostViewAndroid::OnContextLost)); |
177 } | 178 } |
178 | 179 |
179 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> | 180 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> |
180 GLHelperHolder::CreateContext3D() { | 181 GLHelperHolder::CreateContext3D(gfx::NativeWindow nativeWindow) { |
181 BrowserGpuChannelHostFactory* factory = | 182 BrowserGpuChannelHostFactory* factory = |
182 BrowserGpuChannelHostFactory::instance(); | 183 BrowserGpuChannelHostFactory::instance(); |
183 scoped_refptr<GpuChannelHost> gpu_channel_host(factory->GetGpuChannel()); | 184 scoped_refptr<GpuChannelHost> gpu_channel_host(factory->GetGpuChannel()); |
184 // GLHelper can only be used in asynchronous APIs for postprocessing after | 185 // GLHelper can only be used in asynchronous APIs for postprocessing after |
185 // Browser Compositor operations (i.e. readback). | 186 // Browser Compositor operations (i.e. readback). |
186 if (!gpu_channel_host.get()) { | 187 if (!gpu_channel_host.get()) { |
187 // The Browser Compositor is in charge of reestablishing the channel. | 188 // The Browser Compositor is in charge of reestablishing the channel. |
188 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); | 189 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); |
189 } | 190 } |
190 | 191 |
191 blink::WebGraphicsContext3D::Attributes attrs; | 192 blink::WebGraphicsContext3D::Attributes attrs; |
192 attrs.shareResources = true; | 193 attrs.shareResources = true; |
193 GURL url("chrome://gpu/RenderWidgetHostViewAndroid"); | 194 GURL url("chrome://gpu/RenderWidgetHostViewAndroid"); |
194 static const size_t kBytesPerPixel = 4; | 195 static const size_t kBytesPerPixel = 4; |
195 gfx::DeviceDisplayInfo display_info; | 196 gfx::DeviceDisplayInfo display_info(nativeWindow->GetJavaObject().obj()); |
196 size_t full_screen_texture_size_in_bytes = display_info.GetDisplayHeight() * | 197 size_t full_screen_texture_size_in_bytes = display_info.GetDisplayHeight() * |
197 display_info.GetDisplayWidth() * | 198 display_info.GetDisplayWidth() * |
198 kBytesPerPixel; | 199 kBytesPerPixel; |
199 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits; | 200 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits; |
200 limits.command_buffer_size = 64 * 1024; | 201 limits.command_buffer_size = 64 * 1024; |
201 limits.start_transfer_buffer_size = 64 * 1024; | 202 limits.start_transfer_buffer_size = 64 * 1024; |
202 limits.min_transfer_buffer_size = 64 * 1024; | 203 limits.min_transfer_buffer_size = 64 * 1024; |
203 limits.max_transfer_buffer_size = std::min( | 204 limits.max_transfer_buffer_size = std::min( |
204 3 * full_screen_texture_size_in_bytes, kDefaultMaxTransferBufferSize); | 205 3 * full_screen_texture_size_in_bytes, kDefaultMaxTransferBufferSize); |
205 limits.mapped_memory_reclaim_limit = | 206 limits.mapped_memory_reclaim_limit = |
(...skipping 11 matching lines...) Expand all Loading... | |
217 context.get()).c_str()); | 218 context.get()).c_str()); |
218 } else { | 219 } else { |
219 context.reset(); | 220 context.reset(); |
220 } | 221 } |
221 | 222 |
222 return context.Pass(); | 223 return context.Pass(); |
223 } | 224 } |
224 | 225 |
225 // This can only be used for readback postprocessing. It may return null if the | 226 // This can only be used for readback postprocessing. It may return null if the |
226 // channel was lost and not reestablished yet. | 227 // channel was lost and not reestablished yet. |
227 GLHelper* GetPostReadbackGLHelper() { | 228 GLHelper* GetPostReadbackGLHelper(gfx::NativeWindow nativeWindow) { |
228 static GLHelperHolder* g_readback_helper_holder = nullptr; | 229 static GLHelperHolder* g_readback_helper_holder = nullptr; |
229 | 230 |
230 if (g_readback_helper_holder && g_readback_helper_holder->IsLost()) { | 231 if (g_readback_helper_holder && g_readback_helper_holder->IsLost()) { |
231 delete g_readback_helper_holder; | 232 delete g_readback_helper_holder; |
232 g_readback_helper_holder = nullptr; | 233 g_readback_helper_holder = nullptr; |
233 } | 234 } |
234 | 235 |
235 if (!g_readback_helper_holder) | 236 if (!g_readback_helper_holder) |
236 g_readback_helper_holder = GLHelperHolder::Create(); | 237 g_readback_helper_holder = GLHelperHolder::Create(nativeWindow); |
237 | 238 |
238 return g_readback_helper_holder->GetGLHelper(); | 239 return g_readback_helper_holder->GetGLHelper(); |
239 } | 240 } |
240 | 241 |
241 void CopyFromCompositingSurfaceFinished( | 242 void CopyFromCompositingSurfaceFinished( |
242 ReadbackRequestCallback& callback, | 243 ReadbackRequestCallback& callback, |
243 scoped_ptr<cc::SingleReleaseCallback> release_callback, | 244 scoped_ptr<cc::SingleReleaseCallback> release_callback, |
244 scoped_ptr<SkBitmap> bitmap, | 245 scoped_ptr<SkBitmap> bitmap, |
245 const base::TimeTicks& start_time, | 246 const base::TimeTicks& start_time, |
246 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock, | 247 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock, |
248 gfx::NativeWindow nativeWindow, | |
247 bool result) { | 249 bool result) { |
248 TRACE_EVENT0( | 250 TRACE_EVENT0( |
249 "cc", "RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceFinished"); | 251 "cc", "RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceFinished"); |
250 bitmap_pixels_lock.reset(); | 252 bitmap_pixels_lock.reset(); |
251 uint32 sync_point = 0; | 253 uint32 sync_point = 0; |
252 if (result) { | 254 if (result) { |
253 GLHelper* gl_helper = GetPostReadbackGLHelper(); | 255 GLHelper* gl_helper = GetPostReadbackGLHelper(nativeWindow); |
254 if (gl_helper) | 256 if (gl_helper) |
255 sync_point = gl_helper->InsertSyncPoint(); | 257 sync_point = gl_helper->InsertSyncPoint(); |
256 } | 258 } |
257 bool lost_resource = sync_point == 0; | 259 bool lost_resource = sync_point == 0; |
258 release_callback->Run(sync_point, lost_resource); | 260 release_callback->Run(sync_point, lost_resource); |
259 UMA_HISTOGRAM_TIMES(kAsyncReadBackString, | 261 UMA_HISTOGRAM_TIMES(kAsyncReadBackString, |
260 base::TimeTicks::Now() - start_time); | 262 base::TimeTicks::Now() - start_time); |
261 ReadbackResponse response = result ? READBACK_SUCCESS : READBACK_FAILED; | 263 ReadbackResponse response = result ? READBACK_SUCCESS : READBACK_FAILED; |
262 callback.Run(*bitmap, response); | 264 callback.Run(*bitmap, response); |
263 } | 265 } |
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
941 scoped_refptr<cc::Layer> layer = CreateDelegatedLayer(); | 943 scoped_refptr<cc::Layer> layer = CreateDelegatedLayer(); |
942 DCHECK(layer); | 944 DCHECK(layer); |
943 layer->SetHideLayerAndSubtree(true); | 945 layer->SetHideLayerAndSubtree(true); |
944 compositor->AttachLayerForReadback(layer); | 946 compositor->AttachLayerForReadback(layer); |
945 | 947 |
946 readback_layer = layer; | 948 readback_layer = layer; |
947 request = cc::CopyOutputRequest::CreateRequest( | 949 request = cc::CopyOutputRequest::CreateRequest( |
948 base::Bind(&RenderWidgetHostViewAndroid:: | 950 base::Bind(&RenderWidgetHostViewAndroid:: |
949 PrepareTextureCopyOutputResultForDelegatedReadback, | 951 PrepareTextureCopyOutputResultForDelegatedReadback, |
950 dst_size_in_pixel, preferred_color_type, start_time, | 952 dst_size_in_pixel, preferred_color_type, start_time, |
951 readback_layer, callback)); | 953 readback_layer, callback, content_view_core_window_android_)); |
952 if (!src_subrect_in_pixel.IsEmpty()) | 954 if (!src_subrect_in_pixel.IsEmpty()) |
953 request->set_area(src_subrect_in_pixel); | 955 request->set_area(src_subrect_in_pixel); |
954 readback_layer->RequestCopyOfOutput(request.Pass()); | 956 readback_layer->RequestCopyOfOutput(request.Pass()); |
955 } | 957 } |
956 | 958 |
957 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( | 959 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( |
958 const gfx::Rect& src_subrect, | 960 const gfx::Rect& src_subrect, |
959 const scoped_refptr<media::VideoFrame>& target, | 961 const scoped_refptr<media::VideoFrame>& target, |
960 const base::Callback<void(bool)>& callback) { | 962 const base::Callback<void(bool)>& callback) { |
961 NOTIMPLEMENTED(); | 963 NOTIMPLEMENTED(); |
(...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1920 } | 1922 } |
1921 | 1923 |
1922 // static | 1924 // static |
1923 void RenderWidgetHostViewAndroid:: | 1925 void RenderWidgetHostViewAndroid:: |
1924 PrepareTextureCopyOutputResultForDelegatedReadback( | 1926 PrepareTextureCopyOutputResultForDelegatedReadback( |
1925 const gfx::Size& dst_size_in_pixel, | 1927 const gfx::Size& dst_size_in_pixel, |
1926 SkColorType color_type, | 1928 SkColorType color_type, |
1927 const base::TimeTicks& start_time, | 1929 const base::TimeTicks& start_time, |
1928 scoped_refptr<cc::Layer> readback_layer, | 1930 scoped_refptr<cc::Layer> readback_layer, |
1929 ReadbackRequestCallback& callback, | 1931 ReadbackRequestCallback& callback, |
1932 gfx::NativeWindow nativeWindow, | |
1930 scoped_ptr<cc::CopyOutputResult> result) { | 1933 scoped_ptr<cc::CopyOutputResult> result) { |
1931 readback_layer->RemoveFromParent(); | 1934 readback_layer->RemoveFromParent(); |
1932 PrepareTextureCopyOutputResult( | 1935 PrepareTextureCopyOutputResult( |
1933 dst_size_in_pixel, color_type, start_time, callback, result.Pass()); | 1936 dst_size_in_pixel, color_type, start_time, callback, nativeWindow, |
1937 result.Pass()); | |
1934 } | 1938 } |
1935 | 1939 |
1936 // static | 1940 // static |
1937 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( | 1941 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( |
1938 const gfx::Size& dst_size_in_pixel, | 1942 const gfx::Size& dst_size_in_pixel, |
1939 SkColorType color_type, | 1943 SkColorType color_type, |
1940 const base::TimeTicks& start_time, | 1944 const base::TimeTicks& start_time, |
1941 ReadbackRequestCallback& callback, | 1945 ReadbackRequestCallback& callback, |
1946 gfx::NativeWindow nativeWindow, | |
1942 scoped_ptr<cc::CopyOutputResult> result) { | 1947 scoped_ptr<cc::CopyOutputResult> result) { |
1943 base::ScopedClosureRunner scoped_callback_runner( | 1948 base::ScopedClosureRunner scoped_callback_runner( |
1944 base::Bind(callback, SkBitmap(), READBACK_FAILED)); | 1949 base::Bind(callback, SkBitmap(), READBACK_FAILED)); |
1945 TRACE_EVENT0("cc", | 1950 TRACE_EVENT0("cc", |
1946 "RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult"); | 1951 "RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult"); |
1947 | 1952 |
1948 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) | 1953 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) |
1949 return; | 1954 return; |
1950 | 1955 |
1951 gfx::Size output_size_in_pixel; | 1956 gfx::Size output_size_in_pixel; |
1952 if (dst_size_in_pixel.IsEmpty()) | 1957 if (dst_size_in_pixel.IsEmpty()) |
1953 output_size_in_pixel = result->size(); | 1958 output_size_in_pixel = result->size(); |
1954 else | 1959 else |
1955 output_size_in_pixel = dst_size_in_pixel; | 1960 output_size_in_pixel = dst_size_in_pixel; |
1956 | 1961 |
1957 GLHelper* gl_helper = GetPostReadbackGLHelper(); | 1962 GLHelper* gl_helper = |
1963 GetPostReadbackGLHelper(nativeWindow); | |
1958 if (!gl_helper) | 1964 if (!gl_helper) |
1959 return; | 1965 return; |
1960 if (!gl_helper->IsReadbackConfigSupported(color_type)) | 1966 if (!gl_helper->IsReadbackConfigSupported(color_type)) |
1961 color_type = kRGBA_8888_SkColorType; | 1967 color_type = kRGBA_8888_SkColorType; |
1962 scoped_ptr<SkBitmap> bitmap(new SkBitmap); | 1968 scoped_ptr<SkBitmap> bitmap(new SkBitmap); |
1963 if (!bitmap->tryAllocPixels(SkImageInfo::Make(output_size_in_pixel.width(), | 1969 if (!bitmap->tryAllocPixels(SkImageInfo::Make(output_size_in_pixel.width(), |
1964 output_size_in_pixel.height(), | 1970 output_size_in_pixel.height(), |
1965 color_type, | 1971 color_type, |
1966 kOpaque_SkAlphaType))) { | 1972 kOpaque_SkAlphaType))) { |
1967 scoped_callback_runner.Reset( | 1973 scoped_callback_runner.Reset( |
(...skipping 21 matching lines...) Expand all Loading... | |
1989 result->size(), | 1995 result->size(), |
1990 gfx::Rect(result->size()), | 1996 gfx::Rect(result->size()), |
1991 output_size_in_pixel, | 1997 output_size_in_pixel, |
1992 pixels, | 1998 pixels, |
1993 color_type, | 1999 color_type, |
1994 base::Bind(&CopyFromCompositingSurfaceFinished, | 2000 base::Bind(&CopyFromCompositingSurfaceFinished, |
1995 callback, | 2001 callback, |
1996 base::Passed(&release_callback), | 2002 base::Passed(&release_callback), |
1997 base::Passed(&bitmap), | 2003 base::Passed(&bitmap), |
1998 start_time, | 2004 start_time, |
1999 base::Passed(&bitmap_pixels_lock)), | 2005 base::Passed(&bitmap_pixels_lock), |
2006 nativeWindow), | |
2000 GLHelper::SCALER_QUALITY_GOOD); | 2007 GLHelper::SCALER_QUALITY_GOOD); |
2001 } | 2008 } |
2002 | 2009 |
2003 void RenderWidgetHostViewAndroid::OnStylusSelectBegin(float x0, | 2010 void RenderWidgetHostViewAndroid::OnStylusSelectBegin(float x0, |
2004 float y0, | 2011 float y0, |
2005 float x1, | 2012 float x1, |
2006 float y1) { | 2013 float y1) { |
2007 SelectBetweenCoordinates(gfx::PointF(x0, y0), gfx::PointF(x1, y1)); | 2014 SelectBetweenCoordinates(gfx::PointF(x0, y0), gfx::PointF(x1, y1)); |
2008 } | 2015 } |
2009 | 2016 |
(...skipping 22 matching lines...) Expand all Loading... | |
2032 blink::WebScreenInfo* results) { | 2039 blink::WebScreenInfo* results) { |
2033 const gfx::Display& display = | 2040 const gfx::Display& display = |
2034 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 2041 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
2035 results->rect = display.bounds(); | 2042 results->rect = display.bounds(); |
2036 // TODO(husky): Remove any system controls from availableRect. | 2043 // TODO(husky): Remove any system controls from availableRect. |
2037 results->availableRect = display.work_area(); | 2044 results->availableRect = display.work_area(); |
2038 results->deviceScaleFactor = display.device_scale_factor(); | 2045 results->deviceScaleFactor = display.device_scale_factor(); |
2039 results->orientationAngle = display.RotationAsDegree(); | 2046 results->orientationAngle = display.RotationAsDegree(); |
2040 results->orientationType = | 2047 results->orientationType = |
2041 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); | 2048 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); |
2042 gfx::DeviceDisplayInfo info; | 2049 gfx::DeviceDisplayInfo info; // TODO since we don't have a Native Window here |
2050 // we can only use the primary display? | |
boliu
2015/06/01 15:30:18
Yes
Although should double check that any caller
gsennton
2015/06/04 14:10:29
This is called from two places:
1. GetScreenInfo
boliu
2015/06/05 04:57:51
You are right. Comment assumes android only has a
| |
2043 results->depth = info.GetBitsPerPixel(); | 2051 results->depth = info.GetBitsPerPixel(); |
2044 results->depthPerComponent = info.GetBitsPerComponent(); | 2052 results->depthPerComponent = info.GetBitsPerComponent(); |
2045 results->isMonochrome = (results->depthPerComponent == 0); | 2053 results->isMonochrome = (results->depthPerComponent == 0); |
2046 } | 2054 } |
2047 | 2055 |
2048 } // namespace content | 2056 } // namespace content |
OLD | NEW |