| OLD | NEW |
| 1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 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 "cc/gl_renderer.h" | 5 #include "cc/gl_renderer.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "cc/proxy.h" | 24 #include "cc/proxy.h" |
| 25 #include "cc/render_pass.h" | 25 #include "cc/render_pass.h" |
| 26 #include "cc/render_surface_filters.h" | 26 #include "cc/render_surface_filters.h" |
| 27 #include "cc/scoped_resource.h" | 27 #include "cc/scoped_resource.h" |
| 28 #include "cc/single_thread_proxy.h" | 28 #include "cc/single_thread_proxy.h" |
| 29 #include "cc/stream_video_draw_quad.h" | 29 #include "cc/stream_video_draw_quad.h" |
| 30 #include "cc/texture_draw_quad.h" | 30 #include "cc/texture_draw_quad.h" |
| 31 #include "cc/video_layer_impl.h" | 31 #include "cc/video_layer_impl.h" |
| 32 #include "gpu/GLES2/gl2extchromium.h" | 32 #include "gpu/GLES2/gl2extchromium.h" |
| 33 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" | 33 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" |
| 34 #include "third_party/WebKit/Source/Platform/chromium/public/WebSharedGraphicsCo
ntext3D.h" | |
| 35 #include "third_party/khronos/GLES2/gl2.h" | 34 #include "third_party/khronos/GLES2/gl2.h" |
| 36 #include "third_party/khronos/GLES2/gl2ext.h" | 35 #include "third_party/khronos/GLES2/gl2ext.h" |
| 37 #include "third_party/skia/include/core/SkBitmap.h" | 36 #include "third_party/skia/include/core/SkBitmap.h" |
| 38 #include "third_party/skia/include/core/SkColor.h" | 37 #include "third_party/skia/include/core/SkColor.h" |
| 39 #include "third_party/skia/include/gpu/GrContext.h" | 38 #include "third_party/skia/include/gpu/GrContext.h" |
| 40 #include "third_party/skia/include/gpu/GrTexture.h" | 39 #include "third_party/skia/include/gpu/GrTexture.h" |
| 41 #include "third_party/skia/include/gpu/SkGpuDevice.h" | 40 #include "third_party/skia/include/gpu/SkGpuDevice.h" |
| 42 #include "third_party/skia/include/gpu/SkGrTexturePixelRef.h" | 41 #include "third_party/skia/include/gpu/SkGrTexturePixelRef.h" |
| 43 #include "ui/gfx/quad_f.h" | 42 #include "ui/gfx/quad_f.h" |
| 44 #include "ui/gfx/rect_conversions.h" | 43 #include "ui/gfx/rect_conversions.h" |
| 45 | 44 |
| 46 using WebKit::WebGraphicsContext3D; | 45 using WebKit::WebGraphicsContext3D; |
| 47 using WebKit::WebGraphicsMemoryAllocation; | 46 using WebKit::WebGraphicsMemoryAllocation; |
| 48 using WebKit::WebSharedGraphicsContext3D; | |
| 49 | 47 |
| 50 namespace cc { | 48 namespace cc { |
| 51 | 49 |
| 52 namespace { | 50 namespace { |
| 53 | 51 |
| 54 bool needsIOSurfaceReadbackWorkaround() | 52 bool needsIOSurfaceReadbackWorkaround() |
| 55 { | 53 { |
| 56 #if defined(OS_MACOSX) | 54 #if defined(OS_MACOSX) |
| 57 return true; | 55 return true; |
| 58 #else | 56 #else |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 float alpha = SkColorGetA(color) / 255.0; | 341 float alpha = SkColorGetA(color) / 255.0; |
| 344 | 342 |
| 345 GLC(context(), context()->uniform4f(program->fragmentShader().colorLocation(
), (SkColorGetR(color) / 255.0) * alpha, (SkColorGetG(color) / 255.0) * alpha, (
SkColorGetB(color) / 255.0) * alpha, alpha)); | 343 GLC(context(), context()->uniform4f(program->fragmentShader().colorLocation(
), (SkColorGetR(color) / 255.0) * alpha, (SkColorGetG(color) / 255.0) * alpha, (
SkColorGetB(color) / 255.0) * alpha, alpha)); |
| 346 | 344 |
| 347 GLC(context(), context()->lineWidth(quad->width)); | 345 GLC(context(), context()->lineWidth(quad->width)); |
| 348 | 346 |
| 349 // The indices for the line are stored in the same array as the triangle ind
ices. | 347 // The indices for the line are stored in the same array as the triangle ind
ices. |
| 350 GLC(context(), context()->drawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 0
)); | 348 GLC(context(), context()->drawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 0
)); |
| 351 } | 349 } |
| 352 | 350 |
| 353 static WebGraphicsContext3D* getFilterContext(bool hasImplThread) | 351 static inline SkBitmap applyFilters(GLRenderer* renderer, const WebKit::WebFilte
rOperations& filters, ScopedResource* sourceTexture, WebGraphicsContext3D* filte
rContext, GrContext* filterGrContext) |
| 354 { | |
| 355 if (hasImplThread) | |
| 356 return WebSharedGraphicsContext3D::compositorThreadContext(); | |
| 357 else | |
| 358 return WebSharedGraphicsContext3D::mainThreadContext(); | |
| 359 } | |
| 360 | |
| 361 static GrContext* getFilterGrContext(bool hasImplThread) | |
| 362 { | |
| 363 if (hasImplThread) | |
| 364 return WebSharedGraphicsContext3D::compositorThreadGrContext(); | |
| 365 else | |
| 366 return WebSharedGraphicsContext3D::mainThreadGrContext(); | |
| 367 } | |
| 368 | |
| 369 static inline SkBitmap applyFilters(GLRenderer* renderer, const WebKit::WebFilte
rOperations& filters, ScopedResource* sourceTexture, bool hasImplThread) | |
| 370 { | 352 { |
| 371 if (filters.isEmpty()) | 353 if (filters.isEmpty()) |
| 372 return SkBitmap(); | 354 return SkBitmap(); |
| 373 | 355 |
| 374 WebGraphicsContext3D* filterContext = getFilterContext(hasImplThread); | 356 if (!filterContext) |
| 375 GrContext* filterGrContext = getFilterGrContext(hasImplThread); | 357 return SkBitmap(); |
| 376 | 358 |
| 377 if (!filterContext || !filterGrContext) | 359 if (!filterGrContext) |
| 378 return SkBitmap(); | 360 return SkBitmap(); |
| 379 | 361 |
| 380 renderer->context()->flush(); | 362 renderer->context()->flush(); |
| 381 | 363 |
| 382 ResourceProvider::ScopedWriteLockGL lock(renderer->resourceProvider(), sourc
eTexture->id()); | 364 ResourceProvider::ScopedWriteLockGL lock(renderer->resourceProvider(), sourc
eTexture->id()); |
| 383 SkBitmap source = RenderSurfaceFilters::apply(filters, lock.textureId(), sou
rceTexture->size(), filterContext, filterGrContext); | 365 SkBitmap source = RenderSurfaceFilters::apply(filters, lock.textureId(), sou
rceTexture->size(), filterContext, filterGrContext); |
| 384 return source; | 366 return source; |
| 385 } | 367 } |
| 386 | 368 |
| 387 static SkBitmap applyImageFilter(GLRenderer* renderer, SkImageFilter* filter, Sc
opedResource* sourceTexture, bool hasImplThread) | 369 static SkBitmap applyImageFilter(GLRenderer* renderer, SkImageFilter* filter, Sc
opedResource* sourceTexture, WebGraphicsContext3D* filterContext, GrContext* grC
ontext) |
| 388 { | 370 { |
| 389 if (!filter) | 371 if (!filter) |
| 390 return SkBitmap(); | 372 return SkBitmap(); |
| 391 | 373 |
| 392 WebGraphicsContext3D* context3d = getFilterContext(hasImplThread); | 374 if (!filterContext) |
| 393 GrContext* grContext = getFilterGrContext(hasImplThread); | 375 return SkBitmap(); |
| 394 | 376 |
| 395 if (!context3d || !grContext) | 377 if (!grContext) |
| 396 return SkBitmap(); | 378 return SkBitmap(); |
| 397 | 379 |
| 398 renderer->context()->flush(); | |
| 399 | |
| 400 ResourceProvider::ScopedWriteLockGL lock(renderer->resourceProvider(), sourc
eTexture->id()); | 380 ResourceProvider::ScopedWriteLockGL lock(renderer->resourceProvider(), sourc
eTexture->id()); |
| 401 | 381 |
| 402 // Wrap the source texture in a Ganesh platform texture. | 382 // Wrap the source texture in a Ganesh platform texture. |
| 403 GrPlatformTextureDesc platformTextureDescription; | 383 GrPlatformTextureDesc platformTextureDescription; |
| 404 platformTextureDescription.fWidth = sourceTexture->size().width(); | 384 platformTextureDescription.fWidth = sourceTexture->size().width(); |
| 405 platformTextureDescription.fHeight = sourceTexture->size().height(); | 385 platformTextureDescription.fHeight = sourceTexture->size().height(); |
| 406 platformTextureDescription.fConfig = kSkia8888_GrPixelConfig; | 386 platformTextureDescription.fConfig = kSkia8888_GrPixelConfig; |
| 407 platformTextureDescription.fTextureHandle = lock.textureId(); | 387 platformTextureDescription.fTextureHandle = lock.textureId(); |
| 408 skia::RefPtr<GrTexture> texture = skia::AdoptRef(grContext->createPlatformTe
xture(platformTextureDescription)); | 388 skia::RefPtr<GrTexture> texture = skia::AdoptRef(grContext->createPlatformTe
xture(platformTextureDescription)); |
| 409 | 389 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 426 // Create a device and canvas using that backing store. | 406 // Create a device and canvas using that backing store. |
| 427 SkGpuDevice device(grContext, backingStore.get()); | 407 SkGpuDevice device(grContext, backingStore.get()); |
| 428 SkCanvas canvas(&device); | 408 SkCanvas canvas(&device); |
| 429 | 409 |
| 430 // Draw the source bitmap through the filter to the canvas. | 410 // Draw the source bitmap through the filter to the canvas. |
| 431 SkPaint paint; | 411 SkPaint paint; |
| 432 paint.setImageFilter(filter); | 412 paint.setImageFilter(filter); |
| 433 canvas.clear(0x0); | 413 canvas.clear(0x0); |
| 434 canvas.drawSprite(source, 0, 0, &paint); | 414 canvas.drawSprite(source, 0, 0, &paint); |
| 435 canvas.flush(); | 415 canvas.flush(); |
| 436 context3d->flush(); | 416 filterContext->flush(); |
| 437 return device.accessBitmap(false); | 417 return device.accessBitmap(false); |
| 438 } | 418 } |
| 439 | 419 |
| 440 scoped_ptr<ScopedResource> GLRenderer::drawBackgroundFilters( | 420 scoped_ptr<ScopedResource> GLRenderer::drawBackgroundFilters( |
| 441 DrawingFrame& frame, const RenderPassDrawQuad* quad, | 421 DrawingFrame& frame, const RenderPassDrawQuad* quad, |
| 442 const gfx::Transform& contentsDeviceTransform, | 422 const gfx::Transform& contentsDeviceTransform, |
| 443 const gfx::Transform& contentsDeviceTransformInverse) | 423 const gfx::Transform& contentsDeviceTransformInverse) |
| 444 { | 424 { |
| 445 // This method draws a background filter, which applies a filter to any pixe
ls behind the quad and seen through its background. | 425 // This method draws a background filter, which applies a filter to any pixe
ls behind the quad and seen through its background. |
| 446 // The algorithm works as follows: | 426 // The algorithm works as follows: |
| (...skipping 27 matching lines...) Expand all Loading... |
| 474 int top, right, bottom, left; | 454 int top, right, bottom, left; |
| 475 filters.getOutsets(top, right, bottom, left); | 455 filters.getOutsets(top, right, bottom, left); |
| 476 deviceRect.Inset(-left, -top, -right, -bottom); | 456 deviceRect.Inset(-left, -top, -right, -bottom); |
| 477 | 457 |
| 478 deviceRect.Intersect(frame.currentRenderPass->output_rect); | 458 deviceRect.Intersect(frame.currentRenderPass->output_rect); |
| 479 | 459 |
| 480 scoped_ptr<ScopedResource> deviceBackgroundTexture = ScopedResource::create(
m_resourceProvider); | 460 scoped_ptr<ScopedResource> deviceBackgroundTexture = ScopedResource::create(
m_resourceProvider); |
| 481 if (!getFramebufferTexture(deviceBackgroundTexture.get(), deviceRect)) | 461 if (!getFramebufferTexture(deviceBackgroundTexture.get(), deviceRect)) |
| 482 return scoped_ptr<ScopedResource>(); | 462 return scoped_ptr<ScopedResource>(); |
| 483 | 463 |
| 484 SkBitmap filteredDeviceBackground = applyFilters(this, filters, deviceBackgr
oundTexture.get(), m_client->hasImplThread()); | 464 WebKit::WebGraphicsContext3D* filterContext = m_resourceProvider->offscreenG
raphicsContext3d(); |
| 465 GrContext* filterGrContext = m_resourceProvider->offscreenGrContext(); |
| 466 SkBitmap filteredDeviceBackground = applyFilters(this, filters, deviceBackgr
oundTexture.get(), filterContext, filterGrContext); |
| 485 if (!filteredDeviceBackground.getTexture()) | 467 if (!filteredDeviceBackground.getTexture()) |
| 486 return scoped_ptr<ScopedResource>(); | 468 return scoped_ptr<ScopedResource>(); |
| 487 | 469 |
| 488 GrTexture* texture = reinterpret_cast<GrTexture*>(filteredDeviceBackground.g
etTexture()); | 470 GrTexture* texture = reinterpret_cast<GrTexture*>(filteredDeviceBackground.g
etTexture()); |
| 489 int filteredDeviceBackgroundTextureId = texture->getTextureHandle(); | 471 int filteredDeviceBackgroundTextureId = texture->getTextureHandle(); |
| 490 | 472 |
| 491 scoped_ptr<ScopedResource> backgroundTexture = ScopedResource::create(m_reso
urceProvider); | 473 scoped_ptr<ScopedResource> backgroundTexture = ScopedResource::create(m_reso
urceProvider); |
| 492 if (!backgroundTexture->Allocate(quad->rect.size(), GL_RGBA, ResourceProvide
r::TextureUsageFramebuffer)) | 474 if (!backgroundTexture->Allocate(quad->rect.size(), GL_RGBA, ResourceProvide
r::TextureUsageFramebuffer)) |
| 493 return scoped_ptr<ScopedResource>(); | 475 return scoped_ptr<ScopedResource>(); |
| 494 | 476 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 525 // Can only draw surface if device matrix is invertible. | 507 // Can only draw surface if device matrix is invertible. |
| 526 gfx::Transform contentsDeviceTransformInverse(gfx::Transform::kSkipInitializ
ation); | 508 gfx::Transform contentsDeviceTransformInverse(gfx::Transform::kSkipInitializ
ation); |
| 527 if (!contentsDeviceTransform.GetInverse(&contentsDeviceTransformInverse)) | 509 if (!contentsDeviceTransform.GetInverse(&contentsDeviceTransformInverse)) |
| 528 return; | 510 return; |
| 529 | 511 |
| 530 scoped_ptr<ScopedResource> backgroundTexture = drawBackgroundFilters( | 512 scoped_ptr<ScopedResource> backgroundTexture = drawBackgroundFilters( |
| 531 frame, quad, contentsDeviceTransform, contentsDeviceTransformInverse); | 513 frame, quad, contentsDeviceTransform, contentsDeviceTransformInverse); |
| 532 | 514 |
| 533 // FIXME: Cache this value so that we don't have to do it for both the surfa
ce and its replica. | 515 // FIXME: Cache this value so that we don't have to do it for both the surfa
ce and its replica. |
| 534 // Apply filters to the contents texture. | 516 // Apply filters to the contents texture. |
| 517 WebGraphicsContext3D* filterContext = m_resourceProvider->offscreenGraphicsC
ontext3d(); |
| 518 GrContext* filterGrContext = m_resourceProvider->offscreenGrContext(); |
| 535 SkBitmap filterBitmap; | 519 SkBitmap filterBitmap; |
| 536 if (quad->filter) { | 520 if (quad->filter) { |
| 537 filterBitmap = applyImageFilter(this, quad->filter.get(), contentsTextur
e, m_client->hasImplThread()); | 521 filterBitmap = applyImageFilter(this, quad->filter.get(), contentsTextur
e, filterContext, filterGrContext); |
| 538 } else { | 522 } else { |
| 539 filterBitmap = applyFilters(this, quad->filters, contentsTexture, m_clie
nt->hasImplThread()); | 523 filterBitmap = applyFilters(this, quad->filters, contentsTexture, filter
Context, filterGrContext); |
| 540 } | 524 } |
| 541 | 525 |
| 542 // Draw the background texture if there is one. | 526 // Draw the background texture if there is one. |
| 543 if (backgroundTexture) { | 527 if (backgroundTexture) { |
| 544 DCHECK(backgroundTexture->size() == quad->rect.size()); | 528 DCHECK(backgroundTexture->size() == quad->rect.size()); |
| 545 ResourceProvider::ScopedReadLockGL lock(m_resourceProvider, backgroundTe
xture->id()); | 529 ResourceProvider::ScopedReadLockGL lock(m_resourceProvider, backgroundTe
xture->id()); |
| 546 copyTextureToFramebuffer(frame, lock.textureId(), quad->rect, quad->quad
Transform()); | 530 copyTextureToFramebuffer(frame, lock.textureId(), quad->rect, quad->quad
Transform()); |
| 547 } | 531 } |
| 548 | 532 |
| 549 bool clipped = false; | 533 bool clipped = false; |
| (...skipping 1239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1789 | 1773 |
| 1790 releaseRenderPassTextures(); | 1774 releaseRenderPassTextures(); |
| 1791 } | 1775 } |
| 1792 | 1776 |
| 1793 bool GLRenderer::isContextLost() | 1777 bool GLRenderer::isContextLost() |
| 1794 { | 1778 { |
| 1795 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); | 1779 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); |
| 1796 } | 1780 } |
| 1797 | 1781 |
| 1798 } // namespace cc | 1782 } // namespace cc |
| OLD | NEW |