already_AddRefed<gfxPattern> BasicImageLayer::GetAndPaintCurrentImage(gfxContext* aContext, float aOpacity, Layer* aMaskLayer) { if (!mContainer) return nullptr; mContainer->SetImageFactory(mManager->IsCompositingCheap() ? nullptr : BasicManager()->GetImageFactory()); nsRefPtr<gfxASurface> surface; AutoLockImage autoLock(mContainer, getter_AddRefs(surface)); Image *image = autoLock.GetImage(); gfx::IntSize size = mSize = autoLock.GetSize(); if (!surface || surface->CairoStatus()) { return nullptr; } nsRefPtr<gfxPattern> pat = new gfxPattern(surface); if (!pat) { return nullptr; } pat->SetFilter(mFilter); // The visible region can extend outside the image, so just draw // within the image bounds. if (aContext) { gfxContext::GraphicsOperator mixBlendMode = GetEffectiveMixBlendMode(); AutoSetOperator setOptimizedOperator(aContext, mixBlendMode != gfxContext::OPERATOR_OVER ? mixBlendMode : GetOperator()); PaintContext(pat, nsIntRegion(nsIntRect(0, 0, size.width, size.height)), aOpacity, aContext, aMaskLayer); GetContainer()->NotifyPaintedImage(image); } return pat.forget(); }
bool AutoLockShmemClient::Update(Image* aImage, uint32_t aContentFlags, gfxPattern* pat) { nsRefPtr<gfxASurface> surface = pat->GetSurface(); if (!aImage) { return false; } nsRefPtr<gfxPattern> pattern = pat ? pat : new gfxPattern(surface); gfxIntSize size = aImage->GetSize(); gfxASurface::gfxContentType contentType = gfxASurface::CONTENT_COLOR_ALPHA; bool isOpaque = (aContentFlags & Layer::CONTENT_OPAQUE); if (surface) { contentType = surface->GetContentType(); } if (contentType != gfxASurface::CONTENT_ALPHA && isOpaque) { contentType = gfxASurface::CONTENT_COLOR; } mTextureClient->EnsureAllocated(gfx::IntSize(size.width, size.height), contentType); OpenMode mode = mTextureClient->GetAccessMode() == TextureClient::ACCESS_READ_WRITE ? OPEN_READ_WRITE : OPEN_READ_ONLY; nsRefPtr<gfxASurface> tmpASurface = ShadowLayerForwarder::OpenDescriptor(mode, *mTextureClient->LockSurfaceDescriptor()); if (!tmpASurface) { return false; } nsRefPtr<gfxContext> tmpCtx = new gfxContext(tmpASurface.get()); tmpCtx->SetOperator(gfxContext::OPERATOR_SOURCE); PaintContext(pat, nsIntRegion(nsIntRect(0, 0, size.width, size.height)), 1.0, tmpCtx, nullptr); return true; }