2012-01-31 18:18:30 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 04:12:37 -07: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-01-31 18:18:30 -08:00
|
|
|
|
|
|
|
#include "ImageLayers.h"
|
2013-08-11 16:17:23 -07: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 09:32:02 -08:00
|
|
|
#include "gfx2DGlue.h"
|
2012-01-31 18:18:30 -08:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2012-08-19 12:33:25 -07:00
|
|
|
ImageLayer::ImageLayer(LayerManager* aManager, void* aImplData)
|
2013-10-01 14:01:19 -07:00
|
|
|
: Layer(aManager, aImplData), mFilter(GraphicsFilter::FILTER_GOOD)
|
2014-01-23 10:26:41 -08:00
|
|
|
, mScaleMode(ScaleMode::SCALE_NONE), mDisallowBigImage(false)
|
2012-08-19 12:33:25 -07:00
|
|
|
{}
|
2012-02-15 19:26:19 -08:00
|
|
|
|
2012-08-19 12:33:25 -07:00
|
|
|
ImageLayer::~ImageLayer()
|
|
|
|
{}
|
2012-02-15 19:26:19 -08:00
|
|
|
|
2012-08-19 12:33:25 -07:00
|
|
|
void ImageLayer::SetContainer(ImageContainer* aContainer)
|
2012-01-31 18:18:30 -08:00
|
|
|
{
|
2012-08-19 12:33:25 -07:00
|
|
|
mContainer = aContainer;
|
2012-01-31 18:18:30 -08:00
|
|
|
}
|
|
|
|
|
2014-01-27 07:28:04 -08:00
|
|
|
void ImageLayer::ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface)
|
2012-01-31 18:18:30 -08:00
|
|
|
{
|
2014-01-27 07:28:18 -08:00
|
|
|
gfx::Matrix4x4 local = GetLocalTransform();
|
2012-09-17 20:16:15 -07:00
|
|
|
|
2012-08-19 12:33:25 -07:00
|
|
|
// Snap image edges to pixel boundaries
|
2012-09-17 20:16:15 -07:00
|
|
|
gfxRect sourceRect(0, 0, 0, 0);
|
2012-08-19 12:33:25 -07:00
|
|
|
if (mContainer) {
|
2013-12-13 09:32:02 -08:00
|
|
|
sourceRect.SizeTo(gfx::ThebesIntSize(mContainer->GetCurrentSize()));
|
2014-01-23 10:26:41 -08:00
|
|
|
if (mScaleMode != ScaleMode::SCALE_NONE &&
|
2012-09-17 20:16:15 -07:00
|
|
|
sourceRect.width != 0.0 && sourceRect.height != 0.0) {
|
2014-01-23 10:26:41 -08:00
|
|
|
NS_ASSERTION(mScaleMode == ScaleMode::STRETCH,
|
2012-09-17 20:16:15 -07:00
|
|
|
"No other scalemodes than stretch and none supported yet.");
|
|
|
|
local.Scale(mScaleToSize.width / sourceRect.width,
|
|
|
|
mScaleToSize.height / sourceRect.height, 1.0);
|
|
|
|
}
|
2012-01-31 18:18:30 -08:00
|
|
|
}
|
2012-08-19 12:33:25 -07: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-27 07:27:20 -08:00
|
|
|
mEffectiveTransform =
|
2012-09-17 20:16:15 -07:00
|
|
|
SnapTransform(local, sourceRect, nullptr) *
|
2014-01-27 07:28:04 -08:00
|
|
|
SnapTransformTranslation(aTransformToSurface, nullptr);
|
2012-08-19 12:33:25 -07:00
|
|
|
ComputeEffectiveTransformForMaskLayer(aTransformToSurface);
|
2012-02-15 19:26:19 -08:00
|
|
|
}
|
2012-01-31 18:18:30 -08:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|