1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/layers/basic/BasicColorLayer.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,83 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "BasicLayersImpl.h" // for FillRectWithMask, etc 1.10 +#include "Layers.h" // for ColorLayer, etc 1.11 +#include "BasicImplData.h" // for BasicImplData 1.12 +#include "BasicLayers.h" // for BasicLayerManager 1.13 +#include "gfxContext.h" // for gfxContext, etc 1.14 +#include "gfxRect.h" // for gfxRect 1.15 +#include "gfx2DGlue.h" 1.16 +#include "mozilla/mozalloc.h" // for operator new 1.17 +#include "nsAutoPtr.h" // for nsRefPtr 1.18 +#include "nsCOMPtr.h" // for already_AddRefed 1.19 +#include "nsDebug.h" // for NS_ASSERTION 1.20 +#include "nsISupportsImpl.h" // for Layer::AddRef, etc 1.21 +#include "nsRect.h" // for nsIntRect 1.22 +#include "nsRegion.h" // for nsIntRegion 1.23 +#include "mozilla/gfx/PathHelpers.h" 1.24 + 1.25 +using namespace mozilla::gfx; 1.26 + 1.27 +namespace mozilla { 1.28 +namespace layers { 1.29 + 1.30 +class BasicColorLayer : public ColorLayer, public BasicImplData { 1.31 +public: 1.32 + BasicColorLayer(BasicLayerManager* aLayerManager) : 1.33 + ColorLayer(aLayerManager, 1.34 + static_cast<BasicImplData*>(MOZ_THIS_IN_INITIALIZER_LIST())) 1.35 + { 1.36 + MOZ_COUNT_CTOR(BasicColorLayer); 1.37 + } 1.38 + virtual ~BasicColorLayer() 1.39 + { 1.40 + MOZ_COUNT_DTOR(BasicColorLayer); 1.41 + } 1.42 + 1.43 + virtual void SetVisibleRegion(const nsIntRegion& aRegion) 1.44 + { 1.45 + NS_ASSERTION(BasicManager()->InConstruction(), 1.46 + "Can only set properties in construction phase"); 1.47 + ColorLayer::SetVisibleRegion(aRegion); 1.48 + } 1.49 + 1.50 + virtual void Paint(DrawTarget* aDT, 1.51 + const gfx::Point& aDeviceOffset, 1.52 + Layer* aMaskLayer) MOZ_OVERRIDE 1.53 + { 1.54 + if (IsHidden()) { 1.55 + return; 1.56 + } 1.57 + 1.58 + Rect snapped(mBounds.x, mBounds.y, mBounds.width, mBounds.height); 1.59 + if (UserToDevicePixelSnapped(snapped, aDT->GetTransform())) { 1.60 + Matrix mat = aDT->GetTransform(); 1.61 + mat.Invert(); 1.62 + snapped = mat.TransformBounds(snapped); 1.63 + } 1.64 + 1.65 + FillRectWithMask(aDT, aDeviceOffset, snapped, ToColor(mColor), 1.66 + DrawOptions(GetEffectiveOpacity(), GetEffectiveOperator(this)), 1.67 + aMaskLayer); 1.68 + } 1.69 + 1.70 +protected: 1.71 + BasicLayerManager* BasicManager() 1.72 + { 1.73 + return static_cast<BasicLayerManager*>(mManager); 1.74 + } 1.75 +}; 1.76 + 1.77 +already_AddRefed<ColorLayer> 1.78 +BasicLayerManager::CreateColorLayer() 1.79 +{ 1.80 + NS_ASSERTION(InConstruction(), "Only allowed in construction phase"); 1.81 + nsRefPtr<ColorLayer> layer = new BasicColorLayer(this); 1.82 + return layer.forget(); 1.83 +} 1.84 + 1.85 +} 1.86 +}