Source/WebCore/ChangeLog

 12011-12-14 Adrienne Walker <enne@google.com>
 2
 3 [chromium] Refactor tile drawing to be more data-driven
 4 https://bugs.webkit.org/show_bug.cgi?id=73059
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Partially tested by compositor layout tests. Debug borders and
 9 checkerboarding tested manually.
 10
 11 This is the first part of a move towards rendering quads on screen
 12 from a bag of data rather than in virtual CCLayerImpl::draw functions.
 13
 14 CCDrawQuad-derived classes store material-specific pieces of data to
 15 use when rendering. CCLayerImpl classes now create these CCDrawQuad
 16 objects rather than issuing direct GL commands. Where this data is
 17 shared between quads that come from the same layer, that data is
 18 stored in a CCSharedQuadState object rather than duplicated.
 19
 20 CCRenderPass is the class that holds the list of quads and the target
 21 surface that they draw into. Drawing a frame consists of drawing a
 22 series of render passes onto their respective surfaces.
 23
 24 CCLayerTreeHostImpl constructs these render passes from the output of
 25 calculateDrawTransformsAndVisibility by asking each layer to insert
 26 quads into a list and hands them off to LayerRendererChromium for
 27 rendering.
 28
 29 * WebCore.gypi:
 30 * platform/graphics/chromium/LayerRendererChromium.cpp:
 31 (WebCore::LayerRendererChromium::clearSurfaceForDebug):
 32 (WebCore::LayerRendererChromium::beginDrawingFrame):
 33 (WebCore::LayerRendererChromium::drawRenderPass):
 34 (WebCore::LayerRendererChromium::drawQuad):
 35 (WebCore::LayerRendererChromium::drawDebugBorderQuad):
 36 (WebCore::LayerRendererChromium::drawRenderSurfaceQuad):
 37 (WebCore::LayerRendererChromium::drawSolidColorQuad):
 38 (WebCore::tileUniformLocation):
 39 (WebCore::findTileProgramUniforms):
 40 (WebCore::LayerRendererChromium::drawTileQuad):
 41 (WebCore::LayerRendererChromium::drawCustomLayerQuad):
 42 (WebCore::LayerRendererChromium::finishDrawingFrame):
 43 (WebCore::LayerRendererChromium::useRenderSurface):
 44 * platform/graphics/chromium/LayerRendererChromium.h:
 45 * platform/graphics/chromium/ShaderChromium.h:
 46 (WebCore::FragmentTexAlphaBinding::edgeLocation):
 47 (WebCore::FragmentTexAlphaBinding::fragmentTexTransformLocation):
 48 (WebCore::FragmentTexOpaqueBinding::edgeLocation):
 49 (WebCore::FragmentTexOpaqueBinding::fragmentTexTransformLocation):
 50 * platform/graphics/chromium/TiledLayerChromium.cpp:
 51 (WebCore::TiledLayerChromium::pushPropertiesTo):
 52 * platform/graphics/chromium/cc/CCCustomLayerDrawQuad.cpp: Added.
 53 (WebCore::CCCustomLayerDrawQuad::create):
 54 (WebCore::CCCustomLayerDrawQuad::CCCustomLayerDrawQuad):
 55 * platform/graphics/chromium/cc/CCCustomLayerDrawQuad.h: Added.
 56 (WebCore::CCCustomLayerDrawQuad::layer):
 57 * platform/graphics/chromium/cc/CCDebugBorderDrawQuad.cpp: Added.
 58 (WebCore::CCDebugBorderDrawQuad::create):
 59 (WebCore::CCDebugBorderDrawQuad::CCDebugBorderDrawQuad):
 60 * platform/graphics/chromium/cc/CCDebugBorderDrawQuad.h: Added.
 61 (WebCore::CCDebugBorderDrawQuad::color):
 62 (WebCore::CCDebugBorderDrawQuad::width):
 63 * platform/graphics/chromium/cc/CCDrawQuad.cpp: Added.
 64 (WebCore::CCDrawQuad::CCDrawQuad):
 65 (WebCore::CCDrawQuad::toDebugBorderDrawQuad):
 66 (WebCore::CCDrawQuad::toRenderSurfaceDrawQuad):
 67 (WebCore::CCDrawQuad::toSolidColorDrawQuad):
 68 (WebCore::CCDrawQuad::toTileDrawQuad):
 69 (WebCore::CCDrawQuad::toCustomLayerDrawQuad):
 70 * platform/graphics/chromium/cc/CCDrawQuad.h: Added.
 71 (WebCore::CCDrawQuad::quadRect):
 72 (WebCore::CCDrawQuad::quadTransform):
 73 (WebCore::CCDrawQuad::layerTransform):
 74 (WebCore::CCDrawQuad::layerRect):
 75 (WebCore::CCDrawQuad::clipRect):
 76 (WebCore::CCDrawQuad::opacity):
 77 (WebCore::CCDrawQuad::drawsOpaque):
 78 (WebCore::CCDrawQuad::needsBlending):
 79 (WebCore::CCDrawQuad::isLayerAxisAlignedIntRect):
 80 (WebCore::CCDrawQuad::material):
 81 * platform/graphics/chromium/cc/CCLayerImpl.cpp:
 82 (WebCore::CCLayerImpl::createSharedQuadState):
 83 (WebCore::CCLayerImpl::appendQuads):
 84 (WebCore::CCLayerImpl::appendDebugBorderQuad):
 85 (WebCore::CCLayerImpl::quadTransform):
 86 * platform/graphics/chromium/cc/CCLayerImpl.h:
 87 * platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp:
 88 (WebCore::CCLayerTreeHostImpl::trackDamageForAllSurfaces):
 89 (WebCore::computeScreenSpaceTransformForSurface):
 90 (WebCore::damageInSurfaceSpace):
 91 (WebCore::CCLayerTreeHostImpl::calculateRenderPasses):
 92 (WebCore::CCLayerTreeHostImpl::drawLayers):
 93 * platform/graphics/chromium/cc/CCLayerTreeHostImpl.h:
 94 * platform/graphics/chromium/cc/CCRenderPass.cpp: Added.
 95 (WebCore::CCRenderPass::create):
 96 (WebCore::CCRenderPass::CCRenderPass):
 97 (WebCore::CCRenderPass::appendQuadsForLayer):
 98 (WebCore::CCRenderPass::appendQuadsForRenderSurfaceLayer):
 99 * platform/graphics/chromium/cc/CCRenderPass.h: Added.
 100 (WebCore::CCRenderPass::quadList):
 101 (WebCore::CCRenderPass::targetSurface):
 102 (WebCore::CCRenderPass::setSurfaceDamageRect):
 103 (WebCore::CCRenderPass::surfaceDamageRect):
 104 * platform/graphics/chromium/cc/CCRenderSurfaceDrawQuad.cpp: Added.
 105 (WebCore::CCRenderSurfaceDrawQuad::create):
 106 (WebCore::CCRenderSurfaceDrawQuad::CCRenderSurfaceDrawQuad):
 107 * platform/graphics/chromium/cc/CCRenderSurfaceDrawQuad.h: Added.
 108 (WebCore::CCRenderSurfaceDrawQuad::layer):
 109 (WebCore::CCRenderSurfaceDrawQuad::surfaceDamageRect):
 110 * platform/graphics/chromium/cc/CCSharedQuadState.cpp: Added.
 111 (WebCore::CCSharedQuadState::create):
 112 (WebCore::CCSharedQuadState::CCSharedQuadState):
 113 (WebCore::CCSharedQuadState::isLayerAxisAlignedIntRect):
 114 * platform/graphics/chromium/cc/CCSharedQuadState.h: Added.
 115 (WebCore::CCSharedQuadState::quadTransform):
 116 (WebCore::CCSharedQuadState::layerTransform):
 117 (WebCore::CCSharedQuadState::layerRect):
 118 (WebCore::CCSharedQuadState::clipRect):
 119 (WebCore::CCSharedQuadState::opacity):
 120 (WebCore::CCSharedQuadState::isOpaque):
 121 * platform/graphics/chromium/cc/CCSolidColorDrawQuad.cpp: Added.
 122 (WebCore::CCSolidColorDrawQuad::create):
 123 (WebCore::CCSolidColorDrawQuad::CCSolidColorDrawQuad):
 124 * platform/graphics/chromium/cc/CCSolidColorDrawQuad.h: Added.
 125 (WebCore::CCSolidColorDrawQuad::color):
 126 * platform/graphics/chromium/cc/CCTileDrawQuad.cpp: Added.
 127 (WebCore::CCTileDrawQuad::create):
 128 (WebCore::CCTileDrawQuad::CCTileDrawQuad):
 129 * platform/graphics/chromium/cc/CCTileDrawQuad.h: Added.
 130 (WebCore::CCTileDrawQuad::textureId):
 131 (WebCore::CCTileDrawQuad::textureOffset):
 132 (WebCore::CCTileDrawQuad::textureSize):
 133 (WebCore::CCTileDrawQuad::textureFilter):
 134 (WebCore::CCTileDrawQuad::swizzleContents):
 135 (WebCore::CCTileDrawQuad::leftEdgeAA):
 136 (WebCore::CCTileDrawQuad::topEdgeAA):
 137 (WebCore::CCTileDrawQuad::rightEdgeAA):
 138 (WebCore::CCTileDrawQuad::bottomEdgeAA):
 139 (WebCore::CCTileDrawQuad::isAntialiased):
 140 * platform/graphics/chromium/cc/CCTiledLayerImpl.cpp:
 141 (WebCore::CCTiledLayerImpl::CCTiledLayerImpl):
 142 (WebCore::CCTiledLayerImpl::quadTransform):
 143 (WebCore::CCTiledLayerImpl::appendQuads):
 144 * platform/graphics/chromium/cc/CCTiledLayerImpl.h:
 145 (WebCore::CCTiledLayerImpl::setContentsSwizzled):
 146 (WebCore::CCTiledLayerImpl::contentsSwizzled):
 147
11482011-12-14 Tony Chang <tony@chromium.org>
2149
3150 Remove added calls to CSSStyleSelector to gain back another 2% in page cyclers

Source/WebCore/WebCore.gypi

35973597 'platform/graphics/chromium/WebGLLayerChromium.h',
35983598 'platform/graphics/chromium/cc/CCCanvasLayerImpl.cpp',
35993599 'platform/graphics/chromium/cc/CCCanvasLayerImpl.h',
 3600 'platform/graphics/chromium/cc/CCCustomLayerDrawQuad.cpp',
 3601 'platform/graphics/chromium/cc/CCCustomLayerDrawQuad.h',
36003602 'platform/graphics/chromium/cc/CCDamageTracker.cpp',
36013603 'platform/graphics/chromium/cc/CCDamageTracker.h',
 3604 'platform/graphics/chromium/cc/CCDebugBorderDrawQuad.cpp',
 3605 'platform/graphics/chromium/cc/CCDebugBorderDrawQuad.h',
36023606 'platform/graphics/chromium/cc/CCDelayBasedTimeSource.cpp',
36033607 'platform/graphics/chromium/cc/CCDelayBasedTimeSource.h',
 3608 'platform/graphics/chromium/cc/CCDrawQuad.cpp',
 3609 'platform/graphics/chromium/cc/CCDrawQuad.h',
36043610 'platform/graphics/chromium/cc/CCFrameRateController.cpp',
36053611 'platform/graphics/chromium/cc/CCFrameRateController.h',
36063612 'platform/graphics/chromium/cc/CCHeadsUpDisplay.cpp',

36263632 'platform/graphics/chromium/cc/CCPluginLayerImpl.h',
36273633 'platform/graphics/chromium/cc/CCProxy.cpp',
36283634 'platform/graphics/chromium/cc/CCProxy.h',
 3635 'platform/graphics/chromium/cc/CCRenderPass.cpp',
 3636 'platform/graphics/chromium/cc/CCRenderPass.h',
36293637 'platform/graphics/chromium/cc/CCRenderSurface.cpp',
36303638 'platform/graphics/chromium/cc/CCRenderSurface.h',
 3639 'platform/graphics/chromium/cc/CCRenderSurfaceDrawQuad.cpp',
 3640 'platform/graphics/chromium/cc/CCRenderSurfaceDrawQuad.h',
36313641 'platform/graphics/chromium/cc/CCScheduler.cpp',
36323642 'platform/graphics/chromium/cc/CCScheduler.h',
36333643 'platform/graphics/chromium/cc/CCSchedulerStateMachine.cpp',
36343644 'platform/graphics/chromium/cc/CCSchedulerStateMachine.h',
36353645 'platform/graphics/chromium/cc/CCScopedThreadProxy.h',
 3646 'platform/graphics/chromium/cc/CCSharedQuadState.cpp',
 3647 'platform/graphics/chromium/cc/CCSharedQuadState.h',
36363648 'platform/graphics/chromium/cc/CCSingleThreadProxy.cpp',
36373649 'platform/graphics/chromium/cc/CCSingleThreadProxy.h',
 3650 'platform/graphics/chromium/cc/CCSolidColorDrawQuad.cpp',
 3651 'platform/graphics/chromium/cc/CCSolidColorDrawQuad.h',
36383652 'platform/graphics/chromium/cc/CCTextureUpdater.cpp',
36393653 'platform/graphics/chromium/cc/CCTextureUpdater.h',
 3654 'platform/graphics/chromium/cc/CCTileDrawQuad.cpp',
 3655 'platform/graphics/chromium/cc/CCTileDrawQuad.h',
36403656 'platform/graphics/chromium/cc/CCThread.h',
36413657 'platform/graphics/chromium/cc/CCThreadProxy.cpp',
36423658 'platform/graphics/chromium/cc/CCThreadProxy.h',

Source/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp

5252#include "TrackingTextureAllocator.h"
5353#include "TreeSynchronizer.h"
5454#include "WebGLLayerChromium.h"
 55#include "cc/CCCustomLayerDrawQuad.h"
5556#include "cc/CCDamageTracker.h"
 57#include "cc/CCDebugBorderDrawQuad.h"
 58#include "cc/CCRenderPass.h"
 59#include "cc/CCRenderSurfaceDrawQuad.h"
 60#include "cc/CCSolidColorDrawQuad.h"
 61#include "cc/CCTileDrawQuad.h"
5662#include "cc/CCLayerImpl.h"
5763#include "cc/CCLayerTreeHostCommon.h"
5864#include "cc/CCProxy.h"

@@static TransformationMatrix screenMatrix(int x, int y, int width, int height)
107113 return screen;
108114}
109115
110 static TransformationMatrix computeScreenSpaceTransformForSurface(CCLayerImpl* renderSurfaceLayer)
111 {
112  // The layer's screen space transform can be written as:
113  // layerScreenSpaceTransform = surfaceScreenSpaceTransform * layerOriginTransform
114  // So, to compute the surface screen space, we can do:
115  // surfaceScreenSpaceTransform = layerScreenSpaceTransform * inverse(layerOriginTransform)
116 
117  TransformationMatrix layerOriginTransform = renderSurfaceLayer->drawTransform();
118  layerOriginTransform.translate(-0.5 * renderSurfaceLayer->bounds().width(), -0.5 * renderSurfaceLayer->bounds().height());
119  TransformationMatrix surfaceScreenSpaceTransform = renderSurfaceLayer->screenSpaceTransform();
120  surfaceScreenSpaceTransform.multiply(layerOriginTransform.inverse());
121 
122  return surfaceScreenSpaceTransform;
123 }
124 
125116#if USE(SKIA)
126117bool contextSupportsAcceleratedPainting(GraphicsContext3D* context)
127118{

@@void LayerRendererChromium::viewportChanged()
316307 m_currentRenderSurface = 0;
317308}
318309
319 void LayerRendererChromium::drawLayers()
320 {
321  // FIXME: use the frame begin time from the overall compositor scheduler.
322  // This value is currently inaccessible because it is up in Chromium's
323  // RenderWidget.
324  m_headsUpDisplay->onFrameBegin(currentTime());
325 
326  if (!rootLayer())
327  return;
328 
329  size_t contentsMemoryUseBytes = m_contentsTextureAllocator->currentMemoryUseBytes();
330  size_t maxLimit = TextureManager::highLimitBytes(viewportSize());
331  size_t reclaimLimit = TextureManager::reclaimLimitBytes(viewportSize());
332 
333  m_renderSurfaceTextureManager->setMaxMemoryLimitBytes(maxLimit - contentsMemoryUseBytes);
334 
335  drawLayersInternal();
336 
337  if (reclaimLimit > contentsMemoryUseBytes)
338  m_renderSurfaceTextureManager->setPreferredMemoryLimitBytes(reclaimLimit - contentsMemoryUseBytes);
339  else
340  m_renderSurfaceTextureManager->setPreferredMemoryLimitBytes(0);
341 
342  m_renderSurfaceTextureManager->deleteEvictedTextures(m_renderSurfaceTextureAllocator.get());
343 
344  if (settings().compositeOffscreen)
345  copyOffscreenTextureToDisplay();
346 }
347 
348 void LayerRendererChromium::trackDamageForAllSurfaces(CCLayerImpl* rootDrawLayer, const CCLayerList& renderSurfaceLayerList)
349 {
350  // For now, we use damage tracking to compute a global scissor. To do this, we must
351  // compute all damage tracking before drawing anything, so that we know the root
352  // damage rect. The root damage rect is then used to scissor each surface.
353 
354  ASSERT(m_capabilities.usingPartialSwap);
355 
356  for (int surfaceIndex = renderSurfaceLayerList.size() - 1; surfaceIndex >= 0 ; --surfaceIndex) {
357  CCLayerImpl* renderSurfaceLayer = renderSurfaceLayerList[surfaceIndex].get();
358  CCRenderSurface* renderSurface = renderSurfaceLayer->renderSurface();
359  ASSERT(renderSurface);
360  renderSurface->damageTracker()->updateDamageRectForNextFrame(renderSurface->layerList(), renderSurfaceLayer->id(), renderSurfaceLayer->maskLayer());
361  }
362 }
363 
364 void LayerRendererChromium::clearSurfaceForDebug(CCLayerImpl* renderSurfaceLayer, CCLayerImpl* rootDrawLayer, const FloatRect& surfaceDamageRect)
 310void LayerRendererChromium::clearSurfaceForDebug(CCRenderSurface* renderSurface, CCRenderSurface* rootRenderSurface, const FloatRect& surfaceDamageRect)
365311{
366312 // Non-root layers should clear their entire contents to transparent. The root layer
367313 // is cleared to blue to easily see regions that were not drawn on the screen. If we

@@void LayerRendererChromium::clearSurfaceForDebug(CCLayerImpl* renderSurfaceLayer
369315 // clear the damaged region, so that we don't accidentally clear un-changed portions
370316 // of the screen.
371317
372  if (renderSurfaceLayer != rootDrawLayer)
 318 if (renderSurface != rootRenderSurface)
373319 GLC(m_context.get(), m_context->clearColor(0, 0, 0, 0));
374320 else
375321 GLC(m_context.get(), m_context->clearColor(0, 0, 1, 1));

@@void LayerRendererChromium::clearSurfaceForDebug(CCLayerImpl* renderSurfaceLayer
383329 GLC(m_context.get(), m_context->enable(GraphicsContext3D::SCISSOR_TEST));
384330}
385331
386 void LayerRendererChromium::drawLayersOntoRenderSurfaces(CCLayerImpl* rootDrawLayer, const CCLayerList& renderSurfaceLayerList)
 332void LayerRendererChromium::beginDrawingFrame()
387333{
388  TRACE_EVENT("LayerRendererChromium::drawLayersOntoRenderSurfaces", this, 0);
389 
390  if (m_capabilities.usingPartialSwap)
391  trackDamageForAllSurfaces(rootDrawLayer, renderSurfaceLayerList);
392  m_rootDamageRect = rootDrawLayer->renderSurface()->damageTracker()->currentDamageRect();
393 
394  // Update the contents of the render surfaces. We traverse the render surfaces
395  // from back to front to guarantee that nested render surfaces get rendered in
396  // the correct order.
397  for (int surfaceIndex = renderSurfaceLayerList.size() - 1; surfaceIndex >= 0 ; --surfaceIndex) {
398  CCLayerImpl* renderSurfaceLayer = renderSurfaceLayerList[surfaceIndex].get();
399  CCRenderSurface* renderSurface = renderSurfaceLayer->renderSurface();
400  ASSERT(renderSurface);
401  ASSERT(renderSurface->drawOpacity());
402 
403  if (useRenderSurface(renderSurface)) {
404 
405  FloatRect surfaceDamageRect;
406  if (m_capabilities.usingPartialSwap) {
407  // For now, we conservatively use the root damage as the damage for all
408  // surfaces, except perspective transforms.
409  TransformationMatrix screenSpaceTransform = computeScreenSpaceTransformForSurface(renderSurfaceLayer);
410  if (screenSpaceTransform.hasPerspective()) {
411  // Perspective projections do not play nice with mapRect of inverse transforms.
412  // In this uncommon case, its simpler to just redraw the entire surface.
413  surfaceDamageRect = renderSurface->contentRect();
414  } else {
415  TransformationMatrix inverseScreenSpaceTransform = screenSpaceTransform.inverse();
416  surfaceDamageRect = inverseScreenSpaceTransform.mapRect(m_rootDamageRect);
417  }
418  }
419 
420  // FIXME: eventually we should place this under a debug flag.
421  clearSurfaceForDebug(renderSurfaceLayer, rootDrawLayer, surfaceDamageRect);
422 
423  const CCLayerList& layerList = renderSurface->layerList();
424  for (unsigned layerIndex = 0; layerIndex < layerList.size(); ++layerIndex)
425  drawLayer(layerList[layerIndex].get(), renderSurface, surfaceDamageRect);
426  }
427  }
 334 m_defaultRenderSurface = rootLayer()->renderSurface();
428335
429  // The next frame should start by assuming nothing has changed, and changes are noted as they occur.
430  rootDrawLayer->resetAllChangeTrackingForSubtree();
431 }
 336 // FIXME: use the frame begin time from the overall compositor scheduler.
 337 // This value is currently inaccessible because it is up in Chromium's
 338 // RenderWidget.
 339 m_headsUpDisplay->onFrameBegin(currentTime());
432340
 341 size_t contentsMemoryUseBytes = m_contentsTextureAllocator->currentMemoryUseBytes();
 342 size_t maxLimit = TextureManager::highLimitBytes(viewportSize());
 343 m_renderSurfaceTextureManager->setMaxMemoryLimitBytes(maxLimit - contentsMemoryUseBytes);
433344
434 void LayerRendererChromium::drawLayersInternal()
435 {
436345 if (viewportSize().isEmpty() || !rootLayer())
437346 return;
438347

@@void LayerRendererChromium::drawLayersInternal()
445354 m_context->reshape(viewportWidth(), viewportHeight());
446355 }
447356
448  CCLayerImpl* rootDrawLayer = rootLayer();
449357 makeContextCurrent();
450 
451  if (!rootDrawLayer->renderSurface())
452  rootDrawLayer->createRenderSurface();
453  rootDrawLayer->renderSurface()->setContentRect(IntRect(IntPoint(), viewportSize()));
454 
455  rootDrawLayer->setClipRect(IntRect(IntPoint(), viewportSize()));
456 
457  CCLayerList renderSurfaceLayerList;
458  renderSurfaceLayerList.append(rootDrawLayer);
459 
460  m_defaultRenderSurface = rootDrawLayer->renderSurface();
461  m_defaultRenderSurface->clearLayerList();
462 
463  TransformationMatrix identityMatrix;
464  {
465  TRACE_EVENT("LayerRendererChromium::drawLayersInternal::calcDrawEtc", this, 0);
466  CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(rootDrawLayer, rootDrawLayer, identityMatrix, identityMatrix, renderSurfaceLayerList, m_defaultRenderSurface->layerList(), &m_layerSorter, m_capabilities.maxTextureSize);
467  }
468 
469358 // The GL viewport covers the entire visible area, including the scrollbars.
470359 GLC(m_context.get(), m_context->viewport(0, 0, viewportWidth(), viewportHeight()));
471360 m_windowMatrix = screenMatrix(0, 0, viewportWidth(), viewportHeight());

@@void LayerRendererChromium::drawLayersInternal()
478367 GLC(m_context.get(), m_context->colorMask(true, true, true, true));
479368 GLC(m_context.get(), m_context->enable(GraphicsContext3D::BLEND));
480369 GLC(m_context.get(), m_context->blendFunc(GraphicsContext3D::ONE, GraphicsContext3D::ONE_MINUS_SRC_ALPHA));
 370}
 371
 372void LayerRendererChromium::drawRenderPass(const CCRenderPass* renderPass)
 373{
 374 CCRenderSurface* renderSurface = renderPass->targetSurface();
 375 if (!useRenderSurface(renderSurface))
 376 return;
 377
 378 // FIXME: eventually we should place this under a debug flag.
 379 clearSurfaceForDebug(renderSurface, m_defaultRenderSurface, renderPass->surfaceDamageRect());
 380
 381 const CCQuadList& quadList = renderPass->quadList();
 382 for (size_t i = 0; i < quadList.size(); ++i)
 383 drawQuad(quadList[i].get(), renderPass->surfaceDamageRect());
 384}
 385
 386void LayerRendererChromium::drawQuad(const CCDrawQuad* quad, const FloatRect& surfaceDamageRect)
 387{
 388 IntRect scissorRect;
 389 if (m_capabilities.usingPartialSwap) {
 390 FloatRect clipAndDamageRect = surfaceDamageRect;
 391 if (!quad->clipRect().isEmpty())
 392 clipAndDamageRect.intersect(quad->clipRect());
 393 scissorRect = enclosingIntRect(clipAndDamageRect);
 394 if (scissorRect.isEmpty())
 395 return;
 396 } else
 397 scissorRect = quad->clipRect();
 398
 399 if (scissorRect.isEmpty())
 400 GLC(m_context.get(), m_context->disable(GraphicsContext3D::SCISSOR_TEST));
 401 else
 402 setScissorToRect(scissorRect);
 403
 404 if (quad->needsBlending())
 405 GLC(m_context.get(), m_context->enable(GraphicsContext3D::BLEND));
 406 else
 407 GLC(m_context.get(), m_context->disable(GraphicsContext3D::BLEND));
 408
 409 switch (quad->material()) {
 410 case CCDrawQuad::Invalid:
 411 ASSERT_NOT_REACHED();
 412 break;
 413 case CCDrawQuad::DebugBorder:
 414 drawDebugBorderQuad(quad->toDebugBorderDrawQuad());
 415 break;
 416 case CCDrawQuad::RenderSurface:
 417 drawRenderSurfaceQuad(quad->toRenderSurfaceDrawQuad());
 418 break;
 419 case CCDrawQuad::SolidColor:
 420 drawSolidColorQuad(quad->toSolidColorDrawQuad());
 421 break;
 422 case CCDrawQuad::TiledContent:
 423 drawTileQuad(quad->toTileDrawQuad());
 424 break;
 425 case CCDrawQuad::CustomLayer:
 426 drawCustomLayerQuad(quad->toCustomLayerDrawQuad());
 427 break;
 428 }
 429}
 430
 431void LayerRendererChromium::drawDebugBorderQuad(const CCDebugBorderDrawQuad* quad)
 432{
 433 static float glMatrix[16];
 434 const LayerChromium::BorderProgram* program = borderProgram();
 435 ASSERT(program && program->initialized());
 436 GLC(context(), context()->useProgram(program->program()));
 437
 438 TransformationMatrix renderMatrix = quad->layerTransform();
 439 const IntRect& layerRect = quad->quadRect();
 440 renderMatrix.scaleNonUniform(layerRect.width(), layerRect.height());
 441 LayerRendererChromium::toGLMatrix(&glMatrix[0], projectionMatrix() * renderMatrix);
 442 GLC(context(), context()->uniformMatrix4fv(program->vertexShader().matrixLocation(), false, &glMatrix[0], 1));
 443
 444 GLC(context(), context()->uniform4f(program->fragmentShader().colorLocation(), quad->color().red() / 255.0, quad->color().green() / 255.0, quad->color().blue() / 255.0, 1));
 445
 446 GLC(context(), context()->lineWidth(quad->width()));
 447
 448 // The indices for the line are stored in the same array as the triangle indices.
 449 GLC(context(), context()->drawElements(GraphicsContext3D::LINE_LOOP, 4, GraphicsContext3D::UNSIGNED_SHORT, 6 * sizeof(unsigned short)));
 450}
 451
 452void LayerRendererChromium::drawRenderSurfaceQuad(const CCRenderSurfaceDrawQuad* quad)
 453{
 454 CCLayerImpl* layer = quad->layer();
 455 layer->renderSurface()->draw(this, quad->surfaceDamageRect());
 456 layer->renderSurface()->releaseContentsTexture();
 457}
 458
 459void LayerRendererChromium::drawSolidColorQuad(const CCSolidColorDrawQuad* quad)
 460{
 461 const LayerChromium::BorderProgram* solidColorProgram = borderProgram();
 462 GLC(context(), context()->useProgram(solidColorProgram->program()));
 463
 464 IntRect tileRect = quad->quadRect();
 465
 466 TransformationMatrix tileTransform = quad->quadTransform();
 467 tileTransform.translate(tileRect.x() + tileRect.width() / 2.0, tileRect.y() + tileRect.height() / 2.0);
 468
 469 const Color& color = quad->color();
 470
 471 GLC(context(), context()->uniform4f(solidColorProgram->fragmentShader().colorLocation(), color.red(), color.green(), color.blue(), color.alpha()));
 472
 473 float opacity = quad->opacity();
 474 drawTexturedQuad(tileTransform,
 475 tileRect.width(), tileRect.height(), opacity, FloatQuad(),
 476 solidColorProgram->vertexShader().matrixLocation(),
 477 -1, -1);
 478}
 479
 480struct TileProgramUniforms {
 481 unsigned program;
 482 unsigned samplerLocation;
 483 unsigned vertexTexTransformLocation;
 484 unsigned fragmentTexTransformLocation;
 485 unsigned edgeLocation;
 486 unsigned matrixLocation;
 487 unsigned alphaLocation;
 488 unsigned pointLocation;
 489};
 490
 491template<class T>
 492static void tileUniformLocation(T program, TileProgramUniforms& uniforms)
 493{
 494 uniforms.program = program->program();
 495 uniforms.vertexTexTransformLocation = program->vertexShader().vertexTexTransformLocation();
 496 uniforms.matrixLocation = program->vertexShader().matrixLocation();
 497 uniforms.pointLocation = program->vertexShader().pointLocation();
 498
 499 uniforms.samplerLocation = program->fragmentShader().samplerLocation();
 500 uniforms.alphaLocation = program->fragmentShader().alphaLocation();
 501 uniforms.fragmentTexTransformLocation = program->fragmentShader().fragmentTexTransformLocation();
 502 uniforms.edgeLocation = program->fragmentShader().edgeLocation();
 503}
 504
 505static void findTileProgramUniforms(LayerRendererChromium* layerRenderer, const CCTileDrawQuad* quad, TileProgramUniforms& uniforms)
 506{
 507 if (quad->isAntialiased()) {
 508 if (quad->swizzleContents()) {
 509 const CCTiledLayerImpl::ProgramSwizzleAA* program = layerRenderer->tilerProgramSwizzleAA();
 510 tileUniformLocation(program, uniforms);
 511 } else {
 512 const CCTiledLayerImpl::ProgramAA* program = layerRenderer->tilerProgramAA();
 513 tileUniformLocation(program, uniforms);
 514 }
 515 } else {
 516 if (quad->needsBlending()) {
 517 if (quad->swizzleContents()) {
 518 const CCTiledLayerImpl::ProgramSwizzle* program = layerRenderer->tilerProgramSwizzle();
 519 tileUniformLocation(program, uniforms);
 520 } else {
 521 const CCTiledLayerImpl::Program* program = layerRenderer->tilerProgram();
 522 tileUniformLocation(program, uniforms);
 523 }
 524 } else {
 525 if (quad->swizzleContents()) {
 526 const CCTiledLayerImpl::ProgramSwizzleOpaque* program = layerRenderer->tilerProgramSwizzleOpaque();
 527 tileUniformLocation(program, uniforms);
 528 } else {
 529 const CCTiledLayerImpl::ProgramOpaque* program = layerRenderer->tilerProgramOpaque();
 530 tileUniformLocation(program, uniforms);
 531 }
 532 }
 533 }
 534}
 535
 536void LayerRendererChromium::drawTileQuad(const CCTileDrawQuad* quad)
 537{
 538 const IntRect& tileRect = quad->quadRect();
 539
 540 FloatRect clampRect(tileRect);
 541 // Clamp texture coordinates to avoid sampling outside the layer
 542 // by deflating the tile region half a texel or half a texel
 543 // minus epsilon for one pixel layers. The resulting clamp region
 544 // is mapped to the unit square by the vertex shader and mapped
 545 // back to normalized texture coordinates by the fragment shader
 546 // after being clamped to 0-1 range.
 547 const float epsilon = 1 / 1024.0f;
 548 float clampX = min(0.5, clampRect.width() / 2.0 - epsilon);
 549 float clampY = min(0.5, clampRect.height() / 2.0 - epsilon);
 550 clampRect.inflateX(-clampX);
 551 clampRect.inflateY(-clampY);
 552 FloatSize clampOffset = clampRect.minXMinYCorner() - FloatRect(tileRect).minXMinYCorner();
 553
 554 FloatPoint textureOffset = quad->textureOffset() + clampOffset;
 555
 556 // Map clamping rectangle to unit square.
 557 float vertexTexTranslateX = -clampRect.x() / clampRect.width();
 558 float vertexTexTranslateY = -clampRect.y() / clampRect.height();
 559 float vertexTexScaleX = tileRect.width() / clampRect.width();
 560 float vertexTexScaleY = tileRect.height() / clampRect.height();
 561
 562 // Map to normalized texture coordinates.
 563 const IntSize& textureSize = quad->textureSize();
 564 float fragmentTexTranslateX = textureOffset.x() / textureSize.width();
 565 float fragmentTexTranslateY = textureOffset.y() / textureSize.height();
 566 float fragmentTexScaleX = clampRect.width() / textureSize.width();
 567 float fragmentTexScaleY = clampRect.height() / textureSize.height();
 568
 569 TileProgramUniforms uniforms;
 570 findTileProgramUniforms(this, quad, uniforms);
 571
 572 GLC(context(), context()->useProgram(uniforms.program));
 573 GLC(context(), context()->uniform1i(uniforms.samplerLocation, 0));
 574 GLC(context(), context()->activeTexture(GraphicsContext3D::TEXTURE0));
 575 GLC(context(), context()->bindTexture(GraphicsContext3D::TEXTURE_2D, quad->textureId()));
 576 GLC(context(), context()->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, quad->textureFilter()));
 577 GLC(context(), context()->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, quad->textureFilter()));
 578
 579 FloatQuad localQuad;
 580 if (quad->isAntialiased()) {
 581 TransformationMatrix deviceTransform = TransformationMatrix(windowMatrix() * projectionMatrix() * quad->quadTransform()).to2dTransform();
 582 if (!deviceTransform.isInvertible())
 583 return;
 584
 585 FloatQuad deviceLayerQuad = deviceTransform.mapQuad(FloatQuad(quad->layerRect()));
 586
 587 CCLayerQuad deviceLayerBounds = CCLayerQuad(FloatQuad(deviceLayerQuad.boundingBox()));
 588 deviceLayerBounds.inflateAntiAliasingDistance();
 589
 590 CCLayerQuad deviceLayerEdges = CCLayerQuad(deviceLayerQuad);
 591 deviceLayerEdges.inflateAntiAliasingDistance();
 592
 593 float edge[24];
 594 deviceLayerEdges.toFloatArray(edge);
 595 deviceLayerBounds.toFloatArray(&edge[12]);
 596 GLC(context(), context()->uniform3fv(uniforms.edgeLocation, edge, 8));
 597
 598 GLC(context(), context()->uniform4f(uniforms.vertexTexTransformLocation, vertexTexTranslateX, vertexTexTranslateY, vertexTexScaleX, vertexTexScaleY));
 599 GLC(context(), context()->uniform4f(uniforms.fragmentTexTransformLocation, fragmentTexTranslateX, fragmentTexTranslateY, fragmentTexScaleX, fragmentTexScaleY));
 600
 601 FloatPoint bottomRight(tileRect.maxX(), tileRect.maxY());
 602 FloatPoint bottomLeft(tileRect.x(), tileRect.maxY());
 603 FloatPoint topLeft(tileRect.x(), tileRect.y());
 604 FloatPoint topRight(tileRect.maxX(), tileRect.y());
 605
 606 // Map points to device space.
 607 bottomRight = deviceTransform.mapPoint(bottomRight);
 608 bottomLeft = deviceTransform.mapPoint(bottomLeft);
 609 topLeft = deviceTransform.mapPoint(topLeft);
 610 topRight = deviceTransform.mapPoint(topRight);
 611
 612 CCLayerQuad::Edge bottomEdge(bottomRight, bottomLeft);
 613 CCLayerQuad::Edge leftEdge(bottomLeft, topLeft);
 614 CCLayerQuad::Edge topEdge(topLeft, topRight);
 615 CCLayerQuad::Edge rightEdge(topRight, bottomRight);
 616
 617 if (quad->topEdgeAA())
 618 topEdge = deviceLayerEdges.top();
 619 if (quad->leftEdgeAA())
 620 leftEdge = deviceLayerEdges.left();
 621 if (quad->rightEdgeAA())
 622 rightEdge = deviceLayerEdges.right();
 623 if (quad->bottomEdgeAA())
 624 bottomEdge = deviceLayerEdges.bottom();
 625
 626 float sign = FloatQuad(tileRect).isCounterclockwise() ? -1 : 1;
 627 bottomEdge.scale(sign);
 628 leftEdge.scale(sign);
 629 topEdge.scale(sign);
 630 rightEdge.scale(sign);
 631
 632 // Create device space quad.
 633 CCLayerQuad deviceQuad(leftEdge, topEdge, rightEdge, bottomEdge);
 634
 635 // Map quad to layer space.
 636 TransformationMatrix inverseDeviceTransform = deviceTransform.inverse();
 637 localQuad = inverseDeviceTransform.mapQuad(deviceQuad.floatQuad());
 638 } else {
 639 // Move fragment shader transform to vertex shader. We can do this while
 640 // still producing correct results as fragmentTexTransformLocation
 641 // should always be non-negative when tiles are transformed in a way
 642 // that could result in sampling outside the layer.
 643 vertexTexScaleX *= fragmentTexScaleX;
 644 vertexTexScaleY *= fragmentTexScaleY;
 645 vertexTexTranslateX *= fragmentTexScaleX;
 646 vertexTexTranslateY *= fragmentTexScaleY;
 647 vertexTexTranslateX += fragmentTexTranslateX;
 648 vertexTexTranslateY += fragmentTexTranslateY;
 649
 650 GLC(context(), context()->uniform4f(uniforms.vertexTexTransformLocation, vertexTexTranslateX, vertexTexTranslateY, vertexTexScaleX, vertexTexScaleY));
 651
 652 localQuad = FloatRect(tileRect);
 653 }
 654
 655 // Normalize to tileRect.
 656 localQuad.scale(1.0f / tileRect.width(), 1.0f / tileRect.height());
481657
482  drawLayersOntoRenderSurfaces(rootDrawLayer, renderSurfaceLayerList);
 658 drawTexturedQuad(quad->quadTransform(), tileRect.width(), tileRect.height(), quad->opacity(), localQuad, uniforms.matrixLocation, uniforms.alphaLocation, uniforms.pointLocation);
 659}
 660
 661void LayerRendererChromium::drawCustomLayerQuad(const CCCustomLayerDrawQuad* quad)
 662{
 663 CCLayerImpl* layer = quad->layer();
 664 layer->draw(this);
 665}
483666
 667void LayerRendererChromium::finishDrawingFrame()
 668{
484669 if (m_headsUpDisplay->enabled()) {
485670 GLC(m_context.get(), m_context->enable(GraphicsContext3D::BLEND));
486671 GLC(m_context.get(), m_context->blendFunc(GraphicsContext3D::ONE, GraphicsContext3D::ONE_MINUS_SRC_ALPHA));

@@void LayerRendererChromium::drawLayersInternal()
491676
492677 GLC(m_context.get(), m_context->disable(GraphicsContext3D::SCISSOR_TEST));
493678 GLC(m_context.get(), m_context->disable(GraphicsContext3D::BLEND));
 679
 680 size_t contentsMemoryUseBytes = m_contentsTextureAllocator->currentMemoryUseBytes();
 681 size_t reclaimLimit = TextureManager::reclaimLimitBytes(viewportSize());
 682 if (reclaimLimit > contentsMemoryUseBytes)
 683 m_renderSurfaceTextureManager->setPreferredMemoryLimitBytes(reclaimLimit - contentsMemoryUseBytes);
 684 else
 685 m_renderSurfaceTextureManager->setPreferredMemoryLimitBytes(0);
 686
 687 m_renderSurfaceTextureManager->deleteEvictedTextures(m_renderSurfaceTextureAllocator.get());
 688
 689 if (settings().compositeOffscreen)
 690 copyOffscreenTextureToDisplay();
494691}
495692
496693void LayerRendererChromium::toGLMatrix(float* flattened, const TransformationMatrix& m)

@@bool LayerRendererChromium::useRenderSurface(CCRenderSurface* renderSurface)
642839#endif
643840
644841 setDrawViewportRect(renderSurface->contentRect(), false);
645  return true;
646 }
647 
648 void LayerRendererChromium::drawLayer(CCLayerImpl* layer, CCRenderSurface* targetSurface, const FloatRect& surfaceDamageRect)
649 {
650  if (CCLayerTreeHostCommon::renderSurfaceContributesToTarget<CCLayerImpl>(layer, targetSurface->owningLayerId())) {
651  layer->renderSurface()->draw(this, surfaceDamageRect);
652  layer->renderSurface()->releaseContentsTexture();
653  return;
654  }
655 
656  if (layer->visibleLayerRect().isEmpty())
657  return;
658842
659  if (layer->usesLayerClipping() && m_capabilities.usingPartialSwap) {
660  FloatRect clipAndDamageRect(layer->clipRect());
661  clipAndDamageRect.intersect(surfaceDamageRect);
662  setScissorToRect(enclosingIntRect(clipAndDamageRect));
663  } else if (m_capabilities.usingPartialSwap)
664  setScissorToRect(enclosingIntRect(surfaceDamageRect));
665  else if (layer->usesLayerClipping())
666  setScissorToRect(layer->clipRect());
667  else
668  GLC(m_context.get(), m_context->disable(GraphicsContext3D::SCISSOR_TEST));
669 
670  bool opaque = layer->opaque() && layer->drawOpacity() == 1;
671  if (opaque)
672  GLC(m_context.get(), m_context->disable(GraphicsContext3D::BLEND));
673 
674  layer->draw(this);
675 
676  if (opaque)
677  GLC(m_context.get(), m_context->enable(GraphicsContext3D::BLEND));
678 
679  // Draw the debug border if there is one.
680  layer->drawDebugBorder(this);
 843 return true;
681844}
682845
683846// Sets the scissor region to the given rectangle. The coordinate system for the

Source/WebCore/platform/graphics/chromium/LayerRendererChromium.h

4242#include "VideoLayerChromium.h"
4343#include "cc/CCCanvasLayerImpl.h"
4444#include "cc/CCHeadsUpDisplay.h"
45 #include "cc/CCLayerSorter.h"
4645#include "cc/CCLayerTreeHostImpl.h"
4746#include "cc/CCPluginLayerImpl.h"
4847#include "cc/CCVideoLayerImpl.h"

@@namespace WebCore {
6665class CCHeadsUpDisplay;
6766class CCLayerImpl;
6867class CCLayerTreeHostImpl;
 68class CCRenderPass;
6969class GeometryBinding;
7070class GraphicsContext3D;
7171class TrackingTextureAllocator;

@@public:
9797
9898 void viewportChanged();
9999
100  void drawLayers();
 100 void beginDrawingFrame();
 101 void drawRenderPass(const CCRenderPass*);
 102 void finishDrawingFrame();
101103
102104 // waits for rendering to finish
103105 void finish();

@@public:
151153
152154 GC3Denum bestTextureFormat();
153155
154  typedef Vector<RefPtr<CCLayerImpl> > CCLayerList;
155 
156156 static void toGLMatrix(float*, const TransformationMatrix&);
157157 void drawTexturedQuad(const TransformationMatrix& layerMatrix,
158158 float width, float height, float opacity, const FloatQuad&,

@@private:
162162 LayerRendererChromium(CCLayerTreeHostImpl*, PassRefPtr<GraphicsContext3D>);
163163 bool initialize();
164164
165  void drawLayersInternal();
166  void drawLayersOntoRenderSurfaces(CCLayerImpl* rootDrawLayer, const CCLayerList& renderSurfaceLayerList);
167  void drawLayer(CCLayerImpl*, CCRenderSurface*, const FloatRect&);
168 
169  void trackDamageForAllSurfaces(CCLayerImpl* rootDrawLayer, const CCLayerList& renderSurfaceLayerList);
 165 void drawQuad(const CCDrawQuad*, const FloatRect& surfaceDamageRect);
 166 void drawDebugBorderQuad(const CCDebugBorderDrawQuad*);
 167 void drawRenderSurfaceQuad(const CCRenderSurfaceDrawQuad*);
 168 void drawSolidColorQuad(const CCSolidColorDrawQuad*);
 169 void drawTileQuad(const CCTileDrawQuad*);
 170 void drawCustomLayerQuad(const CCCustomLayerDrawQuad*);
170171
171172 ManagedTexture* getOffscreenLayerTexture();
172173 void copyOffscreenTextureToDisplay();
173174
174175 void setDrawViewportRect(const IntRect&, bool flipY);
175176
176  void releaseRenderSurfaceTextures();
177 
178177 bool useRenderSurface(CCRenderSurface*);
179  void clearSurfaceForDebug(CCLayerImpl* renderSurfaceLayer, CCLayerImpl* rootDrawLayer, const FloatRect& surfaceDamageRect);
 178 void clearSurfaceForDebug(CCRenderSurface*, CCRenderSurface* rootRenderSurface, const FloatRect& surfaceDamageRect);
 179
 180 void releaseRenderSurfaceTextures();
180181
181182 bool makeContextCurrent();
182183

@@private:
238239
239240 CCRenderSurface* m_defaultRenderSurface;
240241
241  CCLayerSorter m_layerSorter;
242 
243242 FloatQuad m_sharedGeometryQuad;
244243
245244 bool m_isViewportChanged;

Source/WebCore/platform/graphics/chromium/ShaderChromium.h

@@public:
151151
152152 void init(GraphicsContext3D*, unsigned program);
153153 int alphaLocation() const { return m_alphaLocation; }
 154 int edgeLocation() const { return -1; }
 155 int fragmentTexTransformLocation() const { return -1; }
154156 int samplerLocation() const { return m_samplerLocation; }
155157
156158private:

@@public:
164166
165167 void init(GraphicsContext3D*, unsigned program);
166168 int alphaLocation() const { return -1; }
 169 int edgeLocation() const { return -1; }
 170 int fragmentTexTransformLocation() const { return -1; }
167171 int samplerLocation() const { return m_samplerLocation; }
168172
169173private:

Source/WebCore/platform/graphics/chromium/TiledLayerChromium.cpp

@@void TiledLayerChromium::pushPropertiesTo(CCLayerImpl* layer)
248248 }
249249
250250 tiledLayer->setSkipsDraw(m_skipsDraw);
251  tiledLayer->setSampledTexelFormat(m_sampledTexelFormat);
 251 tiledLayer->setContentsSwizzled(m_sampledTexelFormat != LayerTextureUpdater::SampledTexelFormatRGBA);
252252 tiledLayer->setTilingData(*m_tiler);
253253
254254 for (CCLayerTilingData::TileMap::const_iterator iter = m_tiler->tiles().begin(); iter != m_tiler->tiles().end(); ++iter) {

Source/WebCore/platform/graphics/chromium/cc/CCCustomLayerDrawQuad.cpp

 1/*
 2 * Copyright (C) 2011 Google Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 *
 8 * 1. Redistributions of source code must retain the above copyright
 9 * notice, this list of conditions and the following disclaimer.
 10 * 2. Redistributions in binary form must reproduce the above copyright
 11 * notice, this list of conditions and the following disclaimer in the
 12 * documentation and/or other materials provided with the distribution.
 13 *
 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#include "config.h"
 27
 28#include "cc/CCCustomLayerDrawQuad.h"
 29
 30namespace WebCore {
 31
 32PassOwnPtr<CCCustomLayerDrawQuad> CCCustomLayerDrawQuad::create(const CCSharedQuadState* sharedQuadState, const IntRect& quadRect, CCLayerImpl* layer)
 33{
 34 return adoptPtr(new CCCustomLayerDrawQuad(sharedQuadState, quadRect, layer));
 35}
 36
 37CCCustomLayerDrawQuad::CCCustomLayerDrawQuad(const CCSharedQuadState* sharedQuadState, const IntRect& quadRect, CCLayerImpl* layer)
 38 : CCDrawQuad(sharedQuadState, CCDrawQuad::CustomLayer, quadRect)
 39 , m_layer(layer)
 40{
 41 ASSERT(m_layer);
 42}
 43
 44}

Source/WebCore/platform/graphics/chromium/cc/CCCustomLayerDrawQuad.h

 1/*
 2 * Copyright (C) 2011 Google Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 *
 8 * 1. Redistributions of source code must retain the above copyright
 9 * notice, this list of conditions and the following disclaimer.
 10 * 2. Redistributions in binary form must reproduce the above copyright
 11 * notice, this list of conditions and the following disclaimer in the
 12 * documentation and/or other materials provided with the distribution.
 13 *
 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#ifndef CCCustomLayerDrawQuad_h
 27#define CCCustomLayerDrawQuad_h
 28
 29#include "cc/CCDrawQuad.h"
 30#include <wtf/PassOwnPtr.h>
 31
 32namespace WebCore {
 33
 34class CCLayerImpl;
 35
 36// FIXME: This class is a temporary way to access CCLayerImpl::draw. This class
 37// should be converted to a set of draw quads for each layer material type and
 38// then removed.
 39class CCCustomLayerDrawQuad : public CCDrawQuad {
 40 WTF_MAKE_NONCOPYABLE(CCCustomLayerDrawQuad);
 41public:
 42 static PassOwnPtr<CCCustomLayerDrawQuad> create(const CCSharedQuadState*, const IntRect&, CCLayerImpl*);
 43
 44 CCLayerImpl* layer() const { return m_layer; }
 45
 46private:
 47 CCCustomLayerDrawQuad(const CCSharedQuadState*, const IntRect&, CCLayerImpl*);
 48
 49 CCLayerImpl* m_layer;
 50};
 51
 52}
 53
 54#endif

Source/WebCore/platform/graphics/chromium/cc/CCDebugBorderDrawQuad.cpp

 1/*
 2 * Copyright (C) 2011 Google Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 *
 8 * 1. Redistributions of source code must retain the above copyright
 9 * notice, this list of conditions and the following disclaimer.
 10 * 2. Redistributions in binary form must reproduce the above copyright
 11 * notice, this list of conditions and the following disclaimer in the
 12 * documentation and/or other materials provided with the distribution.
 13 *
 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#include "config.h"
 27
 28#include "cc/CCDebugBorderDrawQuad.h"
 29
 30namespace WebCore {
 31
 32PassOwnPtr<CCDebugBorderDrawQuad> CCDebugBorderDrawQuad::create(const CCSharedQuadState* sharedQuadState, const IntRect& quadRect, const Color& color, int width)
 33{
 34 return adoptPtr(new CCDebugBorderDrawQuad(sharedQuadState, quadRect, color, width));
 35}
 36
 37CCDebugBorderDrawQuad::CCDebugBorderDrawQuad(const CCSharedQuadState* sharedQuadState, const IntRect& quadRect, const Color& color, int width)
 38 : CCDrawQuad(sharedQuadState, CCDrawQuad::DebugBorder, quadRect)
 39 , m_color(color)
 40 , m_width(width)
 41{
 42 m_quadOpaque = false;
 43 if (m_color.alpha() != 1)
 44 m_needsBlending = true;
 45}
 46
 47}

Source/WebCore/platform/graphics/chromium/cc/CCDebugBorderDrawQuad.h

 1/*
 2 * Copyright (C) 2011 Google Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 *
 8 * 1. Redistributions of source code must retain the above copyright
 9 * notice, this list of conditions and the following disclaimer.
 10 * 2. Redistributions in binary form must reproduce the above copyright
 11 * notice, this list of conditions and the following disclaimer in the
 12 * documentation and/or other materials provided with the distribution.
 13 *
 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#ifndef CCDebugBorderDrawQuad_h
 27#define CCDebugBorderDrawQuad_h
 28
 29#include "Color.h"
 30#include "cc/CCDrawQuad.h"
 31#include <wtf/PassOwnPtr.h>
 32
 33namespace WebCore {
 34
 35class CCDebugBorderDrawQuad : public CCDrawQuad {
 36 WTF_MAKE_NONCOPYABLE(CCDebugBorderDrawQuad);
 37public:
 38 static PassOwnPtr<CCDebugBorderDrawQuad> create(const CCSharedQuadState*, const IntRect&, const Color&, int width);
 39
 40 const Color& color() const { return m_color; };
 41 int width() const { return m_width; }
 42
 43private:
 44 CCDebugBorderDrawQuad(const CCSharedQuadState*, const IntRect&, const Color&, int width);
 45
 46 Color m_color;
 47 int m_width;
 48};
 49
 50}
 51
 52#endif

Source/WebCore/platform/graphics/chromium/cc/CCDrawQuad.cpp

 1/*
 2 * Copyright (C) 2011 Google Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 *
 8 * 1. Redistributions of source code must retain the above copyright
 9 * notice, this list of conditions and the following disclaimer.
 10 * 2. Redistributions in binary form must reproduce the above copyright
 11 * notice, this list of conditions and the following disclaimer in the
 12 * documentation and/or other materials provided with the distribution.
 13 *
 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#include "config.h"
 27
 28#include "cc/CCDrawQuad.h"
 29
 30#include "cc/CCCustomLayerDrawQuad.h"
 31#include "cc/CCDebugBorderDrawQuad.h"
 32#include "cc/CCLayerImpl.h"
 33#include "cc/CCRenderSurfaceDrawQuad.h"
 34#include "cc/CCSolidColorDrawQuad.h"
 35#include "cc/CCTileDrawQuad.h"
 36
 37namespace WebCore {
 38
 39CCDrawQuad::CCDrawQuad(const CCSharedQuadState* sharedQuadState, Material material, const IntRect& quadRect)
 40 : m_sharedQuadState(sharedQuadState)
 41 , m_material(material)
 42 , m_quadRect(quadRect)
 43 , m_quadOpaque(true)
 44 , m_needsBlending(false)
 45{
 46 ASSERT(m_sharedQuadState);
 47 ASSERT(m_material != Invalid);
 48}
 49
 50const CCDebugBorderDrawQuad* CCDrawQuad::toDebugBorderDrawQuad() const
 51{
 52 ASSERT(m_material == DebugBorder);
 53 return static_cast<const CCDebugBorderDrawQuad*>(this);
 54}
 55
 56const CCRenderSurfaceDrawQuad* CCDrawQuad::toRenderSurfaceDrawQuad() const
 57{
 58 ASSERT(m_material == RenderSurface);
 59 return static_cast<const CCRenderSurfaceDrawQuad*>(this);
 60}
 61
 62const CCSolidColorDrawQuad* CCDrawQuad::toSolidColorDrawQuad() const
 63{
 64 ASSERT(m_material == SolidColor);
 65 return static_cast<const CCSolidColorDrawQuad*>(this);
 66}
 67
 68const CCTileDrawQuad* CCDrawQuad::toTileDrawQuad() const
 69{
 70 ASSERT(m_material == TiledContent);
 71 return static_cast<const CCTileDrawQuad*>(this);
 72}
 73
 74const CCCustomLayerDrawQuad* CCDrawQuad::toCustomLayerDrawQuad() const
 75{
 76 ASSERT(m_material == CustomLayer);
 77 return static_cast<const CCCustomLayerDrawQuad*>(this);
 78}
 79
 80}

Source/WebCore/platform/graphics/chromium/cc/CCDrawQuad.h

 1/*
 2 * Copyright (C) 2011 Google Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 *
 8 * 1. Redistributions of source code must retain the above copyright
 9 * notice, this list of conditions and the following disclaimer.
 10 * 2. Redistributions in binary form must reproduce the above copyright
 11 * notice, this list of conditions and the following disclaimer in the
 12 * documentation and/or other materials provided with the distribution.
 13 *
 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#ifndef CCDrawQuad_h
 27#define CCDrawQuad_h
 28
 29#include "cc/CCSharedQuadState.h"
 30
 31namespace WebCore {
 32
 33class CCDebugBorderDrawQuad;
 34class CCRenderSurfaceDrawQuad;
 35class CCSolidColorDrawQuad;
 36class CCTileDrawQuad;
 37class CCCustomLayerDrawQuad;
 38
 39// CCDrawQuad is a bag of data used for drawing a quad. Because different
 40// materials need different bits of per-quad data to render, classes that derive
 41// from CCDrawQuad store additional data in their derived instance. The Material
 42// enum is used to "safely" upcast to the derived class.
 43class CCDrawQuad {
 44 WTF_MAKE_NONCOPYABLE(CCDrawQuad);
 45public:
 46 const IntRect& quadRect() const { return m_quadRect; }
 47 const TransformationMatrix& quadTransform() const { return m_sharedQuadState->quadTransform(); }
 48 const TransformationMatrix& layerTransform() const { return m_sharedQuadState->layerTransform(); }
 49 const IntRect& layerRect() const { return m_sharedQuadState->layerRect(); }
 50 const IntRect& clipRect() const { return m_sharedQuadState->clipRect(); }
 51 float opacity() const { return m_sharedQuadState->opacity(); }
 52 // For the purposes of culling, are the contents of this quad opaque?
 53 bool drawsOpaque() const { return m_sharedQuadState->isOpaque() && m_quadOpaque && opacity() == 1; }
 54 bool needsBlending() const { return !m_sharedQuadState->isOpaque() || m_needsBlending || opacity() != 1; }
 55 bool isLayerAxisAlignedIntRect() const { return m_sharedQuadState->isLayerAxisAlignedIntRect(); }
 56
 57 enum Material {
 58 Invalid,
 59 DebugBorder,
 60 RenderSurface,
 61 SolidColor,
 62 TiledContent,
 63
 64 // FIXME: remove this and add proper material types for all layer types
 65 CustomLayer,
 66 };
 67
 68 Material material() const { return m_material; }
 69
 70 const CCDebugBorderDrawQuad* toDebugBorderDrawQuad() const;
 71 const CCRenderSurfaceDrawQuad* toRenderSurfaceDrawQuad() const;
 72 const CCSolidColorDrawQuad* toSolidColorDrawQuad() const;
 73 const CCTileDrawQuad* toTileDrawQuad() const;
 74 const CCCustomLayerDrawQuad* toCustomLayerDrawQuad() const;
 75
 76protected:
 77 CCDrawQuad(const CCSharedQuadState*, Material, const IntRect&);
 78
 79 const CCSharedQuadState* m_sharedQuadState;
 80
 81 Material m_material;
 82 IntRect m_quadRect;
 83
 84 // By default, the shared quad state determines whether or not this quad is
 85 // opaque or needs blending. Derived classes can override with these
 86 // variables.
 87 bool m_quadOpaque;
 88 bool m_needsBlending;
 89};
 90
 91}
 92
 93#endif

Source/WebCore/platform/graphics/chromium/cc/CCLayerImpl.cpp

3232#include "GraphicsContext3D.h"
3333#include "LayerChromium.h"
3434#include "LayerRendererChromium.h"
 35#include "cc/CCCustomLayerDrawQuad.h"
 36#include "cc/CCDebugBorderDrawQuad.h"
3537#include "cc/CCLayerSorter.h"
3638#include <wtf/text/WTFString.h>
3739

@@void CCLayerImpl::draw(LayerRendererChromium*)
117119 ASSERT_NOT_REACHED();
118120}
119121
 122PassOwnPtr<CCSharedQuadState> CCLayerImpl::createSharedQuadState() const
 123{
 124 IntRect layerClipRect;
 125 if (usesLayerClipping())
 126 layerClipRect = clipRect();
 127 return CCSharedQuadState::create(quadTransform(), drawTransform(), visibleLayerRect(), layerClipRect, drawOpacity(), opaque());
 128}
 129
 130void CCLayerImpl::appendQuads(CCQuadList& quadList, const CCSharedQuadState* sharedQuadState)
 131{
 132 IntRect layerRect(IntPoint(), bounds());
 133 quadList.append(CCCustomLayerDrawQuad::create(sharedQuadState, layerRect, this));
 134}
 135
 136void CCLayerImpl::appendDebugBorderQuad(CCQuadList& quadList, const CCSharedQuadState* sharedQuadState) const
 137{
 138 if (!debugBorderColor().alpha())
 139 return;
 140 if (debugBorderWidth() <= 0)
 141 return;
 142
 143 IntRect layerRect(IntPoint(), bounds());
 144 quadList.append(CCDebugBorderDrawQuad::create(sharedQuadState, layerRect, debugBorderColor(), debugBorderWidth()));
 145}
 146
120147void CCLayerImpl::bindContentsTexture(LayerRendererChromium*)
121148{
122149 ASSERT_NOT_REACHED();

@@const IntRect CCLayerImpl::getDrawRect() const
147174 return mappedRect;
148175}
149176
150 void CCLayerImpl::drawDebugBorder(LayerRendererChromium* layerRenderer)
 177TransformationMatrix CCLayerImpl::quadTransform() const
151178{
152  static float glMatrix[16];
153  if (!debugBorderColor().alpha())
154  return;
155 
156  GraphicsContext3D* context = layerRenderer->context();
157  const LayerChromium::BorderProgram* program = layerRenderer->borderProgram();
158  ASSERT(program && program->initialized());
159  GLC(context, context->useProgram(program->program()));
160 
161  TransformationMatrix renderMatrix = drawTransform();
162  renderMatrix.scale3d(bounds().width(), bounds().height(), 1);
163  LayerRendererChromium::toGLMatrix(&glMatrix[0], layerRenderer->projectionMatrix() * renderMatrix);
164  GLC(context, context->uniformMatrix4fv(program->vertexShader().matrixLocation(), false, &glMatrix[0], 1));
165 
166  GLC(context, context->uniform4f(program->fragmentShader().colorLocation(), debugBorderColor().red() / 255.0, debugBorderColor().green() / 255.0, debugBorderColor().blue() / 255.0, 1));
167 
168  GLC(context, context->lineWidth(debugBorderWidth()));
169 
170  // The indices for the line are stored in the same array as the triangle indices.
171  GLC(context, context->drawElements(GraphicsContext3D::LINE_LOOP, 4, GraphicsContext3D::UNSIGNED_SHORT, 6 * sizeof(unsigned short)));
 179 return drawTransform();
172180}
173181
174182void CCLayerImpl::writeIndent(TextStream& ts, int indent)

Source/WebCore/platform/graphics/chromium/cc/CCLayerImpl.h

3131#include "IntRect.h"
3232#include "TextStream.h"
3333#include "TransformationMatrix.h"
 34#include "cc/CCRenderPass.h"
3435#include "cc/CCRenderSurface.h"
3536#include <wtf/OwnPtr.h>
3637#include <wtf/PassRefPtr.h>

@@public:
7071 int debugID() const { return m_debugID; }
7172#endif
7273
 74 PassOwnPtr<CCSharedQuadState> createSharedQuadState() const;
 75 virtual void appendQuads(CCQuadList&, const CCSharedQuadState*);
 76 void appendDebugBorderQuad(CCQuadList&, const CCSharedQuadState*) const;
 77
7378 virtual void draw(LayerRendererChromium*);
7479 void unreserveContentsTexture();
7580 virtual void bindContentsTexture(LayerRendererChromium*);

@@public:
131136 void setDebugBorderWidth(float);
132137 float debugBorderWidth() const { return m_debugBorderWidth; }
133138
134  void drawDebugBorder(LayerRendererChromium*);
135 
136139 CCRenderSurface* renderSurface() const { return m_renderSurface.get(); }
137140 void createRenderSurface();
138141 void clearRenderSurface() { m_renderSurface.clear(); }

@@protected:
200203 virtual void dumpLayerProperties(TextStream&, int indent) const;
201204 static void writeIndent(TextStream&, int indent);
202205
 206 // Transformation used to transform quads provided in appendQuads.
 207 virtual TransformationMatrix quadTransform() const;
 208
203209private:
204210 void setParent(CCLayerImpl* parent) { m_parent = parent; }
205211 friend class TreeSynchronizer;

Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp

3030#include "GraphicsContext3D.h"
3131#include "LayerRendererChromium.h"
3232#include "TraceEvent.h"
 33#include "cc/CCDamageTracker.h"
 34#include "cc/CCLayerTreeHostCommon.h"
3335#include "cc/CCLayerTreeHost.h"
3436#include "cc/CCPageScaleAnimation.h"
 37#include "cc/CCRenderSurfaceDrawQuad.h"
3538#include "cc/CCThreadTask.h"
3639#include <wtf/CurrentTime.h>
3740

@@void CCLayerTreeHostImpl::startPageScaleAnimation(const IntSize& targetPosition,
126129 m_client->setNeedsRedrawOnImplThread();
127130}
128131
 132void CCLayerTreeHostImpl::trackDamageForAllSurfaces(CCLayerImpl* rootDrawLayer, const CCLayerList& renderSurfaceLayerList)
 133{
 134 // For now, we use damage tracking to compute a global scissor. To do this, we must
 135 // compute all damage tracking before drawing anything, so that we know the root
 136 // damage rect. The root damage rect is then used to scissor each surface.
 137
 138 for (int surfaceIndex = renderSurfaceLayerList.size() - 1; surfaceIndex >= 0 ; --surfaceIndex) {
 139 CCLayerImpl* renderSurfaceLayer = renderSurfaceLayerList[surfaceIndex].get();
 140 CCRenderSurface* renderSurface = renderSurfaceLayer->renderSurface();
 141 ASSERT(renderSurface);
 142 renderSurface->damageTracker()->updateDamageRectForNextFrame(renderSurface->layerList(), renderSurfaceLayer->id(), renderSurfaceLayer->maskLayer());
 143 }
 144}
 145
 146static TransformationMatrix computeScreenSpaceTransformForSurface(CCLayerImpl* renderSurfaceLayer)
 147{
 148 // The layer's screen space transform can be written as:
 149 // layerScreenSpaceTransform = surfaceScreenSpaceTransform * layerOriginTransform
 150 // So, to compute the surface screen space, we can do:
 151 // surfaceScreenSpaceTransform = layerScreenSpaceTransform * inverse(layerOriginTransform)
 152
 153 TransformationMatrix layerOriginTransform = renderSurfaceLayer->drawTransform();
 154 layerOriginTransform.translate(-0.5 * renderSurfaceLayer->bounds().width(), -0.5 * renderSurfaceLayer->bounds().height());
 155 TransformationMatrix surfaceScreenSpaceTransform = renderSurfaceLayer->screenSpaceTransform();
 156 surfaceScreenSpaceTransform.multiply(layerOriginTransform.inverse());
 157
 158 return surfaceScreenSpaceTransform;
 159}
 160
 161static FloatRect damageInSurfaceSpace(CCLayerImpl* renderSurfaceLayer, const FloatRect& rootDamageRect)
 162{
 163 FloatRect surfaceDamageRect;
 164 // For now, we conservatively use the root damage as the damage for
 165 // all surfaces, except perspective transforms.
 166 TransformationMatrix screenSpaceTransform = computeScreenSpaceTransformForSurface(renderSurfaceLayer);
 167 if (screenSpaceTransform.hasPerspective()) {
 168 // Perspective projections do not play nice with mapRect of
 169 // inverse transforms. In this uncommon case, its simpler to
 170 // just redraw the entire surface.
 171 // FIXME: use calculateVisibleRect to handle projections.
 172 CCRenderSurface* renderSurface = renderSurfaceLayer->renderSurface();
 173 surfaceDamageRect = renderSurface->contentRect();
 174 } else {
 175 TransformationMatrix inverseScreenSpaceTransform = screenSpaceTransform.inverse();
 176 surfaceDamageRect = inverseScreenSpaceTransform.mapRect(rootDamageRect);
 177 }
 178 return surfaceDamageRect;
 179}
 180
 181void CCLayerTreeHostImpl::calculateRenderPasses(Vector<OwnPtr<CCRenderPass> >& passes)
 182{
 183 CCLayerList renderSurfaceLayerList;
 184 renderSurfaceLayerList.append(rootLayer());
 185
 186 if (!rootLayer()->renderSurface())
 187 rootLayer()->createRenderSurface();
 188 rootLayer()->renderSurface()->clearLayerList();
 189 rootLayer()->renderSurface()->setContentRect(IntRect(IntPoint(), viewportSize()));
 190
 191 rootLayer()->setClipRect(IntRect(IntPoint(), viewportSize()));
 192
 193 {
 194 TransformationMatrix identityMatrix;
 195 TRACE_EVENT("CCLayerTreeHostImpl::calcDrawEtc", this, 0);
 196 CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(rootLayer(), rootLayer(), identityMatrix, identityMatrix, renderSurfaceLayerList, rootLayer()->renderSurface()->layerList(), &m_layerSorter, layerRendererCapabilities().maxTextureSize);
 197 }
 198
 199 if (layerRendererCapabilities().usingPartialSwap)
 200 trackDamageForAllSurfaces(rootLayer(), renderSurfaceLayerList);
 201 FloatRect rootDamageRect = rootLayer()->renderSurface()->damageTracker()->currentDamageRect();
 202
 203 for (int surfaceIndex = renderSurfaceLayerList.size() - 1; surfaceIndex >= 0 ; --surfaceIndex) {
 204 CCLayerImpl* renderSurfaceLayer = renderSurfaceLayerList[surfaceIndex].get();
 205 CCRenderSurface* renderSurface = renderSurfaceLayer->renderSurface();
 206
 207 OwnPtr<CCRenderPass> pass = CCRenderPass::create(renderSurface);
 208
 209 FloatRect surfaceDamageRect;
 210 if (layerRendererCapabilities().usingPartialSwap)
 211 surfaceDamageRect = damageInSurfaceSpace(renderSurfaceLayer, rootDamageRect);
 212 pass->setSurfaceDamageRect(surfaceDamageRect);
 213
 214 const CCLayerList& layerList = renderSurface->layerList();
 215 for (unsigned layerIndex = 0; layerIndex < layerList.size(); ++layerIndex) {
 216 CCLayerImpl* layer = layerList[layerIndex].get();
 217 if (layer->visibleLayerRect().isEmpty())
 218 continue;
 219
 220 if (CCLayerTreeHostCommon::renderSurfaceContributesToTarget(layer, renderSurfaceLayer->id())) {
 221 pass->appendQuadsForRenderSurfaceLayer(layer);
 222 continue;
 223 }
 224
 225 pass->appendQuadsForLayer(layer);
 226 }
 227
 228 passes.append(pass.release());
 229 }
 230}
 231
129232void CCLayerTreeHostImpl::drawLayers()
130233{
131234 TRACE_EVENT("CCLayerTreeHostImpl::drawLayers", this, 0);
132235 ASSERT(m_layerRenderer);
133  if (m_layerRenderer->rootLayer())
134  m_layerRenderer->drawLayers();
 236
 237 if (!rootLayer())
 238 return;
 239
 240 Vector<OwnPtr<CCRenderPass> > passes;
 241 calculateRenderPasses(passes);
 242
 243 m_layerRenderer->beginDrawingFrame();
 244 for (size_t i = 0; i < passes.size(); ++i)
 245 m_layerRenderer->drawRenderPass(passes[i].get());
 246 m_layerRenderer->finishDrawingFrame();
135247
136248 ++m_frameNumber;
 249
 250 // The next frame should start by assuming nothing has changed, and changes are noted as they occur.
 251 rootLayer()->resetAllChangeTrackingForSubtree();
137252}
138253
139254void CCLayerTreeHostImpl::finishAllRendering()

Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.h

2626#define CCLayerTreeHostImpl_h
2727
2828#include "cc/CCInputHandler.h"
 29#include "cc/CCLayerSorter.h"
2930#include "cc/CCLayerTreeHost.h"
3031#include "cc/CCLayerTreeHostCommon.h"
 32#include "cc/CCRenderPass.h"
3133#include <wtf/RefPtr.h>
3234
3335#if USE(SKIA)

@@protected:
124126 int m_frameNumber;
125127
126128private:
 129 typedef Vector<RefPtr<CCLayerImpl> > CCLayerList;
 130
127131 void setPageScaleDelta(float);
128132 void applyPageScaleDeltaToScrollLayer();
129133 void adjustScrollsForPageScaleChange(float);
130134 void updateMaxScrollPosition();
 135 void trackDamageForAllSurfaces(CCLayerImpl* rootDrawLayer, const CCLayerList& renderSurfaceLayerList);
 136 void calculateRenderPasses(Vector<OwnPtr<CCRenderPass> >&);
131137
132138 OwnPtr<LayerRendererChromium> m_layerRenderer;
133139 RefPtr<CCLayerImpl> m_rootLayerImpl;

@@private:
145151 bool m_pinchGestureActive;
146152
147153 OwnPtr<CCPageScaleAnimation> m_pageScaleAnimation;
 154
 155 CCLayerSorter m_layerSorter;
148156};
149157
150158};

Source/WebCore/platform/graphics/chromium/cc/CCRenderPass.cpp

 1/*
 2 * Copyright (C) 2011 Google Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 *
 8 * 1. Redistributions of source code must retain the above copyright
 9 * notice, this list of conditions and the following disclaimer.
 10 * 2. Redistributions in binary form must reproduce the above copyright
 11 * notice, this list of conditions and the following disclaimer in the
 12 * documentation and/or other materials provided with the distribution.
 13 *
 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#include "config.h"
 27
 28#include "cc/CCRenderPass.h"
 29
 30#include "cc/CCLayerImpl.h"
 31#include "cc/CCRenderSurfaceDrawQuad.h"
 32#include "cc/CCSharedQuadState.h"
 33
 34namespace WebCore {
 35
 36PassOwnPtr<CCRenderPass> CCRenderPass::create(CCRenderSurface* targetSurface)
 37{
 38 return adoptPtr(new CCRenderPass(targetSurface));
 39}
 40
 41CCRenderPass::CCRenderPass(CCRenderSurface* targetSurface)
 42 : m_targetSurface(targetSurface)
 43{
 44 ASSERT(m_targetSurface);
 45}
 46
 47void CCRenderPass::appendQuadsForLayer(CCLayerImpl* layer)
 48{
 49 OwnPtr<CCSharedQuadState> sharedQuadState = layer->createSharedQuadState();
 50 layer->appendQuads(m_quadList, sharedQuadState.get());
 51 layer->appendDebugBorderQuad(m_quadList, sharedQuadState.get());
 52 m_sharedQuadStateList.append(sharedQuadState.release());
 53}
 54
 55void CCRenderPass::appendQuadsForRenderSurfaceLayer(CCLayerImpl* layer)
 56{
 57 // FIXME: render surface layers should be a CCLayerImpl-derived class and
 58 // not be handled specially here.
 59 CCRenderSurface* surface = layer->renderSurface();
 60 bool isOpaque = false;
 61 OwnPtr<CCSharedQuadState> sharedQuadState = CCSharedQuadState::create(surface->drawTransform(), surface->drawTransform(), surface->contentRect(), surface->clipRect(), surface->drawOpacity(), isOpaque);
 62 m_quadList.append(CCRenderSurfaceDrawQuad::create(sharedQuadState.get(), surface->contentRect(), layer, surfaceDamageRect()));
 63 m_sharedQuadStateList.append(sharedQuadState.release());
 64}
 65
 66}

Source/WebCore/platform/graphics/chromium/cc/CCRenderPass.h

 1/*
 2 * Copyright (C) 2011 Google Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 *
 8 * 1. Redistributions of source code must retain the above copyright
 9 * notice, this list of conditions and the following disclaimer.
 10 * 2. Redistributions in binary form must reproduce the above copyright
 11 * notice, this list of conditions and the following disclaimer in the
 12 * documentation and/or other materials provided with the distribution.
 13 *
 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#ifndef CCRenderPass_h
 27#define CCRenderPass_h
 28
 29#include "cc/CCDrawQuad.h"
 30#include <wtf/PassOwnPtr.h>
 31#include <wtf/Vector.h>
 32
 33namespace WebCore {
 34
 35class CCLayerImpl;
 36class CCRenderSurface;
 37class CCSharedQuadState;
 38
 39typedef Vector<OwnPtr<CCDrawQuad> > CCQuadList;
 40
 41class CCRenderPass {
 42 WTF_MAKE_NONCOPYABLE(CCRenderPass);
 43public:
 44 static PassOwnPtr<CCRenderPass> create(CCRenderSurface*);
 45
 46 void appendQuadsForLayer(CCLayerImpl*);
 47 void appendQuadsForRenderSurfaceLayer(CCLayerImpl*);
 48
 49 const CCQuadList& quadList() const { return m_quadList; }
 50 CCRenderSurface* targetSurface() const { return m_targetSurface; }
 51
 52 void setSurfaceDamageRect(const FloatRect& surfaceDamageRect) { m_surfaceDamageRect = surfaceDamageRect; }
 53 const FloatRect& surfaceDamageRect() const { return m_surfaceDamageRect; }
 54
 55private:
 56 explicit CCRenderPass(CCRenderSurface*);
 57
 58 CCRenderSurface* m_targetSurface;
 59 CCQuadList m_quadList;
 60 Vector<OwnPtr<CCSharedQuadState> > m_sharedQuadStateList;
 61 FloatRect m_surfaceDamageRect;
 62};
 63
 64}
 65
 66#endif

Source/WebCore/platform/graphics/chromium/cc/CCRenderSurfaceDrawQuad.cpp

 1/*
 2 * Copyright (C) 2011 Google Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 *
 8 * 1. Redistributions of source code must retain the above copyright
 9 * notice, this list of conditions and the following disclaimer.
 10 * 2. Redistributions in binary form must reproduce the above copyright
 11 * notice, this list of conditions and the following disclaimer in the
 12 * documentation and/or other materials provided with the distribution.
 13 *
 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#include "config.h"
 27
 28#include "cc/CCRenderSurfaceDrawQuad.h"
 29
 30namespace WebCore {
 31
 32PassOwnPtr<CCRenderSurfaceDrawQuad> CCRenderSurfaceDrawQuad::create(const CCSharedQuadState* sharedQuadState, const IntRect& quadRect, CCLayerImpl* layer, const FloatRect& surfaceDamageRect)
 33{
 34 return adoptPtr(new CCRenderSurfaceDrawQuad(sharedQuadState, quadRect, layer, surfaceDamageRect));
 35}
 36
 37CCRenderSurfaceDrawQuad::CCRenderSurfaceDrawQuad(const CCSharedQuadState* sharedQuadState, const IntRect& quadRect, CCLayerImpl* layer, const FloatRect& surfaceDamageRect)
 38 : CCDrawQuad(sharedQuadState, CCDrawQuad::RenderSurface, quadRect)
 39 , m_layer(layer)
 40 , m_surfaceDamageRect(surfaceDamageRect)
 41{
 42 ASSERT(m_layer);
 43}
 44
 45}

Source/WebCore/platform/graphics/chromium/cc/CCRenderSurfaceDrawQuad.h

 1/*
 2 * Copyright (C) 2011 Google Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 *
 8 * 1. Redistributions of source code must retain the above copyright
 9 * notice, this list of conditions and the following disclaimer.
 10 * 2. Redistributions in binary form must reproduce the above copyright
 11 * notice, this list of conditions and the following disclaimer in the
 12 * documentation and/or other materials provided with the distribution.
 13 *
 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#ifndef CCRenderSurfaceDrawQuad_h
 27#define CCRenderSurfaceDrawQuad_h
 28
 29#include "cc/CCDrawQuad.h"
 30#include <wtf/PassOwnPtr.h>
 31
 32namespace WebCore {
 33
 34class CCLayerImpl;
 35
 36class CCRenderSurfaceDrawQuad : public CCDrawQuad {
 37 WTF_MAKE_NONCOPYABLE(CCRenderSurfaceDrawQuad);
 38public:
 39 static PassOwnPtr<CCRenderSurfaceDrawQuad> create(const CCSharedQuadState*, const IntRect&, CCLayerImpl*, const FloatRect& surfaceDamageRect);
 40
 41 CCLayerImpl* layer() const { return m_layer; }
 42
 43 // The surface damage rect for the target surface this quad draws into.
 44 // FIXME: This can be removed once render surfaces get their own layer type.
 45 const FloatRect& surfaceDamageRect() const { return m_surfaceDamageRect; }
 46
 47private:
 48 CCRenderSurfaceDrawQuad(const CCSharedQuadState*, const IntRect&, CCLayerImpl*, const FloatRect& surfaceDamageRect);
 49
 50 CCLayerImpl* m_layer;
 51 FloatRect m_surfaceDamageRect;
 52};
 53
 54}
 55
 56#endif

Source/WebCore/platform/graphics/chromium/cc/CCSharedQuadState.cpp

 1/*
 2 * Copyright (C) 2011 Google Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 *
 8 * 1. Redistributions of source code must retain the above copyright
 9 * notice, this list of conditions and the following disclaimer.
 10 * 2. Redistributions in binary form must reproduce the above copyright
 11 * notice, this list of conditions and the following disclaimer in the
 12 * documentation and/or other materials provided with the distribution.
 13 *
 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#include "config.h"
 27
 28#include "cc/CCSharedQuadState.h"
 29
 30namespace WebCore {
 31
 32PassOwnPtr<CCSharedQuadState> CCSharedQuadState::create(const TransformationMatrix& quadTransform, const TransformationMatrix& layerTransform, const IntRect& layerRect, const IntRect& clipRect, float opacity, bool opaque)
 33{
 34 return adoptPtr(new CCSharedQuadState(quadTransform, layerTransform, layerRect, clipRect, opacity, opaque));
 35}
 36
 37CCSharedQuadState::CCSharedQuadState(const TransformationMatrix& quadTransform, const TransformationMatrix& layerTransform, const IntRect& layerRect, const IntRect& clipRect, float opacity, bool opaque)
 38 : m_quadTransform(quadTransform)
 39 , m_layerTransform(layerTransform)
 40 , m_layerRect(layerRect)
 41 , m_clipRect(clipRect)
 42 , m_opacity(opacity)
 43 , m_opaque(opaque)
 44{
 45}
 46
 47bool CCSharedQuadState::isLayerAxisAlignedIntRect() const
 48{
 49 // Note: this doesn't consider window or projection matrices.
 50 // Assume that they're orthonormal and have integer scales and translations.
 51 FloatQuad quad = quadTransform().mapQuad(FloatQuad(layerRect()));
 52 return quad.isRectilinear() && quad.boundingBox().isExpressibleAsIntRect();
 53}
 54
 55}

Source/WebCore/platform/graphics/chromium/cc/CCSharedQuadState.h

 1/*
 2 * Copyright (C) 2011 Google Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 *
 8 * 1. Redistributions of source code must retain the above copyright
 9 * notice, this list of conditions and the following disclaimer.
 10 * 2. Redistributions in binary form must reproduce the above copyright
 11 * notice, this list of conditions and the following disclaimer in the
 12 * documentation and/or other materials provided with the distribution.
 13 *
 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#ifndef CCSharedQuadState_h
 27#define CCSharedQuadState_h
 28
 29#include "FloatQuad.h"
 30#include "IntRect.h"
 31#include "TransformationMatrix.h"
 32#include <wtf/PassOwnPtr.h>
 33
 34namespace WebCore {
 35
 36class CCSharedQuadState {
 37 WTF_MAKE_NONCOPYABLE(CCSharedQuadState);
 38public:
 39 static PassOwnPtr<CCSharedQuadState> create(const TransformationMatrix& quadTransform, const TransformationMatrix& layerTransform, const IntRect& layerRect, const IntRect& clipRect, float opacity, bool opaque);
 40
 41 // The transform that quads in a CCDrawQuad should be transformed with.
 42 const TransformationMatrix& quadTransform() const { return m_quadTransform; }
 43 // The transform that layerRect() should be transformed with.
 44 const TransformationMatrix& layerTransform() const { return m_layerTransform; }
 45 const IntRect& layerRect() const { return m_layerRect; }
 46 const IntRect& clipRect() const { return m_clipRect; }
 47
 48 float opacity() const { return m_opacity; }
 49 bool isOpaque() const { return m_opaque; }
 50 bool isLayerAxisAlignedIntRect() const;
 51
 52private:
 53 CCSharedQuadState(const TransformationMatrix& quadTransform, const TransformationMatrix& layerTransform, const IntRect& layerRect, const IntRect& clipRect, float opacity, bool opaque);
 54
 55 TransformationMatrix m_quadTransform;
 56 TransformationMatrix m_layerTransform;
 57 IntRect m_layerRect;
 58 IntRect m_clipRect;
 59 float m_opacity;
 60 bool m_opaque;
 61};
 62
 63}
 64
 65#endif

Source/WebCore/platform/graphics/chromium/cc/CCSolidColorDrawQuad.cpp

 1/*
 2 * Copyright (C) 2011 Google Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 *
 8 * 1. Redistributions of source code must retain the above copyright
 9 * notice, this list of conditions and the following disclaimer.
 10 * 2. Redistributions in binary form must reproduce the above copyright
 11 * notice, this list of conditions and the following disclaimer in the
 12 * documentation and/or other materials provided with the distribution.
 13 *
 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#include "config.h"
 27
 28#include "cc/CCSolidColorDrawQuad.h"
 29
 30namespace WebCore {
 31
 32PassOwnPtr<CCSolidColorDrawQuad> CCSolidColorDrawQuad::create(const CCSharedQuadState* sharedQuadState, const IntRect& quadRect, const Color& color)
 33{
 34 return adoptPtr(new CCSolidColorDrawQuad(sharedQuadState, quadRect, color));
 35}
 36
 37CCSolidColorDrawQuad::CCSolidColorDrawQuad(const CCSharedQuadState* sharedQuadState, const IntRect& quadRect, const Color& color)
 38 : CCDrawQuad(sharedQuadState, CCDrawQuad::SolidColor, quadRect)
 39 , m_color(color)
 40{
 41 if (m_color.alpha() != 1)
 42 m_quadOpaque = false;
 43}
 44
 45}

Source/WebCore/platform/graphics/chromium/cc/CCSolidColorDrawQuad.h

 1/*
 2 * Copyright (C) 2011 Google Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 *
 8 * 1. Redistributions of source code must retain the above copyright
 9 * notice, this list of conditions and the following disclaimer.
 10 * 2. Redistributions in binary form must reproduce the above copyright
 11 * notice, this list of conditions and the following disclaimer in the
 12 * documentation and/or other materials provided with the distribution.
 13 *
 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#ifndef CCSolidColorDrawQuad_h
 27#define CCSolidColorDrawQuad_h
 28
 29#include "Color.h"
 30#include "cc/CCDrawQuad.h"
 31#include <wtf/PassOwnPtr.h>
 32
 33namespace WebCore {
 34
 35class CCSolidColorDrawQuad : public CCDrawQuad {
 36 WTF_MAKE_NONCOPYABLE(CCSolidColorDrawQuad);
 37public:
 38 static PassOwnPtr<CCSolidColorDrawQuad> create(const CCSharedQuadState*, const IntRect&, const Color&);
 39
 40 const Color& color() const { return m_color; };
 41
 42private:
 43 CCSolidColorDrawQuad(const CCSharedQuadState*, const IntRect&, const Color&);
 44
 45 Color m_color;
 46};
 47
 48}
 49
 50#endif

Source/WebCore/platform/graphics/chromium/cc/CCTileDrawQuad.cpp

 1/*
 2 * Copyright (C) 2011 Google Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 *
 8 * 1. Redistributions of source code must retain the above copyright
 9 * notice, this list of conditions and the following disclaimer.
 10 * 2. Redistributions in binary form must reproduce the above copyright
 11 * notice, this list of conditions and the following disclaimer in the
 12 * documentation and/or other materials provided with the distribution.
 13 *
 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#include "config.h"
 27
 28#include "cc/CCTileDrawQuad.h"
 29
 30namespace WebCore {
 31
 32PassOwnPtr<CCTileDrawQuad> CCTileDrawQuad::create(const CCSharedQuadState* sharedQuadState, const IntRect& quadRect, Platform3DObject textureId, const IntPoint& textureOffset, const IntSize& textureSize, GC3Dint textureFilter, bool swizzleContents, bool leftEdgeAA, bool topEdgeAA, bool rightEdgeAA, bool bottomEdgeAA)
 33{
 34 return adoptPtr(new CCTileDrawQuad(sharedQuadState, quadRect, textureId, textureOffset, textureSize, textureFilter, swizzleContents, leftEdgeAA, topEdgeAA, rightEdgeAA, bottomEdgeAA));
 35}
 36
 37CCTileDrawQuad::CCTileDrawQuad(const CCSharedQuadState* sharedQuadState, const IntRect& quadRect, Platform3DObject textureId, const IntPoint& textureOffset, const IntSize& textureSize, GC3Dint textureFilter, bool swizzleContents, bool leftEdgeAA, bool topEdgeAA, bool rightEdgeAA, bool bottomEdgeAA)
 38 : CCDrawQuad(sharedQuadState, CCDrawQuad::TiledContent, quadRect)
 39 , m_textureId(textureId)
 40 , m_textureOffset(textureOffset)
 41 , m_textureSize(textureSize)
 42 , m_textureFilter(textureFilter)
 43 , m_swizzleContents(swizzleContents)
 44 , m_leftEdgeAA(leftEdgeAA)
 45 , m_topEdgeAA(topEdgeAA)
 46 , m_rightEdgeAA(rightEdgeAA)
 47 , m_bottomEdgeAA(bottomEdgeAA)
 48{
 49 if (isAntialiased())
 50 m_needsBlending = true;
 51}
 52
 53}

Source/WebCore/platform/graphics/chromium/cc/CCTileDrawQuad.h

 1/*
 2 * Copyright (C) 2011 Google Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 *
 8 * 1. Redistributions of source code must retain the above copyright
 9 * notice, this list of conditions and the following disclaimer.
 10 * 2. Redistributions in binary form must reproduce the above copyright
 11 * notice, this list of conditions and the following disclaimer in the
 12 * documentation and/or other materials provided with the distribution.
 13 *
 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#ifndef CCTileDrawQuad_h
 27#define CCTileDrawQuad_h
 28
 29#include "GraphicsTypes3D.h"
 30#include "cc/CCDrawQuad.h"
 31#include <wtf/PassOwnPtr.h>
 32
 33namespace WebCore {
 34
 35class CCTileDrawQuad : public CCDrawQuad {
 36 WTF_MAKE_NONCOPYABLE(CCTileDrawQuad);
 37public:
 38 static PassOwnPtr<CCTileDrawQuad> create(const CCSharedQuadState*, const IntRect& quadRect, Platform3DObject textureId, const IntPoint& textureOffset, const IntSize& textureSize, GC3Dint textureFilter, bool swizzleContents, bool leftEdgeAA, bool topEdgeAA, bool rightEdgeAA, bool bottomEdgeAA);
 39
 40 Platform3DObject textureId() const { return m_textureId; }
 41 IntPoint textureOffset() const { return m_textureOffset; }
 42 IntSize textureSize() const { return m_textureSize; }
 43 GC3Dint textureFilter() const { return m_textureFilter; }
 44 bool swizzleContents() const { return m_swizzleContents; }
 45
 46 bool leftEdgeAA() const { return m_leftEdgeAA; }
 47 bool topEdgeAA() const { return m_topEdgeAA; }
 48 bool rightEdgeAA() const { return m_rightEdgeAA; }
 49 bool bottomEdgeAA() const { return m_bottomEdgeAA; }
 50
 51 bool isAntialiased() const { return leftEdgeAA() || topEdgeAA() || rightEdgeAA() || bottomEdgeAA(); }
 52
 53private:
 54 CCTileDrawQuad(const CCSharedQuadState*, const IntRect& quadRect, Platform3DObject textureId, const IntPoint& textureOffset, const IntSize& textureSize, GC3Dint textureFilter, bool swizzleContents, bool leftEdgeAA, bool topEdgeAA, bool rightEdgeAA, bool bottomEdgeAA);
 55
 56 Platform3DObject m_textureId;
 57 IntPoint m_textureOffset;
 58 IntSize m_textureSize;
 59 GC3Dint m_textureFilter;
 60 bool m_swizzleContents;
 61 bool m_leftEdgeAA;
 62 bool m_topEdgeAA;
 63 bool m_rightEdgeAA;
 64 bool m_bottomEdgeAA;
 65};
 66
 67}
 68
 69#endif

Source/WebCore/platform/graphics/chromium/cc/CCTiledLayerImpl.cpp

3030#include "cc/CCTiledLayerImpl.h"
3131
3232#include "LayerRendererChromium.h"
33 #include "cc/CCLayerQuad.h"
 33#include "cc/CCSolidColorDrawQuad.h"
 34#include "cc/CCTileDrawQuad.h"
3435#include <wtf/text/WTFString.h>
3536
3637using namespace std;

@@private:
5354CCTiledLayerImpl::CCTiledLayerImpl(int id)
5455 : CCLayerImpl(id)
5556 , m_skipsDraw(true)
 57 , m_contentsSwizzled(false)
5658{
5759}
5860

@@DrawableTile* CCTiledLayerImpl::createTile(int i, int j)
9799 return tile.get();
98100}
99101
100 TransformationMatrix CCTiledLayerImpl::tilingTransform() const
 102TransformationMatrix CCTiledLayerImpl::quadTransform() const
101103{
102104 TransformationMatrix transform = drawTransform();
103105

@@TransformationMatrix CCTiledLayerImpl::tilingTransform() const
112114 return transform;
113115}
114116
115 void CCTiledLayerImpl::draw(LayerRendererChromium* layerRenderer)
 117void CCTiledLayerImpl::appendQuads(CCQuadList& quadList, const CCSharedQuadState* sharedQuadState)
116118{
117  const IntRect& layerRect = visibleLayerRect();
 119 const IntRect& contentRect = visibleLayerRect();
118120
119  if (m_skipsDraw || !m_tiler || m_tiler->isEmpty() || layerRect.isEmpty() || !layerRenderer)
 121 if (m_skipsDraw || !m_tiler || m_tiler->isEmpty() || contentRect.isEmpty())
120122 return;
121123
122  TransformationMatrix layerTransform = tilingTransform();
123  TransformationMatrix deviceMatrix = TransformationMatrix(layerRenderer->windowMatrix() * layerRenderer->projectionMatrix() * layerTransform).to2dTransform();
 124 int left, top, right, bottom;
 125 m_tiler->contentRectToTileIndices(contentRect, left, top, right, bottom);
 126 IntRect layerRect = m_tiler->contentRectToLayerRect(contentRect);
 127 for (int j = top; j <= bottom; ++j) {
 128 for (int i = left; i <= right; ++i) {
 129 DrawableTile* tile = tileAt(i, j);
 130 IntRect tileRect = m_tiler->tileBounds(i, j);
 131 IntRect displayRect = tileRect;
 132 tileRect.intersect(layerRect);
124133
125  // Don't draw any tiles when device matrix is not invertible.
126  if (!deviceMatrix.isInvertible())
127  return;
 134 // Skip empty tiles.
 135 if (tileRect.isEmpty())
 136 continue;
128137
129  FloatQuad quad = deviceMatrix.mapQuad(FloatQuad(layerRect));
130  CCLayerQuad deviceRect = CCLayerQuad(FloatQuad(quad.boundingBox()));
131  CCLayerQuad layerQuad = CCLayerQuad(quad);
 138 if (!tile || !tile->textureId()) {
 139 quadList.append(CCSolidColorDrawQuad::create(sharedQuadState, tileRect, backgroundColor()));
 140 continue;
 141 }
 142
 143 // Keep track of how the top left has moved, so the texture can be
 144 // offset the same amount.
 145 IntSize displayOffset = tileRect.minXMinYCorner() - displayRect.minXMinYCorner();
 146 IntPoint textureOffset = m_tiler->textureOffset(i, j) + displayOffset;
 147 float tileWidth = static_cast<float>(m_tiler->tileSize().width());
 148 float tileHeight = static_cast<float>(m_tiler->tileSize().height());
 149 IntSize textureSize(tileWidth, tileHeight);
132150
133  // Use anti-aliasing programs only when necessary.
134  bool useAA = (m_tiler->hasBorderTexels() && (!quad.isRectilinear() || !quad.boundingBox().isExpressibleAsIntRect()));
 151 bool useAA = m_tiler->hasBorderTexels() && !sharedQuadState->isLayerAxisAlignedIntRect();
135152
136  if (useAA) {
137  deviceRect.inflateAntiAliasingDistance();
138  layerQuad.inflateAntiAliasingDistance();
139  }
 153 bool leftEdgeAA = !i && useAA;
 154 bool topEdgeAA = !j && useAA;
 155 bool rightEdgeAA = i == m_tiler->numTilesX() - 1 && useAA;
 156 bool bottomEdgeAA = j == m_tiler->numTilesY() - 1 && useAA;
140157
141  switch (m_sampledTexelFormat) {
142  case LayerTextureUpdater::SampledTexelFormatRGBA:
143  if (useAA) {
144  const ProgramAA* program = layerRenderer->tilerProgramAA();
145  drawTiles(layerRenderer, layerRect, layerTransform, deviceMatrix, deviceRect, layerQuad, drawOpacity(), program, program->fragmentShader().fragmentTexTransformLocation(), program->fragmentShader().edgeLocation());
146  } else {
147  if (isNonCompositedContent()) {
148  const ProgramOpaque* program = layerRenderer->tilerProgramOpaque();
149  drawTiles(layerRenderer, layerRect, layerTransform, deviceMatrix, deviceRect, layerQuad, drawOpacity(), program, -1, -1);
150  } else {
151  const Program* program = layerRenderer->tilerProgram();
152  drawTiles(layerRenderer, layerRect, layerTransform, deviceMatrix, deviceRect, layerQuad, drawOpacity(), program, -1, -1);
153  }
 158 const GC3Dint textureFilter = m_tiler->hasBorderTexels() ? GraphicsContext3D::LINEAR : GraphicsContext3D::NEAREST;
 159 quadList.append(CCTileDrawQuad::create(sharedQuadState, tileRect, tile->textureId(), textureOffset, textureSize, textureFilter, contentsSwizzled(), leftEdgeAA, topEdgeAA, rightEdgeAA, bottomEdgeAA));
154160 }
155  break;
156  case LayerTextureUpdater::SampledTexelFormatBGRA:
157  if (useAA) {
158  const ProgramSwizzleAA* program = layerRenderer->tilerProgramSwizzleAA();
159  drawTiles(layerRenderer, layerRect, layerTransform, deviceMatrix, deviceRect, layerQuad, drawOpacity(), program, program->fragmentShader().fragmentTexTransformLocation(), program->fragmentShader().edgeLocation());
160  } else {
161  if (isNonCompositedContent()) {
162  const ProgramSwizzleOpaque* program = layerRenderer->tilerProgramSwizzleOpaque();
163  drawTiles(layerRenderer, layerRect, layerTransform, deviceMatrix, deviceRect, layerQuad, drawOpacity(), program, -1, -1);
164  } else {
165  const ProgramSwizzle* program = layerRenderer->tilerProgramSwizzle();
166  drawTiles(layerRenderer, layerRect, layerTransform, deviceMatrix, deviceRect, layerQuad, drawOpacity(), program, -1, -1);
167  }
168  }
169  break;
170  default:
171  ASSERT_NOT_REACHED();
172161 }
173162}
174163

@@void CCTiledLayerImpl::syncTextureId(int i, int j, Platform3DObject textureId)
189178 tile->setTextureId(textureId);
190179}
191180
192 template <class T>
193 void CCTiledLayerImpl::drawTiles(LayerRendererChromium* layerRenderer, const IntRect& contentRect, const TransformationMatrix& globalTransform, const TransformationMatrix& deviceTransform, const CCLayerQuad& deviceRect, const CCLayerQuad& contentQuad, float opacity, const T* program, int fragmentTexTransformLocation, int edgeLocation)
194 {
195  GraphicsContext3D* context = layerRenderer->context();
196  GLC(context, context->useProgram(program->program()));
197  GLC(context, context->uniform1i(program->fragmentShader().samplerLocation(), 0));
198  GLC(context, context->activeTexture(GraphicsContext3D::TEXTURE0));
199 
200  TransformationMatrix quadTransform = deviceTransform.inverse();
201 
202  if (edgeLocation != -1) {
203  float edge[24];
204  contentQuad.toFloatArray(edge);
205  deviceRect.toFloatArray(&edge[12]);
206  GLC(context, context->uniform3fv(edgeLocation, edge, 8));
207  }
208 
209  CCLayerQuad::Edge prevEdgeY = contentQuad.top();
210 
211  int left, top, right, bottom;
212  m_tiler->contentRectToTileIndices(contentRect, left, top, right, bottom);
213  IntRect layerRect = m_tiler->contentRectToLayerRect(contentRect);
214  float sign = FloatQuad(contentRect).isCounterclockwise() ? -1 : 1;
215  const GC3Dint filter = m_tiler->hasBorderTexels() ? GraphicsContext3D::LINEAR : GraphicsContext3D::NEAREST;
216  for (int j = top; j <= bottom; ++j) {
217  CCLayerQuad::Edge prevEdgeX = contentQuad.left();
218 
219  CCLayerQuad::Edge edgeY = contentQuad.bottom();
220  if (j < (m_tiler->numTilesY() - 1)) {
221  IntRect tileRect = unionRect(m_tiler->tileBounds(0, j), m_tiler->tileBounds(m_tiler->numTilesX() - 1, j));
222  tileRect.intersect(layerRect);
223 
224  // Skip empty rows.
225  if (tileRect.isEmpty())
226  continue;
227 
228  tileRect = m_tiler->layerRectToContentRect(tileRect);
229 
230  FloatPoint p1(tileRect.maxX(), tileRect.maxY());
231  FloatPoint p2(tileRect.x(), tileRect.maxY());
232 
233  // Map points to device space.
234  p1 = deviceTransform.mapPoint(p1);
235  p2 = deviceTransform.mapPoint(p2);
236 
237  // Compute horizontal edge.
238  edgeY = CCLayerQuad::Edge(p1, p2);
239  edgeY.scale(sign);
240  }
241 
242  for (int i = left; i <= right; ++i) {
243  DrawableTile* tile = tileAt(i, j);
244 
245  // Don't use tileContentRect here, as that contains the full
246  // rect with border texels which shouldn't be drawn.
247  IntRect tileRect = m_tiler->tileBounds(i, j);
248  IntRect displayRect = tileRect;
249  tileRect.intersect(layerRect);
250 
251  // Keep track of how the top left has moved, so the texture can be
252  // offset the same amount.
253  IntSize displayOffset = tileRect.minXMinYCorner() - displayRect.minXMinYCorner();
254 
255  // Skip empty tiles.
256  if (tileRect.isEmpty())
257  continue;
258 
259  tileRect = m_tiler->layerRectToContentRect(tileRect);
260 
261  FloatRect clampRect(tileRect);
262  // Clamp texture coordinates to avoid sampling outside the layer
263  // by deflating the tile region half a texel or half a texel
264  // minus epsilon for one pixel layers. The resulting clamp region
265  // is mapped to the unit square by the vertex shader and mapped
266  // back to normalized texture coordinates by the fragment shader
267  // after being clamped to 0-1 range.
268  const float epsilon = 1 / 1024.0f;
269  float clampX = min(0.5, clampRect.width() / 2.0 - epsilon);
270  float clampY = min(0.5, clampRect.height() / 2.0 - epsilon);
271  clampRect.inflateX(-clampX);
272  clampRect.inflateY(-clampY);
273  FloatSize clampOffset = clampRect.minXMinYCorner() - FloatRect(tileRect).minXMinYCorner();
274 
275  FloatPoint texOffset = m_tiler->textureOffset(i, j) + clampOffset + FloatSize(displayOffset);
276  float tileWidth = static_cast<float>(m_tiler->tileSize().width());
277  float tileHeight = static_cast<float>(m_tiler->tileSize().height());
278 
279  // Map clamping rectangle to unit square.
280  float vertexTexTranslateX = -clampRect.x() / clampRect.width();
281  float vertexTexTranslateY = -clampRect.y() / clampRect.height();
282  float vertexTexScaleX = tileRect.width() / clampRect.width();
283  float vertexTexScaleY = tileRect.height() / clampRect.height();
284 
285  // Map to normalized texture coordinates.
286  float fragmentTexTranslateX = texOffset.x() / tileWidth;
287  float fragmentTexTranslateY = texOffset.y() / tileHeight;
288  float fragmentTexScaleX = clampRect.width() / tileWidth;
289  float fragmentTexScaleY = clampRect.height() / tileHeight;
290 
291  CCLayerQuad::Edge edgeX = contentQuad.right();
292  if (i < (m_tiler->numTilesX() - 1)) {
293  FloatPoint p1(tileRect.maxX(), tileRect.y());
294  FloatPoint p2(tileRect.maxX(), tileRect.maxY());
295 
296  // Map points to device space.
297  p1 = deviceTransform.mapPoint(p1);
298  p2 = deviceTransform.mapPoint(p2);
299 
300  // Compute vertical edge.
301  edgeX = CCLayerQuad::Edge(p1, p2);
302  edgeX.scale(sign);
303  }
304 
305  // Create device space quad.
306  CCLayerQuad deviceQuad(prevEdgeX, prevEdgeY, edgeX, edgeY);
307 
308  // Map quad to layer space.
309  FloatQuad quad = quadTransform.mapQuad(deviceQuad.floatQuad());
310 
311  // Normalize to tileRect.
312  quad.scale(1.0f / tileRect.width(), 1.0f / tileRect.height());
313 
314  if (fragmentTexTransformLocation == -1) {
315  // Move fragment shader transform to vertex shader. We can do
316  // this while still producing correct results as
317  // fragmentTexTransformLocation should always be non-negative
318  // when tiles are transformed in a way that could result in
319  // sampling outside the layer.
320  vertexTexScaleX *= fragmentTexScaleX;
321  vertexTexScaleY *= fragmentTexScaleY;
322  vertexTexTranslateX *= fragmentTexScaleX;
323  vertexTexTranslateY *= fragmentTexScaleY;
324  vertexTexTranslateX += fragmentTexTranslateX;
325  vertexTexTranslateY += fragmentTexTranslateY;
326  } else
327  GLC(context, context->uniform4f(fragmentTexTransformLocation, fragmentTexTranslateX, fragmentTexTranslateY, fragmentTexScaleX, fragmentTexScaleY));
328 
329  GLC(context, context->uniform4f(program->vertexShader().vertexTexTransformLocation(), vertexTexTranslateX, vertexTexTranslateY, vertexTexScaleX, vertexTexScaleY));
330 
331  if (tile && tile->textureId()) {
332  context->bindTexture(GraphicsContext3D::TEXTURE_2D, tile->textureId());
333  GLC(context, context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, filter));
334  GLC(context, context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, filter));
335 
336  layerRenderer->drawTexturedQuad(globalTransform,
337  tileRect.width(), tileRect.height(), opacity, quad,
338  program->vertexShader().matrixLocation(),
339  program->fragmentShader().alphaLocation(),
340  program->vertexShader().pointLocation());
341  } else {
342  TransformationMatrix tileTransform = globalTransform;
343  tileTransform.translate(tileRect.x() + tileRect.width() / 2.0, tileRect.y() + tileRect.height() / 2.0);
344 
345  const LayerChromium::BorderProgram* solidColorProgram = layerRenderer->borderProgram();
346  GLC(context, context->useProgram(solidColorProgram->program()));
347 
348  GLC(context, context->uniform4f(solidColorProgram->fragmentShader().colorLocation(), backgroundColor().red(), backgroundColor().green(), backgroundColor().blue(), backgroundColor().alpha()));
349 
350  layerRenderer->drawTexturedQuad(tileTransform,
351  tileRect.width(), tileRect.height(), opacity, quad,
352  solidColorProgram->vertexShader().matrixLocation(),
353  -1, -1);
354 
355  GLC(context, context->useProgram(program->program()));
356  }
357 
358  prevEdgeX = edgeX;
359  // Reverse direction.
360  prevEdgeX.scale(-1);
361  }
362 
363  prevEdgeY = edgeY;
364  // Reverse direction.
365  prevEdgeY.scale(-1);
366  }
367 }
368 
369181}
370182
371183#endif // USE(ACCELERATED_COMPOSITING)

Source/WebCore/platform/graphics/chromium/cc/CCTiledLayerImpl.h

@@public:
4343 }
4444 virtual ~CCTiledLayerImpl();
4545
46  virtual void draw(LayerRendererChromium*);
 46 virtual void appendQuads(CCQuadList&, const CCSharedQuadState*);
 47
4748 virtual void bindContentsTexture(LayerRendererChromium*);
4849
4950 virtual void dumpLayerProperties(TextStream&, int indent) const;
5051
5152 void setSkipsDraw(bool skipsDraw) { m_skipsDraw = skipsDraw; }
52  void setSampledTexelFormat(LayerTextureUpdater::SampledTexelFormat sampledTexelFormat) { m_sampledTexelFormat = sampledTexelFormat; }
5353 void setTilingData(const CCLayerTilingData& tiler);
5454 void syncTextureId(int, int, Platform3DObject textureId);
5555
 56 void setContentsSwizzled(bool contentsSwizzled) { m_contentsSwizzled = contentsSwizzled; }
 57 bool contentsSwizzled() const { return m_contentsSwizzled; }
 58
5659 typedef ProgramBinding<VertexShaderTile, FragmentShaderRGBATexAlpha> Program;
5760 // Shader program that swaps red and blue components of texture.
5861 // Used when texture format does not match native color format.

@@protected:
7174 // Exposed for testing.
7275 bool hasTileAt(int, int) const;
7376
 77 virtual TransformationMatrix quadTransform() const;
 78
7479private:
7580
7681 virtual const char* layerTypeAsString() const { return "ContentLayer"; }
7782
78  TransformationMatrix tilingTransform() const;
79 
80  // Draw all tiles that intersect with the content rect.
81  void draw(LayerRendererChromium*, const IntRect& contentRect, const TransformationMatrix&, float opacity);
82 
8383 DrawableTile* tileAt(int, int) const;
8484 DrawableTile* createTile(int, int);
8585
86  // Draw all tiles that intersect with contentRect.
87  template <class T>
88  void drawTiles(LayerRendererChromium*, const IntRect& contentRect, const TransformationMatrix& globalTransform, const TransformationMatrix& deviceTransform, const CCLayerQuad& deviceRect, const CCLayerQuad& contentQuad, float opacity, const T* program, int fragmentTexTransformLocation, int edgeLocation);
89 
9086 bool m_skipsDraw;
91  LayerTextureUpdater::SampledTexelFormat m_sampledTexelFormat;
 87 bool m_contentsSwizzled;
9288
9389 OwnPtr<CCLayerTilingData> m_tiler;
9490};

LayoutTests/ChangeLog

 12011-12-14 Adrienne Walker <enne@google.com>
 2
 3 [chromium] Refactor tile drawing to be more data-driven
 4 https://bugs.webkit.org/show_bug.cgi?id=73059
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Mark three tests as failing with small pixel differences. These just
 9 need rebaselining.
 10
 11 * platform/chromium/test_expectations.txt:
 12
1132011-12-14 Ryosuke Niwa <rniwa@webkit.org>
214
315 Skip fast/forms/select/menulist-onchange-fired-with-key-up-down.html on Mac since

LayoutTests/platform/chromium/test_expectations.txt

@@BUGWK73905 GPU LINUX : media/video-transformed.html = IMAGE
39673967BUGWK73905 GPU LINUX : media/video-zoom-controls.html = IMAGE
39683968BUGWK73905 GPU WIN : media/video-layer-crash.html = TEXT
39693969
 3970// Need rebaseline on all platforms
 3971BUGENNE : compositing/color-matching/image-color-matching.html = FAIL
 3972BUGENNE : compositing/geometry/vertical-scroll-composited.html = FAIL
 3973BUGENNE : compositing/scaling/tiled-layer-recursion.html = FAIL
 3974
39703975BUGWK73933 DEBUG : svg/W3C-SVG-1.1-SE/struct-dom-11-f.svg = TIMEOUT PASS
39713976
39723977BUGWK73991 WIN7 VISTA RELEASE : fast/text/international/complex-character-based-fallback.html = IMAGE+TEXT