1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef GFX_IMAGELAYER_H
8 #define GFX_IMAGELAYER_H
9 
10 #include "Layers.h"                // for Layer, etc
11 #include "mozilla/gfx/BaseSize.h"  // for BaseSize
12 #include "mozilla/gfx/Point.h"     // for IntSize
13 #include "mozilla/layers/LayersTypes.h"
14 #include "nsAutoPtr.h"  // for nsRefPtr
15 #include "nscore.h"     // for nsACString
16 
17 namespace mozilla {
18 namespace layers {
19 
20 class ImageContainer;
21 
22 namespace layerscope {
23 class LayersPacket;
24 }  // namespace layerscope
25 
26 /**
27  * A Layer which renders an Image.
28  */
29 class ImageLayer : public Layer {
30  public:
31   /**
32    * CONSTRUCTION PHASE ONLY
33    * Set the ImageContainer. aContainer must have the same layer manager
34    * as this layer.
35    */
36   virtual void SetContainer(ImageContainer* aContainer);
37 
38   /**
39    * CONSTRUCTION PHASE ONLY
40    * Set the filter used to resample this image if necessary.
41    */
SetSamplingFilter(gfx::SamplingFilter aSamplingFilter)42   void SetSamplingFilter(gfx::SamplingFilter aSamplingFilter) {
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     if (mScaleToSize != aSize || mScaleMode != aMode) {
56       mScaleToSize = aSize;
57       mScaleMode = aMode;
58       Mutated();
59     }
60   }
61 
GetContainer()62   ImageContainer* GetContainer() { return mContainer; }
GetSamplingFilter()63   gfx::SamplingFilter GetSamplingFilter() { return mSamplingFilter; }
GetScaleToSize()64   const gfx::IntSize& GetScaleToSize() { return mScaleToSize; }
GetScaleMode()65   ScaleMode GetScaleMode() { return mScaleMode; }
66 
67   MOZ_LAYER_DECL_NAME("ImageLayer", TYPE_IMAGE)
68 
69   virtual void ComputeEffectiveTransforms(
70       const gfx::Matrix4x4& aTransformToSurface) override;
71 
GetEffectiveTransformForBuffer()72   virtual const gfx::Matrix4x4& GetEffectiveTransformForBuffer()
73       const override {
74     return mEffectiveTransformForBuffer;
75   }
76 
AsImageLayer()77   virtual ImageLayer* AsImageLayer() override { return this; }
78 
79  protected:
80   ImageLayer(LayerManager* aManager, void* aImplData);
81   ~ImageLayer();
82   virtual void PrintInfo(std::stringstream& aStream,
83                          const char* aPrefix) override;
84   virtual void DumpPacket(layerscope::LayersPacket* aPacket,
85                           const void* aParent) override;
86 
87   RefPtr<ImageContainer> mContainer;
88   gfx::SamplingFilter mSamplingFilter;
89   gfx::IntSize mScaleToSize;
90   ScaleMode mScaleMode;
91   gfx::Matrix4x4 mEffectiveTransformForBuffer;
92 };
93 
94 }  // namespace layers
95 }  // namespace mozilla
96 
97 #endif /* GFX_IMAGELAYER_H */
98