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: #ifndef GFX_BASICTHEBESLAYER_H michael@0: #define GFX_BASICTHEBESLAYER_H michael@0: michael@0: #include "Layers.h" // for ThebesLayer, LayerManager, etc michael@0: #include "RotatedBuffer.h" // for RotatedContentBuffer, etc michael@0: #include "BasicImplData.h" // for BasicImplData michael@0: #include "BasicLayers.h" // for BasicLayerManager michael@0: #include "gfxPoint.h" // for gfxPoint michael@0: #include "mozilla/RefPtr.h" // for RefPtr michael@0: #include "mozilla/gfx/BasePoint.h" // for BasePoint michael@0: #include "mozilla/layers/ContentClient.h" // for ContentClientBasic michael@0: #include "mozilla/mozalloc.h" // for operator delete michael@0: #include "nsDebug.h" // for NS_ASSERTION michael@0: #include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc michael@0: #include "nsRegion.h" // for nsIntRegion michael@0: class gfxContext; michael@0: michael@0: namespace mozilla { michael@0: namespace layers { michael@0: michael@0: class ReadbackProcessor; michael@0: michael@0: class BasicThebesLayer : public ThebesLayer, public BasicImplData { michael@0: public: michael@0: typedef RotatedContentBuffer::PaintState PaintState; michael@0: typedef RotatedContentBuffer::ContentType ContentType; michael@0: michael@0: BasicThebesLayer(BasicLayerManager* aLayerManager) : michael@0: ThebesLayer(aLayerManager, michael@0: static_cast(MOZ_THIS_IN_INITIALIZER_LIST())), michael@0: mContentClient(nullptr) michael@0: { michael@0: MOZ_COUNT_CTOR(BasicThebesLayer); michael@0: } michael@0: virtual ~BasicThebesLayer() michael@0: { michael@0: MOZ_COUNT_DTOR(BasicThebesLayer); 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: ThebesLayer::SetVisibleRegion(aRegion); michael@0: } michael@0: virtual void InvalidateRegion(const nsIntRegion& aRegion) michael@0: { michael@0: NS_ASSERTION(BasicManager()->InConstruction(), michael@0: "Can only set properties in construction phase"); michael@0: mInvalidRegion.Or(mInvalidRegion, aRegion); michael@0: mInvalidRegion.SimplifyOutward(20); michael@0: mValidRegion.Sub(mValidRegion, mInvalidRegion); michael@0: } michael@0: michael@0: virtual void PaintThebes(gfxContext* aContext, michael@0: Layer* aMaskLayer, michael@0: LayerManager::DrawThebesLayerCallback aCallback, michael@0: void* aCallbackData, michael@0: ReadbackProcessor* aReadback); michael@0: michael@0: virtual void Validate(LayerManager::DrawThebesLayerCallback aCallback, michael@0: void* aCallbackData) MOZ_OVERRIDE; michael@0: michael@0: virtual void ClearCachedResources() michael@0: { michael@0: if (mContentClient) { michael@0: mContentClient->Clear(); michael@0: } michael@0: mValidRegion.SetEmpty(); michael@0: } michael@0: michael@0: virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface) michael@0: { michael@0: if (!BasicManager()->IsRetained()) { michael@0: // Don't do any snapping of our transform, since we're just going to michael@0: // draw straight through without intermediate buffers. michael@0: mEffectiveTransform = GetLocalTransform() * aTransformToSurface; michael@0: if (gfxPoint(0,0) != mResidualTranslation) { michael@0: mResidualTranslation = gfxPoint(0,0); michael@0: mValidRegion.SetEmpty(); michael@0: } michael@0: ComputeEffectiveTransformForMaskLayer(aTransformToSurface); michael@0: return; michael@0: } michael@0: ThebesLayer::ComputeEffectiveTransforms(aTransformToSurface); michael@0: } michael@0: michael@0: BasicLayerManager* BasicManager() michael@0: { michael@0: return static_cast(mManager); michael@0: } michael@0: michael@0: protected: michael@0: virtual void michael@0: PaintBuffer(gfxContext* aContext, michael@0: const nsIntRegion& aRegionToDraw, michael@0: const nsIntRegion& aExtendedRegionToDraw, michael@0: const nsIntRegion& aRegionToInvalidate, michael@0: bool aDidSelfCopy, michael@0: DrawRegionClip aClip, michael@0: LayerManager::DrawThebesLayerCallback aCallback, michael@0: void* aCallbackData) michael@0: { michael@0: if (!aCallback) { michael@0: BasicManager()->SetTransactionIncomplete(); michael@0: return; michael@0: } michael@0: aCallback(this, aContext, aExtendedRegionToDraw, aClip, michael@0: aRegionToInvalidate, aCallbackData); michael@0: // Everything that's visible has been validated. Do this instead of just michael@0: // OR-ing with aRegionToDraw, since that can lead to a very complex region michael@0: // here (OR doesn't automatically simplify to the simplest possible michael@0: // representation of a region.) michael@0: nsIntRegion tmp; michael@0: tmp.Or(mVisibleRegion, aExtendedRegionToDraw); michael@0: mValidRegion.Or(mValidRegion, tmp); michael@0: } michael@0: michael@0: RefPtr mContentClient; michael@0: }; michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif