Source code

Revision control

Other Tools

1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
* License, v. 2.0. If a copy of the MPL was not distributed with this
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "ImageLayers.h"
8
#include "ImageContainer.h" // for ImageContainer
9
#include "gfxRect.h" // for gfxRect
10
#include "nsDebug.h" // for NS_ASSERTION
11
#include "nsISupportsImpl.h" // for ImageContainer::Release, etc
12
#include "gfx2DGlue.h"
13
14
namespace mozilla {
15
namespace layers {
16
17
ImageLayer::ImageLayer(LayerManager* aManager, void* aImplData)
18
: Layer(aManager, aImplData),
19
mSamplingFilter(gfx::SamplingFilter::GOOD),
20
mScaleMode(ScaleMode::SCALE_NONE) {}
21
22
ImageLayer::~ImageLayer() = default;
23
24
void ImageLayer::SetContainer(ImageContainer* aContainer) {
25
mContainer = aContainer;
26
}
27
28
void ImageLayer::ComputeEffectiveTransforms(
29
const gfx::Matrix4x4& aTransformToSurface) {
30
gfx::Matrix4x4 local = GetLocalTransform();
31
32
// Snap image edges to pixel boundaries
33
gfxRect sourceRect(0, 0, 0, 0);
34
if (mContainer) {
35
sourceRect.SizeTo(gfx::SizeDouble(mContainer->GetCurrentSize()));
36
}
37
// Snap our local transform first, and snap the inherited transform as well.
38
// This makes our snapping equivalent to what would happen if our content
39
// was drawn into a PaintedLayer (gfxContext would snap using the local
40
// transform, then we'd snap again when compositing the PaintedLayer).
41
mEffectiveTransform = SnapTransform(local, sourceRect, nullptr) *
42
SnapTransformTranslation(aTransformToSurface, nullptr);
43
44
if (mScaleMode != ScaleMode::SCALE_NONE && !sourceRect.IsZeroArea()) {
45
NS_ASSERTION(mScaleMode == ScaleMode::STRETCH,
46
"No other scalemodes than stretch and none supported yet.");
47
local.PreScale(mScaleToSize.width / sourceRect.Width(),
48
mScaleToSize.height / sourceRect.Height(), 1.0);
49
50
mEffectiveTransformForBuffer =
51
SnapTransform(local, sourceRect, nullptr) *
52
SnapTransformTranslation(aTransformToSurface, nullptr);
53
} else {
54
mEffectiveTransformForBuffer = mEffectiveTransform;
55
}
56
57
ComputeEffectiveTransformForMaskLayers(aTransformToSurface);
58
}
59
60
} // namespace layers
61
} // namespace mozilla