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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "CCRendererGL.h" | 7 #include "CCRendererGL.h" |
8 | 8 |
9 #include "third_party/khronos/GLES2/gl2.h" | 9 #include "third_party/khronos/GLES2/gl2.h" |
10 #include "third_party/khronos/GLES2/gl2ext.h" | 10 #include "third_party/khronos/GLES2/gl2ext.h" |
11 #include "CCDamageTracker.h" | 11 #include "CCDamageTracker.h" |
12 #include "CCLayerQuad.h" | 12 #include "CCLayerQuad.h" |
13 #include "CCMathUtil.h" | 13 #include "CCMathUtil.h" |
14 #include "CCProxy.h" | 14 #include "CCProxy.h" |
15 #include "CCRenderPass.h" | 15 #include "CCRenderPass.h" |
16 #include "CCRenderSurfaceFilters.h" | 16 #include "CCRenderSurfaceFilters.h" |
17 #include "CCScopedTexture.h" | 17 #include "CCScopedTexture.h" |
18 #include "CCSettings.h" | 18 #include "CCSettings.h" |
19 #include "CCSingleThreadProxy.h" | 19 #include "CCSingleThreadProxy.h" |
20 #include "CCVideoLayerImpl.h" | 20 #include "CCVideoLayerImpl.h" |
21 #include "FloatQuad.h" | 21 #include "FloatQuad.h" |
22 #include "GrTexture.h" | 22 #include "GrTexture.h" |
23 #include "GrContext.h" | |
23 #include "NotImplemented.h" | 24 #include "NotImplemented.h" |
24 #include "base/debug/trace_event.h" | 25 #include "base/debug/trace_event.h" |
26 #include "SkGrTexturePixelRef.h" | |
danakj
2012/10/19 19:34:24
nit: sorting
Stephen White
2012/10/19 21:34:50
Done.
| |
27 #include "SkGpuDevice.h" | |
25 #include "base/string_split.h" | 28 #include "base/string_split.h" |
26 #include "base/string_util.h" | 29 #include "base/string_util.h" |
27 #include "base/logging.h" | 30 #include "base/logging.h" |
28 #include "cc/geometry_binding.h" | 31 #include "cc/geometry_binding.h" |
29 #include "cc/platform_color.h" | 32 #include "cc/platform_color.h" |
30 #include "third_party/skia/include/core/SkBitmap.h" | 33 #include "third_party/skia/include/core/SkBitmap.h" |
31 #include "third_party/skia/include/core/SkColor.h" | 34 #include "third_party/skia/include/core/SkColor.h" |
32 #include <public/WebGraphicsContext3D.h> | 35 #include <public/WebGraphicsContext3D.h> |
33 #include <public/WebSharedGraphicsContext3D.h> | 36 #include <public/WebSharedGraphicsContext3D.h> |
34 #include <public/WebVideoFrame.h> | 37 #include <public/WebVideoFrame.h> |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
339 if (!filterContext || !filterGrContext) | 342 if (!filterContext || !filterGrContext) |
340 return SkBitmap(); | 343 return SkBitmap(); |
341 | 344 |
342 renderer->context()->flush(); | 345 renderer->context()->flush(); |
343 | 346 |
344 CCResourceProvider::ScopedWriteLockGL lock(renderer->resourceProvider(), sou rceTexture->id()); | 347 CCResourceProvider::ScopedWriteLockGL lock(renderer->resourceProvider(), sou rceTexture->id()); |
345 SkBitmap source = CCRenderSurfaceFilters::apply(filters, lock.textureId(), s ourceTexture->size(), filterContext, filterGrContext); | 348 SkBitmap source = CCRenderSurfaceFilters::apply(filters, lock.textureId(), s ourceTexture->size(), filterContext, filterGrContext); |
346 return source; | 349 return source; |
347 } | 350 } |
348 | 351 |
352 static SkBitmap applyFilter(CCRendererGL* renderer, SkImageFilter* filter, CCSco pedTexture* sourceTexture) | |
danakj
2012/10/19 19:34:24
can we rename this to applyImageFilter?
Stephen White
2012/10/19 21:34:50
(I think I convinced Dana offline to let me keep i
| |
353 { | |
354 if (!filter) | |
355 return SkBitmap(); | |
356 | |
357 WebGraphicsContext3D* context3d = CCProxy::hasImplThread() ? WebSharedGraphi csContext3D::compositorThreadContext() : WebSharedGraphicsContext3D::mainThreadC ontext(); | |
358 GrContext* grContext = CCProxy::hasImplThread() ? WebSharedGraphicsContext3D ::compositorThreadGrContext() : WebSharedGraphicsContext3D::mainThreadGrContext( ); | |
jamesr
2012/10/19 19:15:30
this is exactly the same (with different variable
Stephen White
2012/10/19 21:34:50
My goal is that when this is done, we'll just rip
| |
359 | |
360 if (!context3d || !grContext) | |
361 return SkBitmap(); | |
362 | |
363 renderer->context()->flush(); | |
364 | |
365 CCResourceProvider::ScopedWriteLockGL lock(renderer->resourceProvider(), sou rceTexture->id()); | |
366 | |
367 // Wrap the source texture in a Ganesh platform texture. | |
368 GrPlatformTextureDesc platformTextureDescription; | |
369 platformTextureDescription.fWidth = sourceTexture->size().width(); | |
370 platformTextureDescription.fHeight = sourceTexture->size().height(); | |
371 platformTextureDescription.fConfig = kSkia8888_GrPixelConfig; | |
372 platformTextureDescription.fTextureHandle = lock.textureId(); | |
373 SkAutoTUnref<GrTexture> texture(grContext->createPlatformTexture(platformTex tureDescription)); | |
374 | |
375 // Place the platform texture inside an SkBitmap. | |
376 SkBitmap source; | |
377 source.setConfig(SkBitmap::kARGB_8888_Config, sourceTexture->size().width(), sourceTexture->size().height()); | |
378 source.setPixelRef(new SkGrPixelRef(texture.get()))->unref(); | |
379 | |
380 // Create a scratch texture for backing store. | |
381 GrTextureDesc desc; | |
382 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; | |
383 desc.fSampleCnt = 0; | |
384 desc.fWidth = source.width(); | |
385 desc.fHeight = source.height(); | |
386 desc.fConfig = kSkia8888_GrPixelConfig; | |
387 GrAutoScratchTexture scratchTexture(grContext, desc, GrContext::kExact_Scrat chTexMatch); | |
388 | |
389 // Create a device and canvas using that backing store. | |
390 SkGpuDevice device(grContext, scratchTexture.detach()); | |
391 SkCanvas canvas(&device); | |
392 | |
393 // Draw the source bitmap through the filter to the canvas. | |
394 SkPaint paint; | |
395 paint.setImageFilter(filter); | |
396 canvas.clear(0x0); | |
397 canvas.drawSprite(source, 0, 0, &paint); | |
398 canvas.flush(); | |
399 context3d->flush(); | |
400 return device.accessBitmap(false); | |
401 } | |
402 | |
349 scoped_ptr<CCScopedTexture> CCRendererGL::drawBackgroundFilters(DrawingFrame& fr ame, const CCRenderPassDrawQuad* quad, const WebKit::WebFilterOperations& filter s, const WebTransformationMatrix& contentsDeviceTransform) | 403 scoped_ptr<CCScopedTexture> CCRendererGL::drawBackgroundFilters(DrawingFrame& fr ame, const CCRenderPassDrawQuad* quad, const WebKit::WebFilterOperations& filter s, const WebTransformationMatrix& contentsDeviceTransform) |
350 { | 404 { |
351 // This method draws a background filter, which applies a filter to any pixe ls behind the quad and seen through its background. | 405 // This method draws a background filter, which applies a filter to any pixe ls behind the quad and seen through its background. |
352 // The algorithm works as follows: | 406 // The algorithm works as follows: |
353 // 1. Compute a bounding box around the pixels that will be visible through the quad. | 407 // 1. Compute a bounding box around the pixels that will be visible through the quad. |
354 // 2. Read the pixels in the bounding box into a buffer R. | 408 // 2. Read the pixels in the bounding box into a buffer R. |
355 // 3. Apply the background filter to R, so that it is applied in the pixels' coordinate space. | 409 // 3. Apply the background filter to R, so that it is applied in the pixels' coordinate space. |
356 // 4. Apply the quad's inverse transform to map the pixels in R into the qua d's content space. This implicitly | 410 // 4. Apply the quad's inverse transform to map the pixels in R into the qua d's content space. This implicitly |
357 // clips R by the content bounds of the quad since the destination texture h as bounds matching the quad's content. | 411 // clips R by the content bounds of the quad since the destination texture h as bounds matching the quad's content. |
358 // 5. Draw the background texture for the contents using the same transform as used to draw the contents itself. This is done | 412 // 5. Draw the background texture for the contents using the same transform as used to draw the contents itself. This is done |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
433 WebTransformationMatrix contentsDeviceTransform = (frame.windowMatrix * fram e.projectionMatrix * quadRectMatrix).to2dTransform(); | 487 WebTransformationMatrix contentsDeviceTransform = (frame.windowMatrix * fram e.projectionMatrix * quadRectMatrix).to2dTransform(); |
434 | 488 |
435 // Can only draw surface if device matrix is invertible. | 489 // Can only draw surface if device matrix is invertible. |
436 if (!contentsDeviceTransform.isInvertible()) | 490 if (!contentsDeviceTransform.isInvertible()) |
437 return; | 491 return; |
438 | 492 |
439 scoped_ptr<CCScopedTexture> backgroundTexture = drawBackgroundFilters(frame, quad, renderPass->backgroundFilters(), contentsDeviceTransform); | 493 scoped_ptr<CCScopedTexture> backgroundTexture = drawBackgroundFilters(frame, quad, renderPass->backgroundFilters(), contentsDeviceTransform); |
440 | 494 |
441 // FIXME: Cache this value so that we don't have to do it for both the surfa ce and its replica. | 495 // FIXME: Cache this value so that we don't have to do it for both the surfa ce and its replica. |
442 // Apply filters to the contents texture. | 496 // Apply filters to the contents texture. |
443 SkBitmap filterBitmap = applyFilters(this, renderPass->filters(), contentsTe xture); | 497 SkBitmap filterBitmap; |
498 if (renderPass->filter()) { | |
499 filterBitmap = applyFilter(this, renderPass->filter(), contentsTexture); | |
500 } else { | |
501 filterBitmap = applyFilters(this, renderPass->filters(), contentsTexture ); | |
502 } | |
444 scoped_ptr<CCResourceProvider::ScopedReadLockGL> contentsResourceLock; | 503 scoped_ptr<CCResourceProvider::ScopedReadLockGL> contentsResourceLock; |
445 unsigned contentsTextureId = 0; | 504 unsigned contentsTextureId = 0; |
446 if (filterBitmap.getTexture()) { | 505 if (filterBitmap.getTexture()) { |
447 GrTexture* texture = reinterpret_cast<GrTexture*>(filterBitmap.getTextur e()); | 506 GrTexture* texture = reinterpret_cast<GrTexture*>(filterBitmap.getTextur e()); |
448 contentsTextureId = texture->getTextureHandle(); | 507 contentsTextureId = texture->getTextureHandle(); |
449 } else { | 508 } else { |
450 contentsResourceLock = make_scoped_ptr(new CCResourceProvider::ScopedRea dLockGL(m_resourceProvider, contentsTexture->id())); | 509 contentsResourceLock = make_scoped_ptr(new CCResourceProvider::ScopedRea dLockGL(m_resourceProvider, contentsTexture->id())); |
451 contentsTextureId = contentsResourceLock->textureId(); | 510 contentsTextureId = contentsResourceLock->textureId(); |
452 } | 511 } |
453 | 512 |
(...skipping 1058 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1512 | 1571 |
1513 releaseRenderPassTextures(); | 1572 releaseRenderPassTextures(); |
1514 } | 1573 } |
1515 | 1574 |
1516 bool CCRendererGL::isContextLost() | 1575 bool CCRendererGL::isContextLost() |
1517 { | 1576 { |
1518 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); | 1577 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); |
1519 } | 1578 } |
1520 | 1579 |
1521 } // namespace cc | 1580 } // namespace cc |
OLD | NEW |