mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 15:52:07 +00:00
Bug 1150774 (Part 2) - Use the correct units in nsDisplayImageContainer::ConfigureLayer and related code. r=botond
This commit is contained in:
parent
d1dffb1a14
commit
ea22de2fd8
@ -2836,7 +2836,7 @@ void ContainerState::FinishPaintedLayerData(PaintedLayerData& aData, FindOpaqueB
|
||||
if (imageContainer) {
|
||||
nsRefPtr<ImageLayer> imageLayer = CreateOrRecycleImageLayer(data->mLayer);
|
||||
imageLayer->SetContainer(imageContainer);
|
||||
data->mImage->ConfigureLayer(imageLayer, mParameters.mOffset);
|
||||
data->mImage->ConfigureLayer(imageLayer, mParameters);
|
||||
imageLayer->SetPostScale(mParameters.mXScale,
|
||||
mParameters.mYScale);
|
||||
if (data->mItemClip.HasClip()) {
|
||||
|
@ -2510,7 +2510,8 @@ nsDisplayBackgroundImage::TryOptimizeToImageLayer(LayerManager* aManager,
|
||||
// layer pixel boundaries. This should be OK for now.
|
||||
|
||||
int32_t appUnitsPerDevPixel = presContext->AppUnitsPerDevPixel();
|
||||
mDestRect = nsLayoutUtils::RectToGfxRect(state.mDestArea, appUnitsPerDevPixel);
|
||||
mDestRect =
|
||||
LayoutDeviceRect::FromAppUnits(state.mDestArea, appUnitsPerDevPixel);
|
||||
mImageContainer = imageContainer;
|
||||
|
||||
// Ok, we can turn this into a layer if needed.
|
||||
@ -2566,13 +2567,11 @@ nsDisplayBackgroundImage::GetLayerState(nsDisplayListBuilder* aBuilder,
|
||||
mozilla::gfx::IntSize imageSize = mImageContainer->GetCurrentSize();
|
||||
NS_ASSERTION(imageSize.width != 0 && imageSize.height != 0, "Invalid image size!");
|
||||
|
||||
gfxRect destRect = mDestRect;
|
||||
|
||||
destRect.width *= aParameters.mXScale;
|
||||
destRect.height *= aParameters.mYScale;
|
||||
const LayerRect destLayerRect = mDestRect * aParameters.Scale();
|
||||
|
||||
// Calculate the scaling factor for the frame.
|
||||
gfxSize scale = gfxSize(destRect.width / imageSize.width, destRect.height / imageSize.height);
|
||||
const gfxSize scale = gfxSize(destLayerRect.width / imageSize.width,
|
||||
destLayerRect.height / imageSize.height);
|
||||
|
||||
// If we are not scaling at all, no point in separating this into a layer.
|
||||
if (scale.width == 1.0f && scale.height == 1.0f) {
|
||||
@ -2580,7 +2579,7 @@ nsDisplayBackgroundImage::GetLayerState(nsDisplayListBuilder* aBuilder,
|
||||
}
|
||||
|
||||
// If the target size is pretty small, no point in using a layer.
|
||||
if (destRect.width * destRect.height < 64 * 64) {
|
||||
if (destLayerRect.width * destLayerRect.height < 64 * 64) {
|
||||
return LAYER_NONE;
|
||||
}
|
||||
}
|
||||
@ -2601,12 +2600,13 @@ nsDisplayBackgroundImage::BuildLayer(nsDisplayListBuilder* aBuilder,
|
||||
return nullptr;
|
||||
}
|
||||
layer->SetContainer(mImageContainer);
|
||||
ConfigureLayer(layer, aParameters.mOffset);
|
||||
ConfigureLayer(layer, aParameters);
|
||||
return layer.forget();
|
||||
}
|
||||
|
||||
void
|
||||
nsDisplayBackgroundImage::ConfigureLayer(ImageLayer* aLayer, const nsIntPoint& aOffset)
|
||||
nsDisplayBackgroundImage::ConfigureLayer(ImageLayer* aLayer,
|
||||
const ContainerLayerParameters& aParameters)
|
||||
{
|
||||
aLayer->SetFilter(nsLayoutUtils::GetGraphicsFilterForFrame(mFrame));
|
||||
|
||||
@ -2618,7 +2618,13 @@ nsDisplayBackgroundImage::ConfigureLayer(ImageLayer* aLayer, const nsIntPoint& a
|
||||
nsDisplayBackgroundGeometry::UpdateDrawResult(this, DrawResult::SUCCESS);
|
||||
}
|
||||
|
||||
gfxPoint p = mDestRect.TopLeft() + aOffset;
|
||||
// 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));
|
||||
|
||||
const LayoutDevicePoint p = mDestRect.TopLeft();
|
||||
Matrix transform = Matrix::Translation(p.x, p.y);
|
||||
transform.PreScale(mDestRect.width / imageSize.width,
|
||||
mDestRect.height / imageSize.height);
|
||||
|
@ -1962,6 +1962,8 @@ private:
|
||||
|
||||
class nsDisplayImageContainer : public nsDisplayItem {
|
||||
public:
|
||||
typedef mozilla::LayerIntPoint LayerIntPoint;
|
||||
typedef mozilla::LayoutDeviceRect LayoutDeviceRect;
|
||||
typedef mozilla::layers::ImageContainer ImageContainer;
|
||||
typedef mozilla::layers::ImageLayer ImageLayer;
|
||||
|
||||
@ -1971,7 +1973,8 @@ public:
|
||||
|
||||
virtual already_AddRefed<ImageContainer> GetContainer(LayerManager* aManager,
|
||||
nsDisplayListBuilder* aBuilder) = 0;
|
||||
virtual void ConfigureLayer(ImageLayer* aLayer, const nsIntPoint& aOffset) = 0;
|
||||
virtual void ConfigureLayer(ImageLayer* aLayer,
|
||||
const ContainerLayerParameters& aParameters) = 0;
|
||||
|
||||
virtual bool SupportsOptimizingToImage() override { return true; }
|
||||
};
|
||||
@ -2319,7 +2322,8 @@ public:
|
||||
|
||||
virtual already_AddRefed<ImageContainer> GetContainer(LayerManager* aManager,
|
||||
nsDisplayListBuilder *aBuilder) override;
|
||||
virtual void ConfigureLayer(ImageLayer* aLayer, const nsIntPoint& aOffset) override;
|
||||
virtual void ConfigureLayer(ImageLayer* aLayer,
|
||||
const ContainerLayerParameters& aParameters) override;
|
||||
|
||||
static nsRegion GetInsideClipRegion(nsDisplayItem* aItem, nsPresContext* aPresContext, uint8_t aClip,
|
||||
const nsRect& aRect, bool* aSnap);
|
||||
@ -2344,7 +2348,7 @@ protected:
|
||||
const nsStyleBackground* mBackgroundStyle;
|
||||
/* If this background can be a simple image layer, we store the format here. */
|
||||
nsRefPtr<ImageContainer> mImageContainer;
|
||||
gfxRect mDestRect;
|
||||
LayoutDeviceRect mDestRect;
|
||||
/* Bounds of this display item */
|
||||
nsRect mBounds;
|
||||
uint32_t mLayer;
|
||||
|
@ -1436,17 +1436,15 @@ nsDisplayImage::GetContainer(LayerManager* aManager,
|
||||
return mImage->GetImageContainer(aManager, flags);
|
||||
}
|
||||
|
||||
gfxRect
|
||||
nsRect
|
||||
nsDisplayImage::GetDestRect()
|
||||
{
|
||||
int32_t factor = mFrame->PresContext()->AppUnitsPerDevPixel();
|
||||
|
||||
// XXX(seth): This method will do something more interesting once the patch in
|
||||
// bug 1150704 lands.
|
||||
bool snap;
|
||||
nsRect dest = GetBounds(&snap);
|
||||
gfxRect destRect(dest.x, dest.y, dest.width, dest.height);
|
||||
destRect.ScaleInverse(factor);
|
||||
|
||||
return destRect;
|
||||
return dest;
|
||||
}
|
||||
|
||||
LayerState
|
||||
@ -1473,14 +1471,14 @@ nsDisplayImage::GetLayerState(nsDisplayListBuilder* aBuilder,
|
||||
|
||||
NS_ASSERTION(imageWidth != 0 && imageHeight != 0, "Invalid image size!");
|
||||
|
||||
gfxRect destRect = GetDestRect();
|
||||
|
||||
destRect.width *= aParameters.mXScale;
|
||||
destRect.height *= aParameters.mYScale;
|
||||
const int32_t factor = mFrame->PresContext()->AppUnitsPerDevPixel();
|
||||
const LayoutDeviceRect destRect =
|
||||
LayoutDeviceRect::FromAppUnits(GetDestRect(), factor);
|
||||
const LayerRect destLayerRect = destRect * aParameters.Scale();
|
||||
|
||||
// Calculate the scaling factor for the frame.
|
||||
gfxSize scale = gfxSize(destRect.width / imageWidth,
|
||||
destRect.height / imageHeight);
|
||||
const gfxSize scale = gfxSize(destLayerRect.width / imageWidth,
|
||||
destLayerRect.height / imageHeight);
|
||||
|
||||
// If we are not scaling at all, no point in separating this into a layer.
|
||||
if (scale.width == 1.0f && scale.height == 1.0f) {
|
||||
@ -1488,7 +1486,7 @@ nsDisplayImage::GetLayerState(nsDisplayListBuilder* aBuilder,
|
||||
}
|
||||
|
||||
// If the target size is pretty small, no point in using a layer.
|
||||
if (destRect.width * destRect.height < 64 * 64) {
|
||||
if (destLayerRect.width * destLayerRect.height < 64 * 64) {
|
||||
return LAYER_NONE;
|
||||
}
|
||||
}
|
||||
@ -1560,12 +1558,13 @@ nsDisplayImage::BuildLayer(nsDisplayListBuilder* aBuilder,
|
||||
return nullptr;
|
||||
}
|
||||
layer->SetContainer(container);
|
||||
ConfigureLayer(layer, aParameters.mOffset);
|
||||
ConfigureLayer(layer, aParameters);
|
||||
return layer.forget();
|
||||
}
|
||||
|
||||
void
|
||||
nsDisplayImage::ConfigureLayer(ImageLayer *aLayer, const nsIntPoint& aOffset)
|
||||
nsDisplayImage::ConfigureLayer(ImageLayer* aLayer,
|
||||
const ContainerLayerParameters& aParameters)
|
||||
{
|
||||
aLayer->SetFilter(nsLayoutUtils::GetGraphicsFilterForFrame(mFrame));
|
||||
|
||||
@ -1582,9 +1581,17 @@ nsDisplayImage::ConfigureLayer(ImageLayer *aLayer, const nsIntPoint& aOffset)
|
||||
DrawResult::SUCCESS);
|
||||
}
|
||||
|
||||
const gfxRect destRect = GetDestRect();
|
||||
const int32_t factor = mFrame->PresContext()->AppUnitsPerDevPixel();
|
||||
const LayoutDeviceRect destRect =
|
||||
LayoutDeviceRect::FromAppUnits(GetDestRect(), factor);
|
||||
|
||||
gfxPoint p = destRect.TopLeft() + aOffset;
|
||||
// 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));
|
||||
|
||||
const LayoutDevicePoint p = destRect.TopLeft();
|
||||
Matrix transform = Matrix::Translation(p.x, p.y);
|
||||
transform.PreScale(destRect.Width() / imageWidth,
|
||||
destRect.Height() / imageHeight);
|
||||
|
@ -401,7 +401,7 @@ public:
|
||||
virtual already_AddRefed<ImageContainer> GetContainer(LayerManager* aManager,
|
||||
nsDisplayListBuilder* aBuilder) override;
|
||||
|
||||
gfxRect GetDestRect();
|
||||
nsRect GetDestRect();
|
||||
|
||||
virtual LayerState GetLayerState(nsDisplayListBuilder* aBuilder,
|
||||
LayerManager* aManager,
|
||||
@ -431,7 +431,8 @@ public:
|
||||
* Configure an ImageLayer for this display item.
|
||||
* Set the required filter and scaling transform.
|
||||
*/
|
||||
virtual void ConfigureLayer(ImageLayer* aLayer, const nsIntPoint& aOffset) override;
|
||||
virtual void ConfigureLayer(ImageLayer* aLayer,
|
||||
const ContainerLayerParameters& aParameters) override;
|
||||
|
||||
NS_DISPLAY_DECL_NAME("Image", TYPE_IMAGE)
|
||||
private:
|
||||
|
@ -395,18 +395,19 @@ nsDisplayXULImage::ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
|
||||
}
|
||||
|
||||
void
|
||||
nsDisplayXULImage::ConfigureLayer(ImageLayer* aLayer, const nsIntPoint& aOffset)
|
||||
nsDisplayXULImage::ConfigureLayer(ImageLayer* aLayer,
|
||||
const ContainerLayerParameters& aParameters)
|
||||
{
|
||||
aLayer->SetFilter(nsLayoutUtils::GetGraphicsFilterForFrame(mFrame));
|
||||
|
||||
int32_t factor = mFrame->PresContext()->AppUnitsPerDevPixel();
|
||||
nsImageBoxFrame* imageFrame = static_cast<nsImageBoxFrame*>(mFrame);
|
||||
|
||||
nsRect dest;
|
||||
imageFrame->GetClientRect(dest);
|
||||
dest += ToReferenceFrame();
|
||||
gfxRect destRect(dest.x, dest.y, dest.width, dest.height);
|
||||
destRect.ScaleInverse(factor);
|
||||
nsRect clientRect;
|
||||
imageFrame->GetClientRect(clientRect);
|
||||
|
||||
const int32_t factor = mFrame->PresContext()->AppUnitsPerDevPixel();
|
||||
const LayoutDeviceRect destRect =
|
||||
LayoutDeviceRect::FromAppUnits(clientRect + ToReferenceFrame(), factor);
|
||||
|
||||
nsCOMPtr<imgIContainer> imgCon;
|
||||
imageFrame->mImageRequest->GetImage(getter_AddRefs(imgCon));
|
||||
@ -423,7 +424,13 @@ nsDisplayXULImage::ConfigureLayer(ImageLayer* aLayer, const nsIntPoint& aOffset)
|
||||
DrawResult::SUCCESS);
|
||||
}
|
||||
|
||||
gfxPoint p = destRect.TopLeft() + aOffset;
|
||||
// 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));
|
||||
|
||||
const LayoutDevicePoint p = destRect.TopLeft();
|
||||
Matrix transform = Matrix::Translation(p.x, p.y);
|
||||
transform.PreScale(destRect.Width() / imageWidth,
|
||||
destRect.Height() / imageHeight);
|
||||
|
@ -144,7 +144,8 @@ public:
|
||||
|
||||
virtual already_AddRefed<ImageContainer> GetContainer(LayerManager* aManager,
|
||||
nsDisplayListBuilder* aBuilder) override;
|
||||
virtual void ConfigureLayer(ImageLayer* aLayer, const nsIntPoint& aOffset) override;
|
||||
virtual void ConfigureLayer(ImageLayer* aLayer,
|
||||
const ContainerLayerParameters& aParameters) override;
|
||||
virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) override
|
||||
{
|
||||
*aSnap = true;
|
||||
|
Loading…
Reference in New Issue
Block a user