Index: cc/gl_renderer.cc |
diff --git a/cc/gl_renderer.cc b/cc/gl_renderer.cc |
index 51d46f529c64d1b54f178b43885f25f410e805b4..192f0df0ae769559e7f0d5e39351174d02d7fee1 100644 |
--- a/cc/gl_renderer.cc |
+++ b/cc/gl_renderer.cc |
@@ -9,8 +9,11 @@ |
#include "CCDamageTracker.h" |
#include "CCLayerQuad.h" |
#include "FloatQuad.h" |
+#include "GrContext.h" |
#include "GrTexture.h" |
#include "NotImplemented.h" |
+#include "SkGpuDevice.h" |
+#include "SkGrTexturePixelRef.h" |
#include "base/debug/trace_event.h" |
#include "base/logging.h" |
#include "base/string_split.h" |
@@ -349,6 +352,57 @@ static inline SkBitmap applyFilters(CCRendererGL* renderer, const WebKit::WebFil |
return source; |
} |
+static SkBitmap applyImageFilter(CCRendererGL* renderer, SkImageFilter* filter, CCScopedTexture* sourceTexture) |
+{ |
+ if (!filter) |
+ return SkBitmap(); |
+ |
+ WebGraphicsContext3D* context3d = CCProxy::hasImplThread() ? WebSharedGraphicsContext3D::compositorThreadContext() : WebSharedGraphicsContext3D::mainThreadContext(); |
+ GrContext* grContext = CCProxy::hasImplThread() ? WebSharedGraphicsContext3D::compositorThreadGrContext() : WebSharedGraphicsContext3D::mainThreadGrContext(); |
+ |
+ 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. |
@@ -442,7 +496,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 = applyImageFilter(this, renderPass->filter(), contentsTexture); |
+ } else { |
+ filterBitmap = applyFilters(this, renderPass->filters(), contentsTexture); |
+ } |
scoped_ptr<CCResourceProvider::ScopedReadLockGL> contentsResourceLock; |
unsigned contentsTextureId = 0; |
if (filterBitmap.getTexture()) { |