michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "BasicLayersImpl.h" // for FillRectWithMask, etc michael@0: #include "Layers.h" // for ColorLayer, etc michael@0: #include "BasicImplData.h" // for BasicImplData michael@0: #include "BasicLayers.h" // for BasicLayerManager michael@0: #include "gfxContext.h" // for gfxContext, etc michael@0: #include "gfxRect.h" // for gfxRect michael@0: #include "gfx2DGlue.h" michael@0: #include "mozilla/mozalloc.h" // for operator new michael@0: #include "nsAutoPtr.h" // for nsRefPtr michael@0: #include "nsCOMPtr.h" // for already_AddRefed michael@0: #include "nsDebug.h" // for NS_ASSERTION michael@0: #include "nsISupportsImpl.h" // for Layer::AddRef, etc michael@0: #include "nsRect.h" // for nsIntRect michael@0: #include "nsRegion.h" // for nsIntRegion michael@0: #include "mozilla/gfx/PathHelpers.h" michael@0: michael@0: using namespace mozilla::gfx; michael@0: michael@0: namespace mozilla { michael@0: namespace layers { michael@0: michael@0: class BasicColorLayer : public ColorLayer, public BasicImplData { michael@0: public: michael@0: BasicColorLayer(BasicLayerManager* aLayerManager) : michael@0: ColorLayer(aLayerManager, michael@0: static_cast(MOZ_THIS_IN_INITIALIZER_LIST())) michael@0: { michael@0: MOZ_COUNT_CTOR(BasicColorLayer); michael@0: } michael@0: virtual ~BasicColorLayer() michael@0: { michael@0: MOZ_COUNT_DTOR(BasicColorLayer); michael@0: } michael@0: michael@0: virtual void SetVisibleRegion(const nsIntRegion& aRegion) michael@0: { michael@0: NS_ASSERTION(BasicManager()->InConstruction(), michael@0: "Can only set properties in construction phase"); michael@0: ColorLayer::SetVisibleRegion(aRegion); michael@0: } michael@0: michael@0: virtual void Paint(DrawTarget* aDT, michael@0: const gfx::Point& aDeviceOffset, michael@0: Layer* aMaskLayer) MOZ_OVERRIDE michael@0: { michael@0: if (IsHidden()) { michael@0: return; michael@0: } michael@0: michael@0: Rect snapped(mBounds.x, mBounds.y, mBounds.width, mBounds.height); michael@0: if (UserToDevicePixelSnapped(snapped, aDT->GetTransform())) { michael@0: Matrix mat = aDT->GetTransform(); michael@0: mat.Invert(); michael@0: snapped = mat.TransformBounds(snapped); michael@0: } michael@0: michael@0: FillRectWithMask(aDT, aDeviceOffset, snapped, ToColor(mColor), michael@0: DrawOptions(GetEffectiveOpacity(), GetEffectiveOperator(this)), michael@0: aMaskLayer); michael@0: } michael@0: michael@0: protected: michael@0: BasicLayerManager* BasicManager() michael@0: { michael@0: return static_cast(mManager); michael@0: } michael@0: }; michael@0: michael@0: already_AddRefed michael@0: BasicLayerManager::CreateColorLayer() michael@0: { michael@0: NS_ASSERTION(InConstruction(), "Only allowed in construction phase"); michael@0: nsRefPtr layer = new BasicColorLayer(this); michael@0: return layer.forget(); michael@0: } michael@0: michael@0: } michael@0: }