Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; 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 "BasicLayersImpl.h" // for FillRectWithMask, etc
7 : #include "Layers.h" // for ColorLayer, etc
8 : #include "BasicImplData.h" // for BasicImplData
9 : #include "BasicLayers.h" // for BasicLayerManager
10 : #include "gfxContext.h" // for gfxContext, etc
11 : #include "gfxRect.h" // for gfxRect
12 : #include "gfx2DGlue.h"
13 : #include "mozilla/mozalloc.h" // for operator new
14 : #include "nsCOMPtr.h" // for already_AddRefed
15 : #include "nsDebug.h" // for NS_ASSERTION
16 : #include "nsISupportsImpl.h" // for Layer::AddRef, etc
17 : #include "nsRect.h" // for mozilla::gfx::IntRect
18 : #include "nsRegion.h" // for nsIntRegion
19 : #include "mozilla/gfx/PathHelpers.h"
20 :
21 : using namespace mozilla::gfx;
22 :
23 : namespace mozilla {
24 : namespace layers {
25 :
26 : class BasicColorLayer : public ColorLayer, public BasicImplData {
27 : public:
28 0 : explicit BasicColorLayer(BasicLayerManager* aLayerManager) :
29 0 : ColorLayer(aLayerManager, static_cast<BasicImplData*>(this))
30 : {
31 0 : MOZ_COUNT_CTOR(BasicColorLayer);
32 0 : }
33 :
34 : protected:
35 0 : virtual ~BasicColorLayer()
36 0 : {
37 0 : MOZ_COUNT_DTOR(BasicColorLayer);
38 0 : }
39 :
40 : public:
41 0 : virtual void SetVisibleRegion(const LayerIntRegion& aRegion) override
42 : {
43 0 : NS_ASSERTION(BasicManager()->InConstruction(),
44 : "Can only set properties in construction phase");
45 0 : ColorLayer::SetVisibleRegion(aRegion);
46 0 : }
47 :
48 0 : virtual void Paint(DrawTarget* aDT,
49 : const gfx::Point& aDeviceOffset,
50 : Layer* aMaskLayer) override
51 : {
52 0 : if (IsHidden()) {
53 0 : return;
54 : }
55 :
56 0 : Rect snapped(mBounds.x, mBounds.y, mBounds.width, mBounds.height);
57 0 : MaybeSnapToDevicePixels(snapped, *aDT, true);
58 :
59 : // Clip drawing in case we're using (unbounded) operator source.
60 0 : aDT->PushClipRect(snapped);
61 0 : FillRectWithMask(aDT, aDeviceOffset, snapped, mColor,
62 0 : DrawOptions(GetEffectiveOpacity(), GetEffectiveOperator(this)),
63 0 : aMaskLayer);
64 0 : aDT->PopClip();
65 : }
66 :
67 : protected:
68 0 : BasicLayerManager* BasicManager()
69 : {
70 0 : return static_cast<BasicLayerManager*>(mManager);
71 : }
72 : };
73 :
74 : already_AddRefed<ColorLayer>
75 0 : BasicLayerManager::CreateColorLayer()
76 : {
77 0 : NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
78 0 : RefPtr<ColorLayer> layer = new BasicColorLayer(this);
79 0 : return layer.forget();
80 : }
81 :
82 : } // namespace layers
83 9 : } // namespace mozilla
|