Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(579)

Side by Side Diff: cc/gl_renderer.cc

Issue 11175009: Implement SkImageFilter support in the compositor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add damage tracker test, fix braces, include order. Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "cc/gl_renderer.h" 7 #include "cc/gl_renderer.h"
8 8
9 #include "CCDamageTracker.h" 9 #include "CCDamageTracker.h"
10 #include "CCLayerQuad.h" 10 #include "CCLayerQuad.h"
11 #include "FloatQuad.h" 11 #include "FloatQuad.h"
12 #include "GrContext.h"
12 #include "GrTexture.h" 13 #include "GrTexture.h"
13 #include "NotImplemented.h" 14 #include "NotImplemented.h"
15 #include "SkGpuDevice.h"
16 #include "SkGrTexturePixelRef.h"
14 #include "base/debug/trace_event.h" 17 #include "base/debug/trace_event.h"
15 #include "base/logging.h" 18 #include "base/logging.h"
16 #include "base/string_split.h" 19 #include "base/string_split.h"
17 #include "base/string_util.h" 20 #include "base/string_util.h"
18 #include "cc/geometry_binding.h" 21 #include "cc/geometry_binding.h"
19 #include "cc/math_util.h" 22 #include "cc/math_util.h"
20 #include "cc/platform_color.h" 23 #include "cc/platform_color.h"
21 #include "cc/proxy.h" 24 #include "cc/proxy.h"
22 #include "cc/render_pass.h" 25 #include "cc/render_pass.h"
23 #include "cc/render_surface_filters.h" 26 #include "cc/render_surface_filters.h"
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 if (!filterContext || !filterGrContext) 345 if (!filterContext || !filterGrContext)
343 return SkBitmap(); 346 return SkBitmap();
344 347
345 renderer->context()->flush(); 348 renderer->context()->flush();
346 349
347 CCResourceProvider::ScopedWriteLockGL lock(renderer->resourceProvider(), sou rceTexture->id()); 350 CCResourceProvider::ScopedWriteLockGL lock(renderer->resourceProvider(), sou rceTexture->id());
348 SkBitmap source = CCRenderSurfaceFilters::apply(filters, lock.textureId(), s ourceTexture->size(), filterContext, filterGrContext); 351 SkBitmap source = CCRenderSurfaceFilters::apply(filters, lock.textureId(), s ourceTexture->size(), filterContext, filterGrContext);
349 return source; 352 return source;
350 } 353 }
351 354
355 static SkBitmap applyImageFilter(CCRendererGL* renderer, SkImageFilter* filter, CCScopedTexture* sourceTexture)
356 {
357 if (!filter)
358 return SkBitmap();
359
360 WebGraphicsContext3D* context3d = CCProxy::hasImplThread() ? WebSharedGraphi csContext3D::compositorThreadContext() : WebSharedGraphicsContext3D::mainThreadC ontext();
361 GrContext* grContext = CCProxy::hasImplThread() ? WebSharedGraphicsContext3D ::compositorThreadGrContext() : WebSharedGraphicsContext3D::mainThreadGrContext( );
jamesr 2012/10/22 19:14:17 please refactor this to share code with lines 342-
Stephen White 2012/10/22 20:11:20 Done.
362
363 if (!context3d || !grContext)
364 return SkBitmap();
365
366 renderer->context()->flush();
367
368 CCResourceProvider::ScopedWriteLockGL lock(renderer->resourceProvider(), sou rceTexture->id());
369
370 // Wrap the source texture in a Ganesh platform texture.
371 GrPlatformTextureDesc platformTextureDescription;
372 platformTextureDescription.fWidth = sourceTexture->size().width();
373 platformTextureDescription.fHeight = sourceTexture->size().height();
374 platformTextureDescription.fConfig = kSkia8888_GrPixelConfig;
375 platformTextureDescription.fTextureHandle = lock.textureId();
376 SkAutoTUnref<GrTexture> texture(grContext->createPlatformTexture(platformTex tureDescription));
377
378 // Place the platform texture inside an SkBitmap.
379 SkBitmap source;
380 source.setConfig(SkBitmap::kARGB_8888_Config, sourceTexture->size().width(), sourceTexture->size().height());
381 source.setPixelRef(new SkGrPixelRef(texture.get()))->unref();
382
383 // Create a scratch texture for backing store.
384 GrTextureDesc desc;
385 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
386 desc.fSampleCnt = 0;
387 desc.fWidth = source.width();
388 desc.fHeight = source.height();
389 desc.fConfig = kSkia8888_GrPixelConfig;
390 GrAutoScratchTexture scratchTexture(grContext, desc, GrContext::kExact_Scrat chTexMatch);
391
392 // Create a device and canvas using that backing store.
393 SkGpuDevice device(grContext, scratchTexture.detach());
394 SkCanvas canvas(&device);
395
396 // Draw the source bitmap through the filter to the canvas.
397 SkPaint paint;
398 paint.setImageFilter(filter);
399 canvas.clear(0x0);
400 canvas.drawSprite(source, 0, 0, &paint);
401 canvas.flush();
402 context3d->flush();
403 return device.accessBitmap(false);
404 }
405
352 scoped_ptr<CCScopedTexture> CCRendererGL::drawBackgroundFilters(DrawingFrame& fr ame, const CCRenderPassDrawQuad* quad, const WebKit::WebFilterOperations& filter s, const WebTransformationMatrix& contentsDeviceTransform) 406 scoped_ptr<CCScopedTexture> CCRendererGL::drawBackgroundFilters(DrawingFrame& fr ame, const CCRenderPassDrawQuad* quad, const WebKit::WebFilterOperations& filter s, const WebTransformationMatrix& contentsDeviceTransform)
353 { 407 {
354 // This method draws a background filter, which applies a filter to any pixe ls behind the quad and seen through its background. 408 // This method draws a background filter, which applies a filter to any pixe ls behind the quad and seen through its background.
355 // The algorithm works as follows: 409 // The algorithm works as follows:
356 // 1. Compute a bounding box around the pixels that will be visible through the quad. 410 // 1. Compute a bounding box around the pixels that will be visible through the quad.
357 // 2. Read the pixels in the bounding box into a buffer R. 411 // 2. Read the pixels in the bounding box into a buffer R.
358 // 3. Apply the background filter to R, so that it is applied in the pixels' coordinate space. 412 // 3. Apply the background filter to R, so that it is applied in the pixels' coordinate space.
359 // 4. Apply the quad's inverse transform to map the pixels in R into the qua d's content space. This implicitly 413 // 4. Apply the quad's inverse transform to map the pixels in R into the qua d's content space. This implicitly
360 // clips R by the content bounds of the quad since the destination texture h as bounds matching the quad's content. 414 // clips R by the content bounds of the quad since the destination texture h as bounds matching the quad's content.
361 // 5. Draw the background texture for the contents using the same transform as used to draw the contents itself. This is done 415 // 5. Draw the background texture for the contents using the same transform as used to draw the contents itself. This is done
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 WebTransformationMatrix contentsDeviceTransform = (frame.windowMatrix * fram e.projectionMatrix * quadRectMatrix).to2dTransform(); 489 WebTransformationMatrix contentsDeviceTransform = (frame.windowMatrix * fram e.projectionMatrix * quadRectMatrix).to2dTransform();
436 490
437 // Can only draw surface if device matrix is invertible. 491 // Can only draw surface if device matrix is invertible.
438 if (!contentsDeviceTransform.isInvertible()) 492 if (!contentsDeviceTransform.isInvertible())
439 return; 493 return;
440 494
441 scoped_ptr<CCScopedTexture> backgroundTexture = drawBackgroundFilters(frame, quad, renderPass->backgroundFilters(), contentsDeviceTransform); 495 scoped_ptr<CCScopedTexture> backgroundTexture = drawBackgroundFilters(frame, quad, renderPass->backgroundFilters(), contentsDeviceTransform);
442 496
443 // FIXME: Cache this value so that we don't have to do it for both the surfa ce and its replica. 497 // FIXME: Cache this value so that we don't have to do it for both the surfa ce and its replica.
444 // Apply filters to the contents texture. 498 // Apply filters to the contents texture.
445 SkBitmap filterBitmap = applyFilters(this, renderPass->filters(), contentsTe xture); 499 SkBitmap filterBitmap;
500 if (renderPass->filter()) {
501 filterBitmap = applyImageFilter(this, renderPass->filter(), contentsText ure);
502 } else {
jamesr 2012/10/22 19:14:17 same comment here re 'else'
Stephen White 2012/10/22 20:11:20 Done in setFilter()/setFilters() (see above).
503 filterBitmap = applyFilters(this, renderPass->filters(), contentsTexture );
504 }
446 scoped_ptr<CCResourceProvider::ScopedReadLockGL> contentsResourceLock; 505 scoped_ptr<CCResourceProvider::ScopedReadLockGL> contentsResourceLock;
447 unsigned contentsTextureId = 0; 506 unsigned contentsTextureId = 0;
448 if (filterBitmap.getTexture()) { 507 if (filterBitmap.getTexture()) {
449 GrTexture* texture = reinterpret_cast<GrTexture*>(filterBitmap.getTextur e()); 508 GrTexture* texture = reinterpret_cast<GrTexture*>(filterBitmap.getTextur e());
450 contentsTextureId = texture->getTextureHandle(); 509 contentsTextureId = texture->getTextureHandle();
451 } else { 510 } else {
452 contentsResourceLock = make_scoped_ptr(new CCResourceProvider::ScopedRea dLockGL(m_resourceProvider, contentsTexture->id())); 511 contentsResourceLock = make_scoped_ptr(new CCResourceProvider::ScopedRea dLockGL(m_resourceProvider, contentsTexture->id()));
453 contentsTextureId = contentsResourceLock->textureId(); 512 contentsTextureId = contentsResourceLock->textureId();
454 } 513 }
455 514
(...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after
1513 1572
1514 releaseRenderPassTextures(); 1573 releaseRenderPassTextures();
1515 } 1574 }
1516 1575
1517 bool CCRendererGL::isContextLost() 1576 bool CCRendererGL::isContextLost()
1518 { 1577 {
1519 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); 1578 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR);
1520 } 1579 }
1521 1580
1522 } // namespace cc 1581 } // namespace cc
OLDNEW
« cc/damage_tracker_unittest.cc ('K') | « cc/damage_tracker_unittest.cc ('k') | cc/layer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698