Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(533)

Side by Side Diff: content/browser/renderer_host/compositor_impl_android.cc

Issue 143803004: android: Migrate old content readback to use async readback (and delegated renderer) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/compositor_impl_android.h" 5 #include "content/browser/renderer_host/compositor_impl_android.h"
6 6
7 #include <android/bitmap.h> 7 #include <android/bitmap.h>
8 #include <android/native_window_jni.h> 8 #include <android/native_window_jni.h>
9 #include <map> 9 #include <map>
10 10
11 #include "base/android/jni_android.h" 11 #include "base/android/jni_android.h"
12 #include "base/android/scoped_java_ref.h" 12 #include "base/android/scoped_java_ref.h"
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/callback_helpers.h"
14 #include "base/command_line.h" 15 #include "base/command_line.h"
15 #include "base/lazy_instance.h" 16 #include "base/lazy_instance.h"
16 #include "base/logging.h" 17 #include "base/logging.h"
17 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
18 #include "base/synchronization/lock.h" 19 #include "base/synchronization/lock.h"
19 #include "base/threading/thread.h" 20 #include "base/threading/thread.h"
20 #include "cc/input/input_handler.h" 21 #include "cc/input/input_handler.h"
21 #include "cc/layers/layer.h" 22 #include "cc/layers/layer.h"
22 #include "cc/output/compositor_frame.h" 23 #include "cc/output/compositor_frame.h"
23 #include "cc/output/context_provider.h" 24 #include "cc/output/context_provider.h"
24 #include "cc/output/output_surface.h" 25 #include "cc/output/output_surface.h"
25 #include "cc/resources/scoped_ui_resource.h" 26 #include "cc/resources/scoped_ui_resource.h"
26 #include "cc/resources/ui_resource_bitmap.h" 27 #include "cc/resources/ui_resource_bitmap.h"
27 #include "cc/trees/layer_tree_host.h" 28 #include "cc/trees/layer_tree_host.h"
29 #include "content/browser/android/transient_ui_resource.h"
28 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" 30 #include "content/browser/gpu/browser_gpu_channel_host_factory.h"
29 #include "content/browser/gpu/gpu_surface_tracker.h" 31 #include "content/browser/gpu/gpu_surface_tracker.h"
30 #include "content/common/gpu/client/command_buffer_proxy_impl.h" 32 #include "content/common/gpu/client/command_buffer_proxy_impl.h"
31 #include "content/common/gpu/client/context_provider_command_buffer.h" 33 #include "content/common/gpu/client/context_provider_command_buffer.h"
32 #include "content/common/gpu/client/gl_helper.h" 34 #include "content/common/gpu/client/gl_helper.h"
33 #include "content/common/gpu/client/gpu_channel_host.h" 35 #include "content/common/gpu/client/gpu_channel_host.h"
34 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" 36 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
35 #include "content/common/gpu/gpu_process_launch_causes.h" 37 #include "content/common/gpu/gpu_process_launch_causes.h"
36 #include "content/public/browser/android/compositor_client.h" 38 #include "content/public/browser/android/compositor_client.h"
37 #include "content/public/common/content_switches.h" 39 #include "content/public/common/content_switches.h"
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 ANativeWindow_release(window); 207 ANativeWindow_release(window);
206 { 208 {
207 base::AutoLock lock(g_surface_map_lock.Get()); 209 base::AutoLock lock(g_surface_map_lock.Get());
208 g_surface_map.Get().insert(std::make_pair(surface_id_, j_surface)); 210 g_surface_map.Get().insert(std::make_pair(surface_id_, j_surface));
209 } 211 }
210 } 212 }
211 } 213 }
212 214
213 void CompositorImpl::SetVisible(bool visible) { 215 void CompositorImpl::SetVisible(bool visible) {
214 if (!visible) { 216 if (!visible) {
215 ui_resource_map_.clear(); 217 ui_resource_map_.clear();
no sievers 2014/01/28 20:47:22 Does the application need to recreate all UI resou
powei 2014/01/29 13:53:17 Yes, right now the tabs resources are gone when sh
no sievers 2014/01/29 21:13:48 Sure, no problem. Was mainly wondering what the ap
216 host_.reset(); 218 host_.reset();
217 client_->UIResourcesAreInvalid(); 219 client_->UIResourcesAreInvalid();
218 } else if (!host_) { 220 } else if (!host_) {
219 cc::LayerTreeSettings settings; 221 cc::LayerTreeSettings settings;
220 settings.refresh_rate = 60.0; 222 settings.refresh_rate = 60.0;
221 settings.impl_side_painting = false; 223 settings.impl_side_painting = false;
222 settings.allow_antialiasing = false; 224 settings.allow_antialiasing = false;
223 settings.calculate_top_controls_position = false; 225 settings.calculate_top_controls_position = false;
224 settings.top_controls_height = 0.f; 226 settings.top_controls_height = 0.f;
225 settings.use_memory_management = false; 227 settings.use_memory_management = false;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 if (host_) 265 if (host_)
264 return host_->CompositeAndReadback(pixels, rect); 266 return host_->CompositeAndReadback(pixels, rect);
265 else 267 else
266 return false; 268 return false;
267 } 269 }
268 270
269 cc::UIResourceId CompositorImpl::GenerateUIResource( 271 cc::UIResourceId CompositorImpl::GenerateUIResource(
270 const cc::UIResourceBitmap& bitmap) { 272 const cc::UIResourceBitmap& bitmap) {
271 if (!host_) 273 if (!host_)
272 return 0; 274 return 0;
273 scoped_ptr<cc::ScopedUIResource> ui_resource = 275 scoped_ptr<cc::UIResourceClient> ui_resource;
274 cc::ScopedUIResource::Create(host_.get(), bitmap); 276 cc::UIResourceId id = 0;
275 cc::UIResourceId id = ui_resource->id(); 277 if (bitmap.GetFormat() == cc::UIResourceBitmap::RGBA8) {
278 scoped_ptr<cc::ScopedUIResource> scoped =
no sievers 2014/01/28 20:47:22 nit: |scoped| -> |resource|
powei 2014/01/29 13:53:17 Done.
279 cc::ScopedUIResource::Create(host_.get(), bitmap);
280 id = scoped->id();
281 ui_resource.reset(scoped.release());
282 } else if (bitmap.GetFormat() == cc::UIResourceBitmap::ETC1) {
283 scoped_ptr<TransientUIResource> transient =
284 TransientUIResource::Create(host_.get(), bitmap);
285 id = transient->id();
286 ui_resource.reset(transient.release());
287 } else {
288 NOTREACHED();
no sievers 2014/01/28 20:47:22 return 0;
powei 2014/01/29 13:53:17 Done.
289 }
290
276 ui_resource_map_.set(id, ui_resource.Pass()); 291 ui_resource_map_.set(id, ui_resource.Pass());
277 return id; 292 return id;
278 } 293 }
279 294
280 void CompositorImpl::DeleteUIResource(cc::UIResourceId resource_id) { 295 void CompositorImpl::DeleteUIResource(cc::UIResourceId resource_id) {
281 UIResourceMap::iterator it = ui_resource_map_.find(resource_id); 296 UIResourceMap::iterator it = ui_resource_map_.find(resource_id);
282 if (it != ui_resource_map_.end()) 297 if (it != ui_resource_map_.end())
283 ui_resource_map_.erase(it); 298 ui_resource_map_.erase(it);
284 } 299 }
285 300
286 GLuint CompositorImpl::GenerateTexture(gfx::JavaBitmap& bitmap) {
287 unsigned int texture_id = BuildBasicTexture();
288 gpu::gles2::GLES2Interface* gl =
289 ImageTransportFactoryAndroid::GetInstance()->GetContextGL();
290 if (texture_id == 0u)
291 return 0u;
292 GLenum format = GetGLFormatForBitmap(bitmap);
293 GLenum type = GetGLTypeForBitmap(bitmap);
294
295 gl->TexImage2D(GL_TEXTURE_2D,
296 0,
297 format,
298 bitmap.size().width(),
299 bitmap.size().height(),
300 0,
301 format,
302 type,
303 bitmap.pixels());
304 gl->ShallowFlushCHROMIUM();
305 return texture_id;
306 }
307
308 GLuint CompositorImpl::GenerateCompressedTexture(gfx::Size& size,
309 int data_size,
310 void* data) {
311 unsigned int texture_id = BuildBasicTexture();
312 gpu::gles2::GLES2Interface* gl =
313 ImageTransportFactoryAndroid::GetInstance()->GetContextGL();
314 if (texture_id == 0u)
315 return 0u;
316 gl->CompressedTexImage2D(GL_TEXTURE_2D,
317 0,
318 GL_ETC1_RGB8_OES,
319 size.width(),
320 size.height(),
321 0,
322 data_size,
323 data);
324 gl->ShallowFlushCHROMIUM();
325 return texture_id;
326 }
327
328 void CompositorImpl::DeleteTexture(GLuint texture_id) {
329 gpu::gles2::GLES2Interface* gl =
330 ImageTransportFactoryAndroid::GetInstance()->GetContextGL();
331 gl->DeleteTextures(1, &texture_id);
332 gl->ShallowFlushCHROMIUM();
333 }
334
335 bool CompositorImpl::CopyTextureToBitmap(GLuint texture_id,
336 gfx::JavaBitmap& bitmap) {
337 return CopyTextureToBitmap(texture_id, gfx::Rect(bitmap.size()), bitmap);
338 }
339
340 bool CompositorImpl::CopyTextureToBitmap(GLuint texture_id,
341 const gfx::Rect& sub_rect,
342 gfx::JavaBitmap& bitmap) {
343 // The sub_rect should match the bitmap size.
344 DCHECK(bitmap.size() == sub_rect.size());
345 if (bitmap.size() != sub_rect.size() || texture_id == 0) return false;
346
347 GLHelper* helper = ImageTransportFactoryAndroid::GetInstance()->GetGLHelper();
348 helper->ReadbackTextureSync(texture_id,
349 sub_rect,
350 static_cast<unsigned char*> (bitmap.pixels()),
351 SkBitmap::kARGB_8888_Config);
352 return true;
353 }
354
355 static scoped_ptr<WebGraphicsContext3DCommandBufferImpl> 301 static scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
356 CreateGpuProcessViewContext( 302 CreateGpuProcessViewContext(
357 const blink::WebGraphicsContext3D::Attributes attributes, 303 const blink::WebGraphicsContext3D::Attributes attributes,
358 int surface_id) { 304 int surface_id) {
359 BrowserGpuChannelHostFactory* factory = 305 BrowserGpuChannelHostFactory* factory =
360 BrowserGpuChannelHostFactory::instance(); 306 BrowserGpuChannelHostFactory::instance();
361 CauseForGpuLaunch cause = 307 CauseForGpuLaunch cause =
362 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; 308 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
363 scoped_refptr<GpuChannelHost> gpu_channel_host( 309 scoped_refptr<GpuChannelHost> gpu_channel_host(
364 factory->EstablishGpuChannelSync(cause)); 310 factory->EstablishGpuChannelSync(cause));
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 default: 434 default:
489 return GL_UNSIGNED_SHORT_5_6_5; 435 return GL_UNSIGNED_SHORT_5_6_5;
490 } 436 }
491 } 437 }
492 438
493 void CompositorImpl::DidCommit() { 439 void CompositorImpl::DidCommit() {
494 root_window_->OnCompositingDidCommit(); 440 root_window_->OnCompositingDidCommit();
495 } 441 }
496 442
497 } // namespace content 443 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698