2012-02-01 06:18:30 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 15:12:37 +04: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 06:18:30 +04:00
|
|
|
|
|
|
|
#include "ImageLayers.h"
|
2013-08-12 03:17:23 +04: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 21:32:02 +04:00
|
|
|
#include "gfx2DGlue.h"
|
2012-02-01 06:18:30 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2012-08-19 23:33:25 +04:00
|
|
|
ImageLayer::ImageLayer(LayerManager* aManager, void* aImplData)
|
2013-10-02 01:01:19 +04:00
|
|
|
: Layer(aManager, aImplData), mFilter(GraphicsFilter::FILTER_GOOD)
|
2014-01-23 22:26:41 +04:00
|
|
|
, mScaleMode(ScaleMode::SCALE_NONE), mDisallowBigImage(false)
|
2012-08-19 23:33:25 +04:00
|
|
|
{}
|
2012-02-16 07:26:19 +04:00
|
|
|
|
2012-08-19 23:33:25 +04:00
|
|
|
ImageLayer::~ImageLayer()
|
|
|
|
{}
|
2012-02-16 07:26:19 +04:00
|
|
|
|
2012-08-19 23:33:25 +04:00
|
|
|
void ImageLayer::SetContainer(ImageContainer* aContainer)
|
2012-02-01 06:18:30 +04:00
|
|
|
{
|
2012-08-19 23:33:25 +04:00
|
|
|
mContainer = aContainer;
|
2012-02-01 06:18:30 +04:00
|
|
|
}
|
|
|
|
|
2014-01-27 19:28:04 +04:00
|
|
|
void ImageLayer::ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface)
|
2012-02-01 06:18:30 +04:00
|
|
|
{
|
2014-01-27 19:28:18 +04:00
|
|
|
gfx::Matrix4x4 local = GetLocalTransform();
|
2012-09-18 07:16:15 +04:00
|
|
|
|
2012-08-19 23:33:25 +04:00
|
|
|
// Snap image edges to pixel boundaries
|
2012-09-18 07:16:15 +04:00
|
|
|
gfxRect sourceRect(0, 0, 0, 0);
|
2012-08-19 23:33:25 +04:00
|
|
|
if (mContainer) {
|
2015-03-29 17:59:15 +03:00
|
|
|
sourceRect.SizeTo(mContainer->GetCurrentSize());
|
2012-02-01 06:18:30 +04:00
|
|
|
}
|
2012-08-19 23:33:25 +04: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 21:06:08 +04: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 19:27:20 +04:00
|
|
|
mEffectiveTransform =
|
2012-09-18 07:16:15 +04:00
|
|
|
SnapTransform(local, sourceRect, nullptr) *
|
2014-01-27 19:28:04 +04:00
|
|
|
SnapTransformTranslation(aTransformToSurface, nullptr);
|
2014-12-07 04:12:50 +03: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;
|
|
|
|
}
|
|
|
|
|
2015-07-01 04:07:09 +03:00
|
|
|
ComputeEffectiveTransformForMaskLayers(aTransformToSurface);
|
2012-02-16 07:26:19 +04:00
|
|
|
}
|
2012-02-01 06:18:30 +04:00
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|