void BasicImageLayer::Paint(DrawTarget* aDT, const gfx::Point& aDeviceOffset, Layer* aMaskLayer) { if (IsHidden() || !mContainer) { return; } RefPtr<ImageFactory> originalIF = mContainer->GetImageFactory(); mContainer->SetImageFactory(mManager->IsCompositingCheap() ? nullptr : BasicManager()->GetImageFactory()); AutoLockImage autoLock(mContainer); Image *image = autoLock.GetImage(BasicManager()->GetCompositionTime()); if (!image) { mContainer->SetImageFactory(originalIF); return; } RefPtr<gfx::SourceSurface> surface = image->GetAsSourceSurface(); if (!surface || !surface->IsValid()) { mContainer->SetImageFactory(originalIF); return; } gfx::IntSize size = mSize = surface->GetSize(); FillRectWithMask(aDT, aDeviceOffset, Rect(0, 0, size.width, size.height), surface, mSamplingFilter, DrawOptions(GetEffectiveOpacity(), GetEffectiveOperator(this)), aMaskLayer); mContainer->SetImageFactory(originalIF); }
virtual void Paint(DrawTarget* aDT, const gfx::Point& aDeviceOffset, Layer* aMaskLayer) override { if (IsHidden()) { return; } Rect snapped(mBounds.X(), mBounds.Y(), mBounds.Width(), mBounds.Height()); MaybeSnapToDevicePixels(snapped, *aDT, true); // Clip drawing in case we're using (unbounded) operator source. aDT->PushClipRect(snapped); FillRectWithMask( aDT, aDeviceOffset, snapped, mColor, DrawOptions(GetEffectiveOpacity(), GetEffectiveOperator(this)), aMaskLayer); aDT->PopClip(); }
void BasicCanvasLayer::Paint(DrawTarget* aDT, const Point& aDeviceOffset, Layer* aMaskLayer) { if (IsHidden()) return; if (IsDirty()) { Painted(); FirePreTransactionCallback(); UpdateTarget(); FireDidTransactionCallback(); } if (!mSurface) { return; } const bool needsYFlip = (mOriginPos == gl::OriginPos::BottomLeft); Matrix oldTM; if (needsYFlip) { oldTM = aDT->GetTransform(); aDT->SetTransform(Matrix(oldTM). PreTranslate(0.0f, mBounds.height). PreScale(1.0f, -1.0f)); } FillRectWithMask(aDT, aDeviceOffset, Rect(0, 0, mBounds.width, mBounds.height), mSurface, ToFilter(mFilter), DrawOptions(GetEffectiveOpacity(), GetEffectiveOperator(this)), aMaskLayer); if (needsYFlip) { aDT->SetTransform(oldTM); } }
void BasicThebesLayer::PaintThebes(gfxContext* aContext, Layer* aMaskLayer, LayerManager::DrawThebesLayerCallback aCallback, void* aCallbackData, ReadbackProcessor* aReadback) { PROFILER_LABEL("BasicThebesLayer", "PaintThebes"); NS_ASSERTION(BasicManager()->InDrawing(), "Can only draw in drawing phase"); nsTArray<ReadbackProcessor::Update> readbackUpdates; if (aReadback && UsedForReadback()) { aReadback->GetThebesLayerUpdates(this, &readbackUpdates); } float opacity = GetEffectiveOpacity(); CompositionOp effectiveOperator = GetEffectiveOperator(this); if (!BasicManager()->IsRetained()) { NS_ASSERTION(readbackUpdates.IsEmpty(), "Can't do readback for non-retained layer"); mValidRegion.SetEmpty(); mContentClient->Clear(); nsIntRegion toDraw = IntersectWithClip(GetEffectiveVisibleRegion(), aContext); RenderTraceInvalidateStart(this, "FFFF00", toDraw.GetBounds()); if (!toDraw.IsEmpty() && !IsHidden()) { if (!aCallback) { BasicManager()->SetTransactionIncomplete(); return; } aContext->Save(); bool needsClipToVisibleRegion = GetClipToVisibleRegion(); bool needsGroup = opacity != 1.0 || effectiveOperator != CompositionOp::OP_OVER || aMaskLayer; nsRefPtr<gfxContext> groupContext; if (needsGroup) { groupContext = BasicManager()->PushGroupForLayer(aContext, this, toDraw, &needsClipToVisibleRegion); if (effectiveOperator != CompositionOp::OP_OVER) { needsClipToVisibleRegion = true; } } else { groupContext = aContext; } SetAntialiasingFlags(this, groupContext); aCallback(this, groupContext, toDraw, DrawRegionClip::CLIP_NONE, nsIntRegion(), aCallbackData); if (needsGroup) { BasicManager()->PopGroupToSourceWithCachedSurface(aContext, groupContext); if (needsClipToVisibleRegion) { gfxUtils::ClipToRegion(aContext, toDraw); } AutoSetOperator setOptimizedOperator(aContext, ThebesOp(effectiveOperator)); PaintWithMask(aContext, opacity, aMaskLayer); } aContext->Restore(); } RenderTraceInvalidateEnd(this, "FFFF00"); return; } if (BasicManager()->IsTransactionIncomplete()) return; gfxRect clipExtents; clipExtents = aContext->GetClipExtents(); // Pull out the mask surface and transform here, because the mask // is internal to basic layers AutoMoz2DMaskData mask; SourceSurface* maskSurface = nullptr; Matrix maskTransform; if (GetMaskData(aMaskLayer, &mask)) { maskSurface = mask.GetSurface(); maskTransform = mask.GetTransform(); } if (!IsHidden() && !clipExtents.IsEmpty()) { mContentClient->DrawTo(this, aContext->GetDrawTarget(), opacity, GetOperator(), maskSurface, &maskTransform); } for (uint32_t i = 0; i < readbackUpdates.Length(); ++i) { ReadbackProcessor::Update& update = readbackUpdates[i]; nsIntPoint offset = update.mLayer->GetBackgroundLayerOffset(); nsRefPtr<gfxContext> ctx = update.mLayer->GetSink()->BeginUpdate(update.mUpdateRect + offset, update.mSequenceCounter); if (ctx) { NS_ASSERTION(opacity == 1.0, "Should only read back opaque layers"); ctx->Translate(gfxPoint(offset.x, offset.y)); mContentClient->DrawTo(this, ctx->GetDrawTarget(), 1.0, CompositionOpForOp(ctx->CurrentOperator()), maskSurface, &maskTransform); update.mLayer->GetSink()->EndUpdate(ctx, update.mUpdateRect + offset); } } }