| 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/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 |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 ui_resource_map_.set(id, ui_resource.Pass()); | 276 ui_resource_map_.set(id, ui_resource.Pass()); |
| 277 return id; | 277 return id; |
| 278 } | 278 } |
| 279 | 279 |
| 280 void CompositorImpl::DeleteUIResource(cc::UIResourceId resource_id) { | 280 void CompositorImpl::DeleteUIResource(cc::UIResourceId resource_id) { |
| 281 UIResourceMap::iterator it = ui_resource_map_.find(resource_id); | 281 UIResourceMap::iterator it = ui_resource_map_.find(resource_id); |
| 282 if (it != ui_resource_map_.end()) | 282 if (it != ui_resource_map_.end()) |
| 283 ui_resource_map_.erase(it); | 283 ui_resource_map_.erase(it); |
| 284 } | 284 } |
| 285 | 285 |
| 286 WebKit::WebGLId CompositorImpl::GenerateTexture(gfx::JavaBitmap& bitmap) { | 286 blink::WebGLId CompositorImpl::GenerateTexture(gfx::JavaBitmap& bitmap) { |
| 287 unsigned int texture_id = BuildBasicTexture(); | 287 unsigned int texture_id = BuildBasicTexture(); |
| 288 WebKit::WebGraphicsContext3D* context = | 288 blink::WebGraphicsContext3D* context = |
| 289 ImageTransportFactoryAndroid::GetInstance()->GetContext3D(); | 289 ImageTransportFactoryAndroid::GetInstance()->GetContext3D(); |
| 290 if (texture_id == 0 || context->isContextLost() || | 290 if (texture_id == 0 || context->isContextLost() || |
| 291 !context->makeContextCurrent()) | 291 !context->makeContextCurrent()) |
| 292 return 0; | 292 return 0; |
| 293 WebKit::WebGLId format = GetGLFormatForBitmap(bitmap); | 293 blink::WebGLId format = GetGLFormatForBitmap(bitmap); |
| 294 WebKit::WebGLId type = GetGLTypeForBitmap(bitmap); | 294 blink::WebGLId type = GetGLTypeForBitmap(bitmap); |
| 295 | 295 |
| 296 context->texImage2D(GL_TEXTURE_2D, | 296 context->texImage2D(GL_TEXTURE_2D, |
| 297 0, | 297 0, |
| 298 format, | 298 format, |
| 299 bitmap.size().width(), | 299 bitmap.size().width(), |
| 300 bitmap.size().height(), | 300 bitmap.size().height(), |
| 301 0, | 301 0, |
| 302 format, | 302 format, |
| 303 type, | 303 type, |
| 304 bitmap.pixels()); | 304 bitmap.pixels()); |
| 305 context->shallowFlushCHROMIUM(); | 305 context->shallowFlushCHROMIUM(); |
| 306 return texture_id; | 306 return texture_id; |
| 307 } | 307 } |
| 308 | 308 |
| 309 WebKit::WebGLId CompositorImpl::GenerateCompressedTexture(gfx::Size& size, | 309 blink::WebGLId CompositorImpl::GenerateCompressedTexture(gfx::Size& size, |
| 310 int data_size, | 310 int data_size, |
| 311 void* data) { | 311 void* data) { |
| 312 unsigned int texture_id = BuildBasicTexture(); | 312 unsigned int texture_id = BuildBasicTexture(); |
| 313 WebKit::WebGraphicsContext3D* context = | 313 blink::WebGraphicsContext3D* context = |
| 314 ImageTransportFactoryAndroid::GetInstance()->GetContext3D(); | 314 ImageTransportFactoryAndroid::GetInstance()->GetContext3D(); |
| 315 if (texture_id == 0 || context->isContextLost() || | 315 if (texture_id == 0 || context->isContextLost() || |
| 316 !context->makeContextCurrent()) | 316 !context->makeContextCurrent()) |
| 317 return 0; | 317 return 0; |
| 318 context->compressedTexImage2D(GL_TEXTURE_2D, | 318 context->compressedTexImage2D(GL_TEXTURE_2D, |
| 319 0, | 319 0, |
| 320 GL_ETC1_RGB8_OES, | 320 GL_ETC1_RGB8_OES, |
| 321 size.width(), | 321 size.width(), |
| 322 size.height(), | 322 size.height(), |
| 323 0, | 323 0, |
| 324 data_size, | 324 data_size, |
| 325 data); | 325 data); |
| 326 context->shallowFlushCHROMIUM(); | 326 context->shallowFlushCHROMIUM(); |
| 327 return texture_id; | 327 return texture_id; |
| 328 } | 328 } |
| 329 | 329 |
| 330 void CompositorImpl::DeleteTexture(WebKit::WebGLId texture_id) { | 330 void CompositorImpl::DeleteTexture(blink::WebGLId texture_id) { |
| 331 WebKit::WebGraphicsContext3D* context = | 331 blink::WebGraphicsContext3D* context = |
| 332 ImageTransportFactoryAndroid::GetInstance()->GetContext3D(); | 332 ImageTransportFactoryAndroid::GetInstance()->GetContext3D(); |
| 333 if (context->isContextLost() || !context->makeContextCurrent()) | 333 if (context->isContextLost() || !context->makeContextCurrent()) |
| 334 return; | 334 return; |
| 335 context->deleteTexture(texture_id); | 335 context->deleteTexture(texture_id); |
| 336 context->shallowFlushCHROMIUM(); | 336 context->shallowFlushCHROMIUM(); |
| 337 } | 337 } |
| 338 | 338 |
| 339 bool CompositorImpl::CopyTextureToBitmap(WebKit::WebGLId texture_id, | 339 bool CompositorImpl::CopyTextureToBitmap(blink::WebGLId texture_id, |
| 340 gfx::JavaBitmap& bitmap) { | 340 gfx::JavaBitmap& bitmap) { |
| 341 return CopyTextureToBitmap(texture_id, gfx::Rect(bitmap.size()), bitmap); | 341 return CopyTextureToBitmap(texture_id, gfx::Rect(bitmap.size()), bitmap); |
| 342 } | 342 } |
| 343 | 343 |
| 344 bool CompositorImpl::CopyTextureToBitmap(WebKit::WebGLId texture_id, | 344 bool CompositorImpl::CopyTextureToBitmap(blink::WebGLId texture_id, |
| 345 const gfx::Rect& sub_rect, | 345 const gfx::Rect& sub_rect, |
| 346 gfx::JavaBitmap& bitmap) { | 346 gfx::JavaBitmap& bitmap) { |
| 347 // The sub_rect should match the bitmap size. | 347 // The sub_rect should match the bitmap size. |
| 348 DCHECK(bitmap.size() == sub_rect.size()); | 348 DCHECK(bitmap.size() == sub_rect.size()); |
| 349 if (bitmap.size() != sub_rect.size() || texture_id == 0) return false; | 349 if (bitmap.size() != sub_rect.size() || texture_id == 0) return false; |
| 350 | 350 |
| 351 GLHelper* helper = ImageTransportFactoryAndroid::GetInstance()->GetGLHelper(); | 351 GLHelper* helper = ImageTransportFactoryAndroid::GetInstance()->GetGLHelper(); |
| 352 helper->ReadbackTextureSync(texture_id, | 352 helper->ReadbackTextureSync(texture_id, |
| 353 sub_rect, | 353 sub_rect, |
| 354 static_cast<unsigned char*> (bitmap.pixels())); | 354 static_cast<unsigned char*> (bitmap.pixels())); |
| 355 return true; | 355 return true; |
| 356 } | 356 } |
| 357 | 357 |
| 358 static scoped_ptr<WebGraphicsContext3DCommandBufferImpl> | 358 static scoped_ptr<WebGraphicsContext3DCommandBufferImpl> |
| 359 CreateGpuProcessViewContext( | 359 CreateGpuProcessViewContext( |
| 360 const WebKit::WebGraphicsContext3D::Attributes attributes, | 360 const blink::WebGraphicsContext3D::Attributes attributes, |
| 361 int surface_id, | 361 int surface_id, |
| 362 base::WeakPtr<CompositorImpl> compositor_impl) { | 362 base::WeakPtr<CompositorImpl> compositor_impl) { |
| 363 BrowserGpuChannelHostFactory* factory = | 363 BrowserGpuChannelHostFactory* factory = |
| 364 BrowserGpuChannelHostFactory::instance(); | 364 BrowserGpuChannelHostFactory::instance(); |
| 365 scoped_refptr<GpuChannelHost> gpu_channel_host(factory->EstablishGpuChannelSyn
c( | 365 scoped_refptr<GpuChannelHost> gpu_channel_host(factory->EstablishGpuChannelSyn
c( |
| 366 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE)); | 366 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE)); |
| 367 if (!gpu_channel_host) | 367 if (!gpu_channel_host) |
| 368 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); | 368 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); |
| 369 | 369 |
| 370 GURL url("chrome://gpu/Compositor::createContext3D"); | 370 GURL url("chrome://gpu/Compositor::createContext3D"); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 386 url, | 386 url, |
| 387 gpu_channel_host.get(), | 387 gpu_channel_host.get(), |
| 388 compositor_impl, | 388 compositor_impl, |
| 389 attributes, | 389 attributes, |
| 390 false, | 390 false, |
| 391 limits)); | 391 limits)); |
| 392 } | 392 } |
| 393 | 393 |
| 394 scoped_ptr<cc::OutputSurface> CompositorImpl::CreateOutputSurface( | 394 scoped_ptr<cc::OutputSurface> CompositorImpl::CreateOutputSurface( |
| 395 bool fallback) { | 395 bool fallback) { |
| 396 WebKit::WebGraphicsContext3D::Attributes attrs; | 396 blink::WebGraphicsContext3D::Attributes attrs; |
| 397 attrs.shareResources = true; | 397 attrs.shareResources = true; |
| 398 attrs.noAutomaticFlushes = true; | 398 attrs.noAutomaticFlushes = true; |
| 399 | 399 |
| 400 DCHECK(window_); | 400 DCHECK(window_); |
| 401 DCHECK(surface_id_); | 401 DCHECK(surface_id_); |
| 402 | 402 |
| 403 scoped_refptr<ContextProviderCommandBuffer> context_provider = | 403 scoped_refptr<ContextProviderCommandBuffer> context_provider = |
| 404 ContextProviderCommandBuffer::Create(CreateGpuProcessViewContext( | 404 ContextProviderCommandBuffer::Create(CreateGpuProcessViewContext( |
| 405 attrs, surface_id_, weak_factory_.GetWeakPtr()), "BrowserCompositor"); | 405 attrs, surface_id_, weak_factory_.GetWeakPtr()), "BrowserCompositor"); |
| 406 if (!context_provider.get()) { | 406 if (!context_provider.get()) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 TRACE_EVENT0("compositor", | 441 TRACE_EVENT0("compositor", |
| 442 "CompositorImpl::OnViewContextSwapBuffersComplete"); | 442 "CompositorImpl::OnViewContextSwapBuffersComplete"); |
| 443 client_->OnSwapBuffersCompleted(); | 443 client_->OnSwapBuffersCompleted(); |
| 444 } | 444 } |
| 445 | 445 |
| 446 void CompositorImpl::OnViewContextSwapBuffersAborted() { | 446 void CompositorImpl::OnViewContextSwapBuffersAborted() { |
| 447 TRACE_EVENT0("compositor", "CompositorImpl::OnViewContextSwapBuffersAborted"); | 447 TRACE_EVENT0("compositor", "CompositorImpl::OnViewContextSwapBuffersAborted"); |
| 448 client_->OnSwapBuffersCompleted(); | 448 client_->OnSwapBuffersCompleted(); |
| 449 } | 449 } |
| 450 | 450 |
| 451 WebKit::WebGLId CompositorImpl::BuildBasicTexture() { | 451 blink::WebGLId CompositorImpl::BuildBasicTexture() { |
| 452 WebKit::WebGraphicsContext3D* context = | 452 blink::WebGraphicsContext3D* context = |
| 453 ImageTransportFactoryAndroid::GetInstance()->GetContext3D(); | 453 ImageTransportFactoryAndroid::GetInstance()->GetContext3D(); |
| 454 if (context->isContextLost() || !context->makeContextCurrent()) | 454 if (context->isContextLost() || !context->makeContextCurrent()) |
| 455 return 0; | 455 return 0; |
| 456 WebKit::WebGLId texture_id = context->createTexture(); | 456 blink::WebGLId texture_id = context->createTexture(); |
| 457 context->bindTexture(GL_TEXTURE_2D, texture_id); | 457 context->bindTexture(GL_TEXTURE_2D, texture_id); |
| 458 context->texParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 458 context->texParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 459 context->texParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 459 context->texParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 460 context->texParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 460 context->texParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 461 context->texParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 461 context->texParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 462 return texture_id; | 462 return texture_id; |
| 463 } | 463 } |
| 464 | 464 |
| 465 WebKit::WGC3Denum CompositorImpl::GetGLFormatForBitmap( | 465 blink::WGC3Denum CompositorImpl::GetGLFormatForBitmap( |
| 466 gfx::JavaBitmap& bitmap) { | 466 gfx::JavaBitmap& bitmap) { |
| 467 switch (bitmap.format()) { | 467 switch (bitmap.format()) { |
| 468 case ANDROID_BITMAP_FORMAT_A_8: | 468 case ANDROID_BITMAP_FORMAT_A_8: |
| 469 return GL_ALPHA; | 469 return GL_ALPHA; |
| 470 break; | 470 break; |
| 471 case ANDROID_BITMAP_FORMAT_RGBA_4444: | 471 case ANDROID_BITMAP_FORMAT_RGBA_4444: |
| 472 return GL_RGBA; | 472 return GL_RGBA; |
| 473 break; | 473 break; |
| 474 case ANDROID_BITMAP_FORMAT_RGBA_8888: | 474 case ANDROID_BITMAP_FORMAT_RGBA_8888: |
| 475 return GL_RGBA; | 475 return GL_RGBA; |
| 476 break; | 476 break; |
| 477 case ANDROID_BITMAP_FORMAT_RGB_565: | 477 case ANDROID_BITMAP_FORMAT_RGB_565: |
| 478 default: | 478 default: |
| 479 return GL_RGB; | 479 return GL_RGB; |
| 480 } | 480 } |
| 481 } | 481 } |
| 482 | 482 |
| 483 WebKit::WGC3Denum CompositorImpl::GetGLTypeForBitmap(gfx::JavaBitmap& bitmap) { | 483 blink::WGC3Denum CompositorImpl::GetGLTypeForBitmap(gfx::JavaBitmap& bitmap) { |
| 484 switch (bitmap.format()) { | 484 switch (bitmap.format()) { |
| 485 case ANDROID_BITMAP_FORMAT_A_8: | 485 case ANDROID_BITMAP_FORMAT_A_8: |
| 486 return GL_UNSIGNED_BYTE; | 486 return GL_UNSIGNED_BYTE; |
| 487 break; | 487 break; |
| 488 case ANDROID_BITMAP_FORMAT_RGBA_4444: | 488 case ANDROID_BITMAP_FORMAT_RGBA_4444: |
| 489 return GL_UNSIGNED_SHORT_4_4_4_4; | 489 return GL_UNSIGNED_SHORT_4_4_4_4; |
| 490 break; | 490 break; |
| 491 case ANDROID_BITMAP_FORMAT_RGBA_8888: | 491 case ANDROID_BITMAP_FORMAT_RGBA_8888: |
| 492 return GL_UNSIGNED_BYTE; | 492 return GL_UNSIGNED_BYTE; |
| 493 break; | 493 break; |
| 494 case ANDROID_BITMAP_FORMAT_RGB_565: | 494 case ANDROID_BITMAP_FORMAT_RGB_565: |
| 495 default: | 495 default: |
| 496 return GL_UNSIGNED_SHORT_5_6_5; | 496 return GL_UNSIGNED_SHORT_5_6_5; |
| 497 } | 497 } |
| 498 } | 498 } |
| 499 | 499 |
| 500 } // namespace content | 500 } // namespace content |
| OLD | NEW |