michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "ImageLayers.h" michael@0: #include "ImageContainer.h" // for ImageContainer michael@0: #include "gfxRect.h" // for gfxRect michael@0: #include "nsDebug.h" // for NS_ASSERTION michael@0: #include "nsISupportsImpl.h" // for ImageContainer::Release, etc michael@0: #include "gfx2DGlue.h" michael@0: michael@0: namespace mozilla { michael@0: namespace layers { michael@0: michael@0: ImageLayer::ImageLayer(LayerManager* aManager, void* aImplData) michael@0: : Layer(aManager, aImplData), mFilter(GraphicsFilter::FILTER_GOOD) michael@0: , mScaleMode(ScaleMode::SCALE_NONE), mDisallowBigImage(false) michael@0: {} michael@0: michael@0: ImageLayer::~ImageLayer() michael@0: {} michael@0: michael@0: void ImageLayer::SetContainer(ImageContainer* aContainer) michael@0: { michael@0: mContainer = aContainer; michael@0: } michael@0: michael@0: void ImageLayer::ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface) michael@0: { michael@0: gfx::Matrix4x4 local = GetLocalTransform(); michael@0: michael@0: // Snap image edges to pixel boundaries michael@0: gfxRect sourceRect(0, 0, 0, 0); michael@0: if (mContainer) { michael@0: sourceRect.SizeTo(gfx::ThebesIntSize(mContainer->GetCurrentSize())); michael@0: if (mScaleMode != ScaleMode::SCALE_NONE && michael@0: sourceRect.width != 0.0 && sourceRect.height != 0.0) { michael@0: NS_ASSERTION(mScaleMode == ScaleMode::STRETCH, michael@0: "No other scalemodes than stretch and none supported yet."); michael@0: local.Scale(mScaleToSize.width / sourceRect.width, michael@0: mScaleToSize.height / sourceRect.height, 1.0); michael@0: } michael@0: } michael@0: // Snap our local transform first, and snap the inherited transform as well. michael@0: // This makes our snapping equivalent to what would happen if our content michael@0: // was drawn into a ThebesLayer (gfxContext would snap using the local michael@0: // transform, then we'd snap again when compositing the ThebesLayer). michael@0: mEffectiveTransform = michael@0: SnapTransform(local, sourceRect, nullptr) * michael@0: SnapTransformTranslation(aTransformToSurface, nullptr); michael@0: ComputeEffectiveTransformForMaskLayer(aTransformToSurface); michael@0: } michael@0: michael@0: } michael@0: }