1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/layers/ImageLayers.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,56 @@ 1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "ImageLayers.h" 1.10 +#include "ImageContainer.h" // for ImageContainer 1.11 +#include "gfxRect.h" // for gfxRect 1.12 +#include "nsDebug.h" // for NS_ASSERTION 1.13 +#include "nsISupportsImpl.h" // for ImageContainer::Release, etc 1.14 +#include "gfx2DGlue.h" 1.15 + 1.16 +namespace mozilla { 1.17 +namespace layers { 1.18 + 1.19 +ImageLayer::ImageLayer(LayerManager* aManager, void* aImplData) 1.20 +: Layer(aManager, aImplData), mFilter(GraphicsFilter::FILTER_GOOD) 1.21 +, mScaleMode(ScaleMode::SCALE_NONE), mDisallowBigImage(false) 1.22 +{} 1.23 + 1.24 +ImageLayer::~ImageLayer() 1.25 +{} 1.26 + 1.27 +void ImageLayer::SetContainer(ImageContainer* aContainer) 1.28 +{ 1.29 + mContainer = aContainer; 1.30 +} 1.31 + 1.32 +void ImageLayer::ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface) 1.33 +{ 1.34 + gfx::Matrix4x4 local = GetLocalTransform(); 1.35 + 1.36 + // Snap image edges to pixel boundaries 1.37 + gfxRect sourceRect(0, 0, 0, 0); 1.38 + if (mContainer) { 1.39 + sourceRect.SizeTo(gfx::ThebesIntSize(mContainer->GetCurrentSize())); 1.40 + if (mScaleMode != ScaleMode::SCALE_NONE && 1.41 + sourceRect.width != 0.0 && sourceRect.height != 0.0) { 1.42 + NS_ASSERTION(mScaleMode == ScaleMode::STRETCH, 1.43 + "No other scalemodes than stretch and none supported yet."); 1.44 + local.Scale(mScaleToSize.width / sourceRect.width, 1.45 + mScaleToSize.height / sourceRect.height, 1.0); 1.46 + } 1.47 + } 1.48 + // Snap our local transform first, and snap the inherited transform as well. 1.49 + // This makes our snapping equivalent to what would happen if our content 1.50 + // was drawn into a ThebesLayer (gfxContext would snap using the local 1.51 + // transform, then we'd snap again when compositing the ThebesLayer). 1.52 + mEffectiveTransform = 1.53 + SnapTransform(local, sourceRect, nullptr) * 1.54 + SnapTransformTranslation(aTransformToSurface, nullptr); 1.55 + ComputeEffectiveTransformForMaskLayer(aTransformToSurface); 1.56 +} 1.57 + 1.58 +} 1.59 +}