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