2012-02-01 02:18:30 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 11:12:37 +00:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2012-02-01 02:18:30 +00:00
|
|
|
|
|
|
|
#include "ImageLayers.h"
|
2013-08-11 23:17:23 +00:00
|
|
|
#include "ImageContainer.h" // for ImageContainer
|
|
|
|
#include "gfxRect.h" // for gfxRect
|
|
|
|
#include "nsDebug.h" // for NS_ASSERTION
|
|
|
|
#include "nsISupportsImpl.h" // for ImageContainer::Release, etc
|
2013-12-13 17:32:02 +00:00
|
|
|
#include "gfx2DGlue.h"
|
2012-02-01 02:18:30 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2012-08-19 19:33:25 +00:00
|
|
|
ImageLayer::ImageLayer(LayerManager* aManager, void* aImplData)
|
2013-10-01 21:01:19 +00:00
|
|
|
: Layer(aManager, aImplData), mFilter(GraphicsFilter::FILTER_GOOD)
|
2014-01-23 18:26:41 +00:00
|
|
|
, mScaleMode(ScaleMode::SCALE_NONE), mDisallowBigImage(false)
|
2012-08-19 19:33:25 +00:00
|
|
|
{}
|
2012-02-16 03:26:19 +00:00
|
|
|
|
2012-08-19 19:33:25 +00:00
|
|
|
ImageLayer::~ImageLayer()
|
|
|
|
{}
|
2012-02-16 03:26:19 +00:00
|
|
|
|
2012-08-19 19:33:25 +00:00
|
|
|
void ImageLayer::SetContainer(ImageContainer* aContainer)
|
2012-02-01 02:18:30 +00:00
|
|
|
{
|
2012-08-19 19:33:25 +00:00
|
|
|
mContainer = aContainer;
|
2012-02-01 02:18:30 +00:00
|
|
|
}
|
|
|
|
|
2014-01-27 15:28:04 +00:00
|
|
|
void ImageLayer::ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface)
|
2012-02-01 02:18:30 +00:00
|
|
|
{
|
2014-01-27 15:28:18 +00:00
|
|
|
gfx::Matrix4x4 local = GetLocalTransform();
|
2012-09-18 03:16:15 +00:00
|
|
|
|
2012-08-19 19:33:25 +00:00
|
|
|
// Snap image edges to pixel boundaries
|
2012-09-18 03:16:15 +00:00
|
|
|
gfxRect sourceRect(0, 0, 0, 0);
|
2012-08-19 19:33:25 +00:00
|
|
|
if (mContainer) {
|
2013-12-13 17:32:02 +00:00
|
|
|
sourceRect.SizeTo(gfx::ThebesIntSize(mContainer->GetCurrentSize()));
|
2012-02-01 02:18:30 +00:00
|
|
|
}
|
2012-08-19 19:33:25 +00:00
|
|
|
// Snap our local transform first, and snap the inherited transform as well.
|
|
|
|
// This makes our snapping equivalent to what would happen if our content
|
2014-09-26 17:06:08 +00:00
|
|
|
// was drawn into a PaintedLayer (gfxContext would snap using the local
|
|
|
|
// transform, then we'd snap again when compositing the PaintedLayer).
|
2014-01-27 15:27:20 +00:00
|
|
|
mEffectiveTransform =
|
2012-09-18 03:16:15 +00:00
|
|
|
SnapTransform(local, sourceRect, nullptr) *
|
2014-01-27 15:28:04 +00:00
|
|
|
SnapTransformTranslation(aTransformToSurface, nullptr);
|
2014-12-07 01:12:50 +00:00
|
|
|
|
|
|
|
if (mScaleMode != ScaleMode::SCALE_NONE &&
|
|
|
|
sourceRect.width != 0.0 && sourceRect.height != 0.0) {
|
|
|
|
NS_ASSERTION(mScaleMode == ScaleMode::STRETCH,
|
|
|
|
"No other scalemodes than stretch and none supported yet.");
|
|
|
|
local.PreScale(mScaleToSize.width / sourceRect.width,
|
|
|
|
mScaleToSize.height / sourceRect.height, 1.0);
|
|
|
|
|
|
|
|
mEffectiveTransformForBuffer =
|
|
|
|
SnapTransform(local, sourceRect, nullptr) *
|
|
|
|
SnapTransformTranslation(aTransformToSurface, nullptr);
|
|
|
|
} else {
|
|
|
|
mEffectiveTransformForBuffer = mEffectiveTransform;
|
|
|
|
}
|
|
|
|
|
2012-08-19 19:33:25 +00:00
|
|
|
ComputeEffectiveTransformForMaskLayer(aTransformToSurface);
|
2012-02-16 03:26:19 +00:00
|
|
|
}
|
2012-02-01 02:18:30 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|