Index: cc/gl_renderer.cc |
diff --git a/cc/gl_renderer.cc b/cc/gl_renderer.cc |
index 7f2ea51859171ac879b7cd51477d0689353f6ec7..5d5e6ac8481edcbd3ee8e5a4ab947ddf00c71e90 100644 |
--- a/cc/gl_renderer.cc |
+++ b/cc/gl_renderer.cc |
@@ -20,8 +20,11 @@ |
#include "CCVideoLayerImpl.h" |
#include "FloatQuad.h" |
#include "GrTexture.h" |
+#include "GrContext.h" |
#include "NotImplemented.h" |
#include "base/debug/trace_event.h" |
+#include "SkGrTexturePixelRef.h" |
danakj
2012/10/19 19:34:24
nit: sorting
Stephen White
2012/10/19 21:34:50
Done.
|
+#include "SkGpuDevice.h" |
#include "base/string_split.h" |
#include "base/string_util.h" |
#include "base/logging.h" |
@@ -346,6 +349,57 @@ static inline SkBitmap applyFilters(CCRendererGL* renderer, const WebKit::WebFil |
return source; |
} |
+static SkBitmap applyFilter(CCRendererGL* renderer, SkImageFilter* filter, CCScopedTexture* 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
|
+{ |
+ if (!filter) |
+ return SkBitmap(); |
+ |
+ WebGraphicsContext3D* context3d = CCProxy::hasImplThread() ? WebSharedGraphicsContext3D::compositorThreadContext() : WebSharedGraphicsContext3D::mainThreadContext(); |
+ 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
|
+ |
+ if (!context3d || !grContext) |
+ return SkBitmap(); |
+ |
+ renderer->context()->flush(); |
+ |
+ CCResourceProvider::ScopedWriteLockGL lock(renderer->resourceProvider(), sourceTexture->id()); |
+ |
+ // Wrap the source texture in a Ganesh platform texture. |
+ GrPlatformTextureDesc platformTextureDescription; |
+ platformTextureDescription.fWidth = sourceTexture->size().width(); |
+ platformTextureDescription.fHeight = sourceTexture->size().height(); |
+ platformTextureDescription.fConfig = kSkia8888_GrPixelConfig; |
+ platformTextureDescription.fTextureHandle = lock.textureId(); |
+ SkAutoTUnref<GrTexture> texture(grContext->createPlatformTexture(platformTextureDescription)); |
+ |
+ // Place the platform texture inside an SkBitmap. |
+ SkBitmap source; |
+ source.setConfig(SkBitmap::kARGB_8888_Config, sourceTexture->size().width(), sourceTexture->size().height()); |
+ source.setPixelRef(new SkGrPixelRef(texture.get()))->unref(); |
+ |
+ // Create a scratch texture for backing store. |
+ GrTextureDesc desc; |
+ desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; |
+ desc.fSampleCnt = 0; |
+ desc.fWidth = source.width(); |
+ desc.fHeight = source.height(); |
+ desc.fConfig = kSkia8888_GrPixelConfig; |
+ GrAutoScratchTexture scratchTexture(grContext, desc, GrContext::kExact_ScratchTexMatch); |
+ |
+ // Create a device and canvas using that backing store. |
+ SkGpuDevice device(grContext, scratchTexture.detach()); |
+ SkCanvas canvas(&device); |
+ |
+ // Draw the source bitmap through the filter to the canvas. |
+ SkPaint paint; |
+ paint.setImageFilter(filter); |
+ canvas.clear(0x0); |
+ canvas.drawSprite(source, 0, 0, &paint); |
+ canvas.flush(); |
+ context3d->flush(); |
+ return device.accessBitmap(false); |
+} |
+ |
scoped_ptr<CCScopedTexture> CCRendererGL::drawBackgroundFilters(DrawingFrame& frame, const CCRenderPassDrawQuad* quad, const WebKit::WebFilterOperations& filters, const WebTransformationMatrix& contentsDeviceTransform) |
{ |
// This method draws a background filter, which applies a filter to any pixels behind the quad and seen through its background. |
@@ -440,7 +494,12 @@ void CCRendererGL::drawRenderPassQuad(DrawingFrame& frame, const CCRenderPassDra |
// FIXME: Cache this value so that we don't have to do it for both the surface and its replica. |
// Apply filters to the contents texture. |
- SkBitmap filterBitmap = applyFilters(this, renderPass->filters(), contentsTexture); |
+ SkBitmap filterBitmap; |
+ if (renderPass->filter()) { |
+ filterBitmap = applyFilter(this, renderPass->filter(), contentsTexture); |
+ } else { |
+ filterBitmap = applyFilters(this, renderPass->filters(), contentsTexture); |
+ } |
scoped_ptr<CCResourceProvider::ScopedReadLockGL> contentsResourceLock; |
unsigned contentsTextureId = 0; |
if (filterBitmap.getTexture()) { |