Bug 852754 - Part 3: Share the implementation of ConfigureLayer. r=mstange

This commit is contained in:
Matt Woodrow 2016-04-07 18:54:33 +12:00
Родитель 7dc61d9b46
Коммит 3fcbb65a38
6 изменённых файлов: 52 добавлений и 158 удалений

Просмотреть файл

@ -2740,55 +2740,6 @@ nsDisplayBackgroundImage::BuildLayer(nsDisplayListBuilder* aBuilder,
return layer.forget();
}
void
nsDisplayBackgroundImage::ConfigureLayer(ImageLayer* aLayer,
const ContainerLayerParameters& aParameters)
{
aLayer->SetFilter(nsLayoutUtils::GetGraphicsFilterForFrame(mFrame));
MOZ_ASSERT(mImage);
int32_t imageWidth;
int32_t imageHeight;
mImage->GetWidth(&imageWidth);
mImage->GetHeight(&imageHeight);
NS_ASSERTION(imageWidth != 0 && imageHeight != 0, "Invalid image size!");
if (imageWidth > 0 && imageHeight > 0) {
// We're actually using the ImageContainer. Let our frame know that it
// should consider itself to have painted successfully.
nsDisplayBackgroundGeometry::UpdateDrawResult(this,
image::DrawResult::SUCCESS);
}
// XXX(seth): Right now we ignore aParameters.Scale() and
// aParameters.Offset(), because FrameLayerBuilder already applies
// aParameters.Scale() via the layer's post-transform, and
// aParameters.Offset() is always zero.
MOZ_ASSERT(aParameters.Offset() == LayerIntPoint(0,0));
// It's possible (for example, due to downscale-during-decode) that the
// ImageContainer this ImageLayer is holding has a different size from the
// intrinsic size of the image. For this reason we compute the transform using
// the ImageContainer's size rather than the image's intrinsic size.
// XXX(seth): In reality, since the size of the ImageContainer may change
// asynchronously, this is not enough. Bug 1183378 will provide a more
// complete fix, but this solution is safe in more cases than simply relying
// on the intrinsic size.
IntSize containerSize = aLayer->GetContainer()
? aLayer->GetContainer()->GetCurrentSize()
: IntSize(imageWidth, imageHeight);
const int32_t factor = mFrame->PresContext()->AppUnitsPerDevPixel();
const LayoutDeviceRect destRect =
LayoutDeviceRect::FromAppUnits(GetDestRect(), factor);
const LayoutDevicePoint p = destRect.TopLeft();
Matrix transform = Matrix::Translation(p.x, p.y);
transform.PreScale(destRect.width / containerSize.width,
destRect.height / containerSize.height);
aLayer->SetBaseTransform(gfx::Matrix4x4::From2D(transform));
}
void
nsDisplayBackgroundImage::HitTest(nsDisplayListBuilder* aBuilder,
const nsRect& aRect,
@ -3208,6 +3159,56 @@ nsDisplayThemedBackground::GetBoundsInternal() {
return r + ToReferenceFrame();
}
void
nsDisplayImageContainer::ConfigureLayer(ImageLayer* aLayer,
const ContainerLayerParameters& aParameters)
{
aLayer->SetFilter(nsLayoutUtils::GetGraphicsFilterForFrame(mFrame));
nsCOMPtr<imgIContainer> image = GetImage();
MOZ_ASSERT(image);
int32_t imageWidth;
int32_t imageHeight;
image->GetWidth(&imageWidth);
image->GetHeight(&imageHeight);
NS_ASSERTION(imageWidth != 0 && imageHeight != 0, "Invalid image size!");
if (imageWidth > 0 && imageHeight > 0) {
// We're actually using the ImageContainer. Let our frame know that it
// should consider itself to have painted successfully.
nsDisplayBackgroundGeometry::UpdateDrawResult(this,
image::DrawResult::SUCCESS);
}
// XXX(seth): Right now we ignore aParameters.Scale() and
// aParameters.Offset(), because FrameLayerBuilder already applies
// aParameters.Scale() via the layer's post-transform, and
// aParameters.Offset() is always zero.
MOZ_ASSERT(aParameters.Offset() == LayerIntPoint(0,0));
// It's possible (for example, due to downscale-during-decode) that the
// ImageContainer this ImageLayer is holding has a different size from the
// intrinsic size of the image. For this reason we compute the transform using
// the ImageContainer's size rather than the image's intrinsic size.
// XXX(seth): In reality, since the size of the ImageContainer may change
// asynchronously, this is not enough. Bug 1183378 will provide a more
// complete fix, but this solution is safe in more cases than simply relying
// on the intrinsic size.
IntSize containerSize = aLayer->GetContainer()
? aLayer->GetContainer()->GetCurrentSize()
: IntSize(imageWidth, imageHeight);
const int32_t factor = mFrame->PresContext()->AppUnitsPerDevPixel();
const LayoutDeviceRect destRect =
LayoutDeviceRect::FromAppUnits(GetDestRect(), factor);
const LayoutDevicePoint p = destRect.TopLeft();
Matrix transform = Matrix::Translation(p.x, p.y);
transform.PreScale(destRect.width / containerSize.width,
destRect.height / containerSize.height);
aLayer->SetBaseTransform(gfx::Matrix4x4::From2D(transform));
}
already_AddRefed<ImageContainer>
nsDisplayImageContainer::GetContainer(LayerManager* aManager,
nsDisplayListBuilder *aBuilder)

Просмотреть файл

@ -2327,8 +2327,8 @@ public:
already_AddRefed<ImageContainer> GetContainer(LayerManager* aManager,
nsDisplayListBuilder* aBuilder);
virtual void ConfigureLayer(ImageLayer* aLayer,
const ContainerLayerParameters& aParameters) = 0;
void ConfigureLayer(ImageLayer* aLayer,
const ContainerLayerParameters& aParameters);
virtual already_AddRefed<imgIContainer> GetImage() = 0;
@ -2724,8 +2724,6 @@ public:
nsDisplayListBuilder* aBuilder) override;
virtual already_AddRefed<imgIContainer> GetImage() override;
virtual nsRect GetDestRect() override;
virtual void ConfigureLayer(ImageLayer* aLayer,
const ContainerLayerParameters& aParameters) override;
static nsRegion GetInsideClipRegion(nsDisplayItem* aItem, uint8_t aClip,
const nsRect& aRect);

Просмотреть файл

@ -1636,54 +1636,6 @@ nsDisplayImage::BuildLayer(nsDisplayListBuilder* aBuilder,
return layer.forget();
}
void
nsDisplayImage::ConfigureLayer(ImageLayer* aLayer,
const ContainerLayerParameters& aParameters)
{
aLayer->SetFilter(nsLayoutUtils::GetGraphicsFilterForFrame(mFrame));
int32_t imageWidth;
int32_t imageHeight;
mImage->GetWidth(&imageWidth);
mImage->GetHeight(&imageHeight);
NS_ASSERTION(imageWidth != 0 && imageHeight != 0, "Invalid image size!");
if (imageWidth > 0 && imageHeight > 0) {
// We're actually using the ImageContainer. Let our frame know that it
// should consider itself to have painted successfully.
nsDisplayItemGenericImageGeometry::UpdateDrawResult(this,
DrawResult::SUCCESS);
}
const int32_t factor = mFrame->PresContext()->AppUnitsPerDevPixel();
const LayoutDeviceRect destRect =
LayoutDeviceRect::FromAppUnits(GetDestRect(), factor);
// XXX(seth): Right now we ignore aParameters.Scale() and
// aParameters.Offset(), because FrameLayerBuilder already applies
// aParameters.Scale() via the layer's post-transform, and
// aParameters.Offset() is always zero.
MOZ_ASSERT(aParameters.Offset() == LayerIntPoint(0,0));
// It's possible (for example, due to downscale-during-decode) that the
// ImageContainer this ImageLayer is holding has a different size from the
// intrinsic size of the image. For this reason we compute the transform using
// the ImageContainer's size rather than the image's intrinsic size.
// XXX(seth): In reality, since the size of the ImageContainer may change
// asynchronously, this is not enough. Bug 1183378 will provide a more
// complete fix, but this solution is safe in more cases than simply relying
// on the intrinsic size.
IntSize containerSize = aLayer->GetContainer()
? aLayer->GetContainer()->GetCurrentSize()
: IntSize(imageWidth, imageHeight);
const LayoutDevicePoint p = destRect.TopLeft();
Matrix transform = Matrix::Translation(p.x, p.y);
transform.PreScale(destRect.Width() / containerSize.width,
destRect.Height() / containerSize.height);
aLayer->SetBaseTransform(gfx::Matrix4x4::From2D(transform));
}
DrawResult
nsImageFrame::PaintImage(nsRenderingContext& aRenderingContext, nsPoint aPt,
const nsRect& aDirtyRect, imgIContainer* aImage,

Просмотреть файл

@ -460,13 +460,6 @@ public:
LayerManager* aManager,
const ContainerLayerParameters& aContainerParameters) override;
/**
* Configure an ImageLayer for this display item.
* Set the required filter and scaling transform.
*/
virtual void ConfigureLayer(ImageLayer* aLayer,
const ContainerLayerParameters& aParameters) override;
NS_DISPLAY_DECL_NAME("Image", TYPE_IMAGE)
private:
nsCOMPtr<imgIContainer> mImage;

Просмотреть файл

@ -444,54 +444,6 @@ nsDisplayXULImage::ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
nsDisplayImageContainer::ComputeInvalidationRegion(aBuilder, aGeometry, aInvalidRegion);
}
void
nsDisplayXULImage::ConfigureLayer(ImageLayer* aLayer,
const ContainerLayerParameters& aParameters)
{
aLayer->SetFilter(nsLayoutUtils::GetGraphicsFilterForFrame(mFrame));
const int32_t factor = mFrame->PresContext()->AppUnitsPerDevPixel();
LayoutDeviceRect destRect = LayoutDeviceRect::FromAppUnits(GetDestRect(), factor);
nsCOMPtr<imgIContainer> imgCon = GetImage();
int32_t imageWidth;
int32_t imageHeight;
imgCon->GetWidth(&imageWidth);
imgCon->GetHeight(&imageHeight);
NS_ASSERTION(imageWidth != 0 && imageHeight != 0, "Invalid image size!");
if (imageWidth > 0 && imageHeight > 0) {
// We're actually using the ImageContainer. Let our frame know that it
// should consider itself to have painted successfully.
nsDisplayItemGenericImageGeometry::UpdateDrawResult(this,
DrawResult::SUCCESS);
}
// XXX(seth): Right now we ignore aParameters.Scale() and
// aParameters.Offset(), because FrameLayerBuilder already applies
// aParameters.Scale() via the layer's post-transform, and
// aParameters.Offset() is always zero.
MOZ_ASSERT(aParameters.Offset() == LayerIntPoint(0,0));
// It's possible (for example, due to downscale-during-decode) that the
// ImageContainer this ImageLayer is holding has a different size from the
// intrinsic size of the image. For this reason we compute the transform using
// the ImageContainer's size rather than the image's intrinsic size.
// XXX(seth): In reality, since the size of the ImageContainer may change
// asynchronously, this is not enough. Bug 1183378 will provide a more
// complete fix, but this solution is safe in more cases than simply relying
// on the intrinsic size.
IntSize containerSize = aLayer->GetContainer()
? aLayer->GetContainer()->GetCurrentSize()
: IntSize(imageWidth, imageHeight);
const LayoutDevicePoint p = destRect.TopLeft();
Matrix transform = Matrix::Translation(p.x, p.y);
transform.PreScale(destRect.Width() / containerSize.width,
destRect.Height() / containerSize.height);
aLayer->SetBaseTransform(gfx::Matrix4x4::From2D(transform));
}
bool
nsDisplayXULImage::CanOptimizeToImageLayer(LayerManager* aManager,
nsDisplayListBuilder* aBuilder)

Просмотреть файл

@ -144,8 +144,6 @@ public:
nsDisplayListBuilder* aBuilder) override;
virtual already_AddRefed<imgIContainer> GetImage() override;
virtual nsRect GetDestRect() override;
virtual void ConfigureLayer(ImageLayer* aLayer,
const ContainerLayerParameters& aParameters) override;
virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) override
{
*aSnap = true;