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 Layer, 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 : #include "mozilla/gfx/Helpers.h"
21 : #include "nsDisplayList.h" // for nsDisplayItem
22 : #include "nsCaret.h"
23 :
24 : using namespace mozilla::gfx;
25 :
26 : namespace mozilla {
27 : namespace layers {
28 :
29 : class BasicDisplayItemLayer : public DisplayItemLayer, public BasicImplData {
30 : public:
31 0 : explicit BasicDisplayItemLayer(BasicLayerManager* aLayerManager) :
32 0 : DisplayItemLayer(aLayerManager, static_cast<BasicImplData*>(this))
33 : {
34 0 : MOZ_COUNT_CTOR(BasicDisplayItemLayer);
35 0 : }
36 :
37 : protected:
38 0 : virtual ~BasicDisplayItemLayer()
39 0 : {
40 0 : MOZ_COUNT_DTOR(BasicDisplayItemLayer);
41 0 : }
42 :
43 : public:
44 0 : virtual void SetVisibleRegion(const LayerIntRegion& aRegion) override
45 : {
46 0 : NS_ASSERTION(BasicManager()->InConstruction(),
47 : "Can only set properties in construction phase");
48 0 : DisplayItemLayer::SetVisibleRegion(aRegion);
49 0 : }
50 :
51 0 : virtual void Paint(DrawTarget* aDT,
52 : const gfx::Point& aDeviceOffset,
53 : Layer* aMaskLayer) override
54 : {
55 0 : if (IsHidden() || !mItem || !mBuilder) {
56 0 : return;
57 : }
58 :
59 0 : AutoRestoreTransform autoRestoreTransform(aDT);
60 0 : Matrix transform = aDT->GetTransform();
61 0 : RefPtr<gfxContext> context = gfxContext::CreateOrNull(aDT, aDeviceOffset);
62 0 : context->SetMatrix(ThebesMatrix(transform));
63 :
64 0 : mItem->Paint(mBuilder, context);
65 : }
66 :
67 : protected:
68 0 : BasicLayerManager* BasicManager()
69 : {
70 0 : return static_cast<BasicLayerManager*>(mManager);
71 : }
72 : };
73 :
74 : already_AddRefed<DisplayItemLayer>
75 0 : BasicLayerManager::CreateDisplayItemLayer()
76 : {
77 0 : NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
78 0 : RefPtr<DisplayItemLayer> layer = new BasicDisplayItemLayer(this);
79 0 : return layer.forget();
80 : }
81 :
82 : } // namespace layers
83 : } // namespace mozilla
|