2017-10-28 02:10:06 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 15:12:37 +04:00
|
|
|
* 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)
|
2016-05-25 19:01:18 +03:00
|
|
|
: Layer(aManager, aImplData),
|
|
|
|
mSamplingFilter(gfx::SamplingFilter::GOOD),
|
2016-09-23 00:43:11 +03:00
|
|
|
mScaleMode(ScaleMode::SCALE_NONE) {}
|
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) {
|
|
|
|
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) {
|
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) {
|
2017-07-21 09:21:47 +03:00
|
|
|
sourceRect.SizeTo(gfx::SizeDouble(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).
|
2012-09-18 07:16:15 +04:00
|
|
|
mEffectiveTransform = SnapTransform(local, sourceRect, nullptr) *
|
2014-01-27 19:28:04 +04:00
|
|
|
SnapTransformTranslation(aTransformToSurface, nullptr);
|
2014-12-07 04:12:50 +03:00
|
|
|
|
2018-01-11 01:57:10 +03:00
|
|
|
if (mScaleMode != ScaleMode::SCALE_NONE && !sourceRect.IsZeroArea()) {
|
2014-12-07 04:12:50 +03:00
|
|
|
NS_ASSERTION(mScaleMode == ScaleMode::STRETCH,
|
|
|
|
"No other scalemodes than stretch and none supported yet.");
|
2017-08-14 15:29:28 +03:00
|
|
|
local.PreScale(mScaleToSize.width / sourceRect.Width(),
|
|
|
|
mScaleToSize.height / sourceRect.Height(), 1.0);
|
2014-12-07 04:12:50 +03:00
|
|
|
|
|
|
|
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
|