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 "gfx3DMatrix.h" // for gfx3DMatrix
|
|
|
|
#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
|
|
|
}
|
|
|
|
|
2012-08-19 23:33:25 +04:00
|
|
|
void ImageLayer::ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface)
|
2012-02-01 06:18:30 +04:00
|
|
|
{
|
2012-09-18 07:16:15 +04:00
|
|
|
gfx3DMatrix local = GetLocalTransform();
|
|
|
|
|
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) {
|
2013-12-13 21:32:02 +04:00
|
|
|
sourceRect.SizeTo(gfx::ThebesIntSize(mContainer->GetCurrentSize()));
|
2014-01-23 22:26:41 +04:00
|
|
|
if (mScaleMode != ScaleMode::SCALE_NONE &&
|
2012-09-18 07:16:15 +04:00
|
|
|
sourceRect.width != 0.0 && sourceRect.height != 0.0) {
|
2014-01-23 22:26:41 +04:00
|
|
|
NS_ASSERTION(mScaleMode == ScaleMode::STRETCH,
|
2012-09-18 07:16:15 +04:00
|
|
|
"No other scalemodes than stretch and none supported yet.");
|
|
|
|
local.Scale(mScaleToSize.width / sourceRect.width,
|
|
|
|
mScaleToSize.height / sourceRect.height, 1.0);
|
|
|
|
}
|
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
|
|
|
|
// was drawn into a ThebesLayer (gfxContext would snap using the local
|
|
|
|
// transform, then we'd snap again when compositing the ThebesLayer).
|
2014-01-25 05:49:19 +04:00
|
|
|
gfx3DMatrix snappedTransform =
|
2012-09-18 07:16:15 +04:00
|
|
|
SnapTransform(local, sourceRect, nullptr) *
|
2012-12-07 03:58:13 +04:00
|
|
|
SnapTransformTranslation(aTransformToSurface, nullptr);
|
2014-01-25 05:49:19 +04:00
|
|
|
gfx::ToMatrix4x4(snappedTransform, mEffectiveTransform);
|
2012-08-19 23:33:25 +04:00
|
|
|
ComputeEffectiveTransformForMaskLayer(aTransformToSurface);
|
2012-02-16 07:26:19 +04:00
|
|
|
}
|
2012-02-01 06:18:30 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|