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 #ifndef GFX_IMAGELAYER_H 7 #define GFX_IMAGELAYER_H 8 9 #include "Layers.h" // for Layer, etc 10 #include "mozilla/gfx/BaseSize.h" // for BaseSize 11 #include "mozilla/gfx/Point.h" // for IntSize 12 #include "mozilla/layers/LayersTypes.h" 13 #include "nsAutoPtr.h" // for nsRefPtr 14 #include "nscore.h" // for nsACString 15 16 namespace mozilla { 17 namespace layers { 18 19 class ImageContainer; 20 21 namespace layerscope { 22 class LayersPacket; 23 } // namespace layerscope 24 25 /** 26 * A Layer which renders an Image. 27 */ 28 class ImageLayer : public Layer { 29 public: 30 /** 31 * CONSTRUCTION PHASE ONLY 32 * Set the ImageContainer. aContainer must have the same layer manager 33 * as this layer. 34 */ 35 virtual void SetContainer(ImageContainer* aContainer); 36 37 /** 38 * CONSTRUCTION PHASE ONLY 39 * Set the filter used to resample this image if necessary. 40 */ SetSamplingFilter(gfx::SamplingFilter aSamplingFilter)41 void SetSamplingFilter(gfx::SamplingFilter aSamplingFilter) 42 { 43 if (mSamplingFilter != aSamplingFilter) { 44 MOZ_LAYERS_LOG_IF_SHADOWABLE(this, ("Layer::Mutated(%p) Filter", this)); 45 mSamplingFilter = aSamplingFilter; 46 Mutated(); 47 } 48 } 49 50 /** 51 * CONSTRUCTION PHASE ONLY 52 * Set the size to scale the image to and the mode at which to scale. 53 */ SetScaleToSize(const gfx::IntSize & aSize,ScaleMode aMode)54 void SetScaleToSize(const gfx::IntSize &aSize, ScaleMode aMode) 55 { 56 if (mScaleToSize != aSize || mScaleMode != aMode) { 57 mScaleToSize = aSize; 58 mScaleMode = aMode; 59 Mutated(); 60 } 61 } 62 63 GetContainer()64 ImageContainer* GetContainer() { return mContainer; } GetSamplingFilter()65 gfx::SamplingFilter GetSamplingFilter() { return mSamplingFilter; } GetScaleToSize()66 const gfx::IntSize& GetScaleToSize() { return mScaleToSize; } GetScaleMode()67 ScaleMode GetScaleMode() { return mScaleMode; } 68 69 MOZ_LAYER_DECL_NAME("ImageLayer", TYPE_IMAGE) 70 71 virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface) override; 72 GetEffectiveTransformForBuffer()73 virtual const gfx::Matrix4x4& GetEffectiveTransformForBuffer() const override 74 { 75 return mEffectiveTransformForBuffer; 76 } 77 78 protected: 79 ImageLayer(LayerManager* aManager, void* aImplData); 80 ~ImageLayer(); 81 virtual void PrintInfo(std::stringstream& aStream, const char* aPrefix) override; 82 virtual void DumpPacket(layerscope::LayersPacket* aPacket, const void* aParent) override; 83 84 RefPtr<ImageContainer> mContainer; 85 gfx::SamplingFilter mSamplingFilter; 86 gfx::IntSize mScaleToSize; 87 ScaleMode mScaleMode; 88 gfx::Matrix4x4 mEffectiveTransformForBuffer; 89 }; 90 91 } // namespace layers 92 } // namespace mozilla 93 94 #endif /* GFX_IMAGELAYER_H */ 95