void LayerTreeRenderer::paintToCurrentGLContext(const TransformationMatrix& matrix, float opacity, const FloatRect& clipRect, TextureMapper::PaintFlags PaintFlags) { if (!m_textureMapper) m_textureMapper = TextureMapper::create(TextureMapper::OpenGLMode); ASSERT(m_textureMapper->accelerationMode() == TextureMapper::OpenGLMode); adjustPositionForFixedLayers(); GraphicsLayer* currentRootLayer = rootLayer(); if (!currentRootLayer) return; TextureMapperLayer* layer = toTextureMapperLayer(currentRootLayer); if (!layer) return; layer->setTextureMapper(m_textureMapper.get()); m_textureMapper->beginPainting(PaintFlags); m_textureMapper->beginClip(TransformationMatrix(), clipRect); if (currentRootLayer->opacity() != opacity || currentRootLayer->transform() != matrix) { currentRootLayer->setOpacity(opacity); currentRootLayer->setTransform(matrix); currentRootLayer->syncCompositingStateForThisLayerOnly(); } layer->paint(); m_textureMapper->endClip(); m_textureMapper->endPainting(); }
void CoordinatedGraphicsScene::paintToGraphicsContext(PlatformGraphicsContext* platformContext, const Color& backgroundColor, bool drawsBackground) { if (!m_textureMapper) m_textureMapper = TextureMapper::create(); ASSERT(m_textureMapper->accelerationMode() == TextureMapper::SoftwareMode); syncRemoteContent(); TextureMapperLayer* layer = rootLayer(); if (!layer) return; GraphicsContext graphicsContext(platformContext); m_textureMapper->setGraphicsContext(&graphicsContext); m_textureMapper->beginPainting(); IntRect clipRect = graphicsContext.clipBounds(); if (drawsBackground) m_textureMapper->drawSolidColor(clipRect, TransformationMatrix(), backgroundColor); else m_textureMapper->drawSolidColor(clipRect, TransformationMatrix(), m_viewBackgroundColor); layer->paint(); m_fpsCounter.updateFPSAndDisplay(m_textureMapper.get(), clipRect.location()); m_textureMapper->endPainting(); m_textureMapper->setGraphicsContext(0); }
PassOwnPtr<GraphicsLayer> LayerTreeRenderer::createLayer(WebLayerID layerID) { GraphicsLayer* newLayer = new GraphicsLayerTextureMapper(this); TextureMapperLayer* layer = toTextureMapperLayer(newLayer); layer->setShouldUpdateBackingStoreFromLayer(false); return adoptPtr(newLayer); }
void TextureMapperLayer::removeAllChildren() { while (m_children.size()) { TextureMapperLayer* curLayer = m_children[0]; ASSERT(curLayer->m_parent); curLayer->removeFromParent(); } }
void LayerTreeHostProxy::syncAnimations() { TextureMapperLayer* layer = toTextureMapperLayer(rootLayer()); ASSERT(layer); layer->syncAnimationsRecursively(); if (layer->descendantsOrSelfHaveRunningAnimations()) updateViewport(); }
CoordinatedBackingStore* LayerTreeRenderer::getBackingStore(GraphicsLayer* graphicsLayer) { TextureMapperLayer* layer = toTextureMapperLayer(graphicsLayer); ASSERT(layer); CoordinatedBackingStore* backingStore = static_cast<CoordinatedBackingStore*>(layer->backingStore().get()); BackingStoreMap::iterator it = m_pendingSyncBackingStores.find(layer); if (it != m_pendingSyncBackingStores.end()) backingStore = it->value.get(); return backingStore; }
void CoordinatedGraphicsScene::paintToCurrentGLContext(const TransformationMatrix& matrix, float opacity, const FloatRect& clipRect, TextureMapper::PaintFlags PaintFlags) { if (!m_textureMapper) { m_textureMapper = TextureMapper::create(TextureMapper::OpenGLMode); static_cast<TextureMapperGL*>(m_textureMapper.get())->setEnableEdgeDistanceAntialiasing(true); } ASSERT(m_textureMapper->accelerationMode() == TextureMapper::OpenGLMode); syncRemoteContent(); adjustPositionForFixedLayers(); GraphicsLayer* currentRootLayer = rootLayer(); if (!currentRootLayer) return; TextureMapperLayer* layer = toTextureMapperLayer(currentRootLayer); if (!layer) return; layer->setTextureMapper(m_textureMapper.get()); if (!m_animationsLocked) layer->applyAnimationsRecursively(); m_textureMapper->beginPainting(PaintFlags); m_textureMapper->beginClip(TransformationMatrix(), clipRect); if (m_setDrawsBackground) { RGBA32 rgba = makeRGBA32FromFloats(m_backgroundColor.red(), m_backgroundColor.green(), m_backgroundColor.blue(), m_backgroundColor.alpha() * opacity); m_textureMapper->drawSolidColor(clipRect, TransformationMatrix(), Color(rgba)); } if (currentRootLayer->opacity() != opacity || currentRootLayer->transform() != matrix) { currentRootLayer->setOpacity(opacity); currentRootLayer->setTransform(matrix); currentRootLayer->flushCompositingStateForThisLayerOnly(); } layer->paint(); m_fpsCounter.updateFPSAndDisplay(m_textureMapper.get(), clipRect.location(), matrix); m_textureMapper->endClip(); m_textureMapper->endPainting(); if (layer->descendantsOrSelfHaveRunningAnimations()) dispatchOnMainThread(bind(&CoordinatedGraphicsScene::updateViewport, this)); #if ENABLE(REQUEST_ANIMATION_FRAME) if (m_animationFrameRequested) { m_animationFrameRequested = false; dispatchOnMainThread(bind(&CoordinatedGraphicsScene::animationFrameReady, this)); } #endif }
bool TextureMapperLayer::scrollableLayerHitTestCondition(TextureMapperLayer* layer, const FloatPoint& point) { // scrolling layer's m_parent->m_parent, the parent of the scrolling layes, is the one that defines the // rectangle to be used for hit testing. if (!layer->isScrollable() || !layer->m_parent || !layer->m_parent->m_parent) return false; TextureMapperLayer* parentLayer = layer->m_parent->m_parent; FloatRect rect = parentLayer->layerRect(); return parentLayer->m_currentTransform.combined().mapQuad(rect).containsPoint(point); }
void LayerTreeHostProxy::purgeGLResources() { TextureMapperLayer* layer = toTextureMapperLayer(rootLayer()); if (layer) layer->clearBackingStoresRecursive(); m_directlyCompositedImages.clear(); m_textureMapper.clear(); m_backingStoresWithPendingBuffers.clear(); m_drawingAreaProxy->page()->process()->send(Messages::LayerTreeHost::PurgeBackingStores(), m_drawingAreaProxy->page()->pageID()); }
PassRefPtr<LayerBackingStore> LayerTreeHostProxy::getBackingStore(WebLayerID id) { ensureLayer(id); TextureMapperLayer* layer = toTextureMapperLayer(layerByID(id)); RefPtr<LayerBackingStore> backingStore = static_cast<LayerBackingStore*>(layer->backingStore().get()); if (!backingStore) { backingStore = LayerBackingStore::create(); layer->setBackingStore(backingStore.get()); } ASSERT(backingStore); return backingStore; }
PassRefPtr<CoordinatedBackingStore> LayerTreeRenderer::getBackingStore(WebLayerID id) { TextureMapperLayer* layer = toTextureMapperLayer(layerByID(id)); ASSERT(layer); RefPtr<CoordinatedBackingStore> backingStore = static_cast<CoordinatedBackingStore*>(layer->backingStore().get()); if (!backingStore) { backingStore = CoordinatedBackingStore::create(); layer->setBackingStore(backingStore.get()); } ASSERT(backingStore); return backingStore; }
void CoordinatedGraphicsScene::paintToCurrentGLContext(const TransformationMatrix& matrix, float opacity, const FloatRect& clipRect, const Color& backgroundColor, bool drawsBackground, const FloatPoint& contentPosition, TextureMapper::PaintFlags PaintFlags) { if (!m_textureMapper) { m_textureMapper = TextureMapper::create(); static_cast<TextureMapperGL*>(m_textureMapper.get())->setEnableEdgeDistanceAntialiasing(true); } syncRemoteContent(); adjustPositionForFixedLayers(contentPosition); TextureMapperLayer* currentRootLayer = rootLayer(); if (!currentRootLayer) return; #if USE(COORDINATED_GRAPHICS_THREADED) for (auto& proxy : m_platformLayerProxies.values()) proxy->swapBuffer(); #endif currentRootLayer->setTextureMapper(m_textureMapper.get()); currentRootLayer->applyAnimationsRecursively(); m_textureMapper->beginPainting(PaintFlags); m_textureMapper->beginClip(TransformationMatrix(), clipRect); if (drawsBackground) { RGBA32 rgba = makeRGBA32FromFloats(backgroundColor.red(), backgroundColor.green(), backgroundColor.blue(), backgroundColor.alpha() * opacity); m_textureMapper->drawSolidColor(clipRect, TransformationMatrix(), Color(rgba)); } else { GraphicsContext3D* context = static_cast<TextureMapperGL*>(m_textureMapper.get())->graphicsContext3D(); context->clearColor(m_viewBackgroundColor.red() / 255.0f, m_viewBackgroundColor.green() / 255.0f, m_viewBackgroundColor.blue() / 255.0f, m_viewBackgroundColor.alpha() / 255.0f); context->clear(GraphicsContext3D::COLOR_BUFFER_BIT); } if (currentRootLayer->opacity() != opacity || currentRootLayer->transform() != matrix) { currentRootLayer->setOpacity(opacity); currentRootLayer->setTransform(matrix); } currentRootLayer->paint(); m_fpsCounter.updateFPSAndDisplay(*m_textureMapper, clipRect.location(), matrix); m_textureMapper->endClip(); m_textureMapper->endPainting(); if (currentRootLayer->descendantsOrSelfHaveRunningAnimations()) { RefPtr<CoordinatedGraphicsScene> protector(this); dispatchOnClientRunLoop([=] { protector->updateViewport(); }); } }
void LayerTreeRenderer::paintToGraphicsContext(BackingStore::PlatformGraphicsContext painter) { if (!m_textureMapper) m_textureMapper = TextureMapper::create(); ASSERT(m_textureMapper->accelerationMode() == TextureMapper::SoftwareMode); syncRemoteContent(); TextureMapperLayer* layer = toTextureMapperLayer(rootLayer()); if (!layer) return; GraphicsContext graphicsContext(painter); m_textureMapper->setGraphicsContext(&graphicsContext); m_textureMapper->beginPainting(); layer->paint(); m_textureMapper->endPainting(); m_textureMapper->setGraphicsContext(0); }
void LayerTreeHostProxy::paintToGraphicsContext(QPainter* painter) { if (!m_textureMapper) m_textureMapper = TextureMapper::create(); ASSERT(m_textureMapper->accelerationMode() == TextureMapper::SoftwareMode); syncRemoteContent(); TextureMapperLayer* layer = toTextureMapperLayer(rootLayer()); if (!layer) return; GraphicsContext graphicsContext(painter); m_textureMapper->setGraphicsContext(&graphicsContext); m_textureMapper->beginPainting(); m_textureMapper->bindSurface(0); layer->paint(); m_textureMapper->endPainting(); m_textureMapper->setGraphicsContext(0); }
void TextureMapperLayer::syncCompositingState(GraphicsLayerTextureMapper* graphicsLayer, TextureMapper* textureMapper, int options) { if (!textureMapper) return; if (graphicsLayer && !(options & ComputationsOnly)) { syncCompositingStateSelf(graphicsLayer, textureMapper); graphicsLayer->didSynchronize(); } if (graphicsLayer && m_state.maskLayer) { m_state.maskLayer->syncCompositingState(toGraphicsLayerTextureMapper(graphicsLayer->maskLayer()), textureMapper); // A mask layer has its parent's size by default, in case it's not set specifically. if (m_state.maskLayer->m_size.isEmpty()) m_state.maskLayer->m_size = m_size; } if (m_state.replicaLayer) m_state.replicaLayer->syncCompositingState(toGraphicsLayerTextureMapper(graphicsLayer->replicaLayer()), textureMapper); syncAnimations(); updateBackingStore(textureMapper, graphicsLayer); if (!(options & TraverseDescendants)) options = ComputationsOnly; if (graphicsLayer) { Vector<GraphicsLayer*> children = graphicsLayer->children(); for (int i = children.size() - 1; i >= 0; --i) { TextureMapperLayer* layer = toTextureMapperLayer(children[i]); if (!layer) continue; layer->syncCompositingState(toGraphicsLayerTextureMapper(children[i]), textureMapper, options); } } else { for (int i = m_children.size() - 1; i >= 0; --i) m_children[i]->syncCompositingState(0, textureMapper, options); } }
void LayerTreeRenderer::removeBackingStoreIfNeeded(GraphicsLayer* graphicsLayer) { TextureMapperLayer* layer = toTextureMapperLayer(graphicsLayer); ASSERT(layer); // Check if the layout already has a backing store (committed or pending). BackingStoreMap::iterator it = m_pendingSyncBackingStores.find(layer); if (it != m_pendingSyncBackingStores.end()) { if (it->value) { // There is a pending addition, cancel it. m_pendingSyncBackingStores.remove(it); } // There is already a pending removal. return; } if (!layer->backingStore()) return; // The layer has no backing store (and no pending addition). ASSERT(!m_pendingSyncBackingStores.contains(layer)); m_pendingSyncBackingStores.add(layer, 0); }
void LayerTreeRenderer::paintToGraphicsContext(BackingStore::PlatformGraphicsContext painter) { if (!m_textureMapper) m_textureMapper = TextureMapper::create(); ASSERT(m_textureMapper->accelerationMode() == TextureMapper::SoftwareMode); syncRemoteContent(); TextureMapperLayer* layer = toTextureMapperLayer(rootLayer()); if (!layer) return; GraphicsContext graphicsContext(painter); m_textureMapper->setGraphicsContext(&graphicsContext); m_textureMapper->beginPainting(); if (m_setDrawsBackground) m_textureMapper->drawSolidColor(graphicsContext.clipBounds(), TransformationMatrix(), m_backgroundColor); layer->paint(); m_textureMapper->endPainting(); m_textureMapper->setGraphicsContext(0); }
void LayerTreeRenderer::createBackingStoreIfNeeded(GraphicsLayer* graphicsLayer) { TextureMapperLayer* layer = toTextureMapperLayer(graphicsLayer); ASSERT(layer); // Make sure the layer does not already have a backing store (committed or pending). BackingStoreMap::iterator it = m_pendingSyncBackingStores.find(layer); if (it != m_pendingSyncBackingStores.end()) { if (!it->value) { // There is a pending removal, cancel it. m_pendingSyncBackingStores.remove(it); } // There is already a pending addition. return; } if (layer->backingStore()) return; // The layer already has a backing store (and no pending removal). RefPtr<CoordinatedBackingStore> backingStore(CoordinatedBackingStore::create()); backingStore->setSize(graphicsLayer->size()); ASSERT(!m_pendingSyncBackingStores.contains(layer)); m_pendingSyncBackingStores.add(layer, backingStore); }
void LayerTreeRenderer::purgeGLResources() { TextureMapperLayer* layer = toTextureMapperLayer(rootLayer()); if (layer) layer->clearBackingStoresRecursive(); m_imageBackings.clear(); #if USE(GRAPHICS_SURFACE) m_surfaceBackingStores.clear(); #endif m_rootLayer.clear(); m_rootLayerID = InvalidCoordinatedLayerID; m_layers.clear(); m_fixedLayers.clear(); m_textureMapper.clear(); m_pendingSyncBackingStores.clear(); m_backingStoresWithPendingBuffers.clear(); setActive(false); dispatchOnMainThread(bind(&LayerTreeRenderer::purgeBackingStores, this)); }
void WebLayerTreeRenderer::paintToCurrentGLContext(const TransformationMatrix& matrix, float opacity, const FloatRect& clipRect, TextureMapper::PaintFlags PaintFlags) { if (!m_textureMapper) m_textureMapper = TextureMapper::create(TextureMapper::OpenGLMode); ASSERT(m_textureMapper->accelerationMode() == TextureMapper::OpenGLMode); // We need to compensate for the rounding error that happens due to m_visibleContentsRect being // int and not float. We do that by moving the TransformationMatrix by the delta between the // position of m_visibleContentsRect and the position it would have if it wasn't rounded. TransformationMatrix newMatrix = matrix; newMatrix.translate(m_accurateVisibleContentsPosition.x() / m_contentsScale - m_visibleContentsRect.x(), m_accurateVisibleContentsPosition.y() / m_contentsScale - m_visibleContentsRect.y()); adjustPositionForFixedLayers(); GraphicsLayer* currentRootLayer = rootLayer(); if (!currentRootLayer) return; TextureMapperLayer* layer = toTextureMapperLayer(currentRootLayer); if (!layer) return; layer->setTextureMapper(m_textureMapper.get()); m_textureMapper->beginPainting(PaintFlags); m_textureMapper->beginClip(TransformationMatrix(), clipRect); if (currentRootLayer->opacity() != opacity || currentRootLayer->transform() != newMatrix) { currentRootLayer->setOpacity(opacity); currentRootLayer->setTransform(newMatrix); currentRootLayer->syncCompositingStateForThisLayerOnly(); } layer->paint(); m_textureMapper->endClip(); m_textureMapper->endPainting(); }
void LayerTreeRenderer::purgeGLResources() { TextureMapperLayer* layer = toTextureMapperLayer(rootLayer()); if (layer) layer->clearBackingStoresRecursive(); m_directlyCompositedImages.clear(); #if USE(GRAPHICS_SURFACE) m_surfaceBackingStores.clear(); #endif m_rootLayer->removeAllChildren(); m_rootLayer.clear(); m_rootLayerID = InvalidWebLayerID; m_layers.clear(); m_fixedLayers.clear(); m_textureMapper.clear(); m_backingStoresWithPendingBuffers.clear(); setActive(false); callOnMainThread(bind(&LayerTreeRenderer::purgeBackingStores, this)); }
void CoordinatedGraphicsScene::setLayerState(CoordinatedLayerID id, const CoordinatedGraphicsLayerState& layerState) { ASSERT(m_rootLayerID != InvalidCoordinatedLayerID); TextureMapperLayer* layer = layerByID(id); if (layerState.positionChanged) layer->setPosition(layerState.pos); if (layerState.anchorPointChanged) layer->setAnchorPoint(layerState.anchorPoint); if (layerState.sizeChanged) layer->setSize(layerState.size); if (layerState.transformChanged) layer->setTransform(layerState.transform); if (layerState.childrenTransformChanged) layer->setChildrenTransform(layerState.childrenTransform); if (layerState.contentsRectChanged) layer->setContentsRect(layerState.contentsRect); if (layerState.contentsTilingChanged) { layer->setContentsTilePhase(layerState.contentsTilePhase); layer->setContentsTileSize(layerState.contentsTileSize); } if (layerState.opacityChanged) layer->setOpacity(layerState.opacity); if (layerState.solidColorChanged) layer->setSolidColor(layerState.solidColor); if (layerState.debugBorderColorChanged || layerState.debugBorderWidthChanged) layer->setDebugVisuals(layerState.showDebugBorders, layerState.debugBorderColor, layerState.debugBorderWidth, layerState.showRepaintCounter); if (layerState.replicaChanged) layer->setReplicaLayer(getLayerByIDIfExists(layerState.replica)); if (layerState.maskChanged) layer->setMaskLayer(getLayerByIDIfExists(layerState.mask)); if (layerState.imageChanged) assignImageBackingToLayer(layer, layerState.imageID); if (layerState.flagsChanged) { layer->setContentsOpaque(layerState.contentsOpaque); layer->setDrawsContent(layerState.drawsContent); layer->setContentsVisible(layerState.contentsVisible); layer->setBackfaceVisibility(layerState.backfaceVisible); // Never clip the root layer. layer->setMasksToBounds(id == m_rootLayerID ? false : layerState.masksToBounds); layer->setPreserves3D(layerState.preserves3D); bool fixedToViewportChanged = layer->fixedToViewport() != layerState.fixedToViewport; layer->setFixedToViewport(layerState.fixedToViewport); if (fixedToViewportChanged) { if (layerState.fixedToViewport) m_fixedLayers.add(id, layer); else m_fixedLayers.remove(id); } layer->setIsScrollable(layerState.isScrollable); } if (layerState.committedScrollOffsetChanged) layer->didCommitScrollOffset(layerState.committedScrollOffset); prepareContentBackingStore(layer); // Apply Operations. setLayerChildrenIfNeeded(layer, layerState); createTilesIfNeeded(layer, layerState); removeTilesIfNeeded(layer, layerState); updateTilesIfNeeded(layer, layerState); setLayerFiltersIfNeeded(layer, layerState); setLayerAnimationsIfNeeded(layer, layerState); #if USE(GRAPHICS_SURFACE) syncPlatformLayerIfNeeded(layer, layerState); #endif setLayerRepaintCountIfNeeded(layer, layerState); }
void TextureMapperLayer::computeOverlapRegions(Region& overlapRegion, Region& nonOverlapRegion, ResolveSelfOverlapMode mode) { if (!m_state.visible || !m_state.contentsVisible) return; FloatRect boundingRect; if (m_backingStore || m_state.masksToBounds || m_state.maskLayer || hasFilters()) boundingRect = layerRect(); else if (m_contentsLayer || m_state.solidColor.alpha()) boundingRect = m_state.contentsRect; #if ENABLE(CSS_FILTERS) if (m_currentFilters.hasOutsets()) { FilterOutsets outsets = m_currentFilters.outsets(); IntRect unfilteredTargetRect(boundingRect); boundingRect.move(std::max(0, -outsets.left()), std::max(0, -outsets.top())); boundingRect.expand(outsets.left() + outsets.right(), outsets.top() + outsets.bottom()); boundingRect.unite(unfilteredTargetRect); } #endif TransformationMatrix replicaMatrix; if (m_state.replicaLayer) { replicaMatrix = replicaTransform(); boundingRect.unite(replicaMatrix.mapRect(boundingRect)); } boundingRect = m_currentTransform.combined().mapRect(boundingRect); // Count all masks and filters as overlap layers. if (hasFilters() || m_state.maskLayer || (m_state.replicaLayer && m_state.replicaLayer->m_state.maskLayer)) { Region newOverlapRegion(enclosingIntRect(boundingRect)); nonOverlapRegion.subtract(newOverlapRegion); overlapRegion.unite(newOverlapRegion); return; } Region newOverlapRegion; Region newNonOverlapRegion(enclosingIntRect(boundingRect)); if (!m_state.masksToBounds) { for (size_t i = 0; i < m_children.size(); ++i) { TextureMapperLayer* child = m_children[i]; child->computeOverlapRegions(newOverlapRegion, newNonOverlapRegion, ResolveSelfOverlapIfNeeded); } } if (m_state.replicaLayer) { newOverlapRegion.unite(replicaMatrix.mapRect(newOverlapRegion.bounds())); Region replicaRegion(replicaMatrix.mapRect(newNonOverlapRegion.bounds())); resolveOverlaps(replicaRegion, newOverlapRegion, newNonOverlapRegion); } if ((mode != ResolveSelfOverlapAlways) && shouldBlend()) { newNonOverlapRegion.unite(newOverlapRegion); newOverlapRegion = Region(); } overlapRegion.unite(newOverlapRegion); resolveOverlaps(newNonOverlapRegion, overlapRegion, nonOverlapRegion); }