|
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 ImageLayer::ImageLayer(LayerManager* aManager, void* aImplData) |
|
17 : Layer(aManager, aImplData), mFilter(GraphicsFilter::FILTER_GOOD) |
|
18 , mScaleMode(ScaleMode::SCALE_NONE), mDisallowBigImage(false) |
|
19 {} |
|
20 |
|
21 ImageLayer::~ImageLayer() |
|
22 {} |
|
23 |
|
24 void ImageLayer::SetContainer(ImageContainer* aContainer) |
|
25 { |
|
26 mContainer = aContainer; |
|
27 } |
|
28 |
|
29 void ImageLayer::ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface) |
|
30 { |
|
31 gfx::Matrix4x4 local = GetLocalTransform(); |
|
32 |
|
33 // Snap image edges to pixel boundaries |
|
34 gfxRect sourceRect(0, 0, 0, 0); |
|
35 if (mContainer) { |
|
36 sourceRect.SizeTo(gfx::ThebesIntSize(mContainer->GetCurrentSize())); |
|
37 if (mScaleMode != ScaleMode::SCALE_NONE && |
|
38 sourceRect.width != 0.0 && sourceRect.height != 0.0) { |
|
39 NS_ASSERTION(mScaleMode == ScaleMode::STRETCH, |
|
40 "No other scalemodes than stretch and none supported yet."); |
|
41 local.Scale(mScaleToSize.width / sourceRect.width, |
|
42 mScaleToSize.height / sourceRect.height, 1.0); |
|
43 } |
|
44 } |
|
45 // Snap our local transform first, and snap the inherited transform as well. |
|
46 // This makes our snapping equivalent to what would happen if our content |
|
47 // was drawn into a ThebesLayer (gfxContext would snap using the local |
|
48 // transform, then we'd snap again when compositing the ThebesLayer). |
|
49 mEffectiveTransform = |
|
50 SnapTransform(local, sourceRect, nullptr) * |
|
51 SnapTransformTranslation(aTransformToSurface, nullptr); |
|
52 ComputeEffectiveTransformForMaskLayer(aTransformToSurface); |
|
53 } |
|
54 |
|
55 } |
|
56 } |