Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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/. */
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 "nsAutoPtr.h" // for nsRefPtr
15 #include "nsCOMPtr.h" // for already_AddRefed
16 #include "nsDebug.h" // for NS_ASSERTION
17 #include "nsISupportsImpl.h" // for Layer::AddRef, etc
18 #include "nsRect.h" // for nsIntRect
19 #include "nsRegion.h" // for nsIntRegion
20 #include "mozilla/gfx/PathHelpers.h"
22 using namespace mozilla::gfx;
24 namespace mozilla {
25 namespace layers {
27 class BasicColorLayer : public ColorLayer, public BasicImplData {
28 public:
29 BasicColorLayer(BasicLayerManager* aLayerManager) :
30 ColorLayer(aLayerManager,
31 static_cast<BasicImplData*>(MOZ_THIS_IN_INITIALIZER_LIST()))
32 {
33 MOZ_COUNT_CTOR(BasicColorLayer);
34 }
35 virtual ~BasicColorLayer()
36 {
37 MOZ_COUNT_DTOR(BasicColorLayer);
38 }
40 virtual void SetVisibleRegion(const nsIntRegion& aRegion)
41 {
42 NS_ASSERTION(BasicManager()->InConstruction(),
43 "Can only set properties in construction phase");
44 ColorLayer::SetVisibleRegion(aRegion);
45 }
47 virtual void Paint(DrawTarget* aDT,
48 const gfx::Point& aDeviceOffset,
49 Layer* aMaskLayer) MOZ_OVERRIDE
50 {
51 if (IsHidden()) {
52 return;
53 }
55 Rect snapped(mBounds.x, mBounds.y, mBounds.width, mBounds.height);
56 if (UserToDevicePixelSnapped(snapped, aDT->GetTransform())) {
57 Matrix mat = aDT->GetTransform();
58 mat.Invert();
59 snapped = mat.TransformBounds(snapped);
60 }
62 FillRectWithMask(aDT, aDeviceOffset, snapped, ToColor(mColor),
63 DrawOptions(GetEffectiveOpacity(), GetEffectiveOperator(this)),
64 aMaskLayer);
65 }
67 protected:
68 BasicLayerManager* BasicManager()
69 {
70 return static_cast<BasicLayerManager*>(mManager);
71 }
72 };
74 already_AddRefed<ColorLayer>
75 BasicLayerManager::CreateColorLayer()
76 {
77 NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
78 nsRefPtr<ColorLayer> layer = new BasicColorLayer(this);
79 return layer.forget();
80 }
82 }
83 }