1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/layers/basic/BasicThebesLayer.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,130 @@ 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 +#ifndef GFX_BASICTHEBESLAYER_H 1.10 +#define GFX_BASICTHEBESLAYER_H 1.11 + 1.12 +#include "Layers.h" // for ThebesLayer, LayerManager, etc 1.13 +#include "RotatedBuffer.h" // for RotatedContentBuffer, etc 1.14 +#include "BasicImplData.h" // for BasicImplData 1.15 +#include "BasicLayers.h" // for BasicLayerManager 1.16 +#include "gfxPoint.h" // for gfxPoint 1.17 +#include "mozilla/RefPtr.h" // for RefPtr 1.18 +#include "mozilla/gfx/BasePoint.h" // for BasePoint 1.19 +#include "mozilla/layers/ContentClient.h" // for ContentClientBasic 1.20 +#include "mozilla/mozalloc.h" // for operator delete 1.21 +#include "nsDebug.h" // for NS_ASSERTION 1.22 +#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc 1.23 +#include "nsRegion.h" // for nsIntRegion 1.24 +class gfxContext; 1.25 + 1.26 +namespace mozilla { 1.27 +namespace layers { 1.28 + 1.29 +class ReadbackProcessor; 1.30 + 1.31 +class BasicThebesLayer : public ThebesLayer, public BasicImplData { 1.32 +public: 1.33 + typedef RotatedContentBuffer::PaintState PaintState; 1.34 + typedef RotatedContentBuffer::ContentType ContentType; 1.35 + 1.36 + BasicThebesLayer(BasicLayerManager* aLayerManager) : 1.37 + ThebesLayer(aLayerManager, 1.38 + static_cast<BasicImplData*>(MOZ_THIS_IN_INITIALIZER_LIST())), 1.39 + mContentClient(nullptr) 1.40 + { 1.41 + MOZ_COUNT_CTOR(BasicThebesLayer); 1.42 + } 1.43 + virtual ~BasicThebesLayer() 1.44 + { 1.45 + MOZ_COUNT_DTOR(BasicThebesLayer); 1.46 + } 1.47 + 1.48 + virtual void SetVisibleRegion(const nsIntRegion& aRegion) 1.49 + { 1.50 + NS_ASSERTION(BasicManager()->InConstruction(), 1.51 + "Can only set properties in construction phase"); 1.52 + ThebesLayer::SetVisibleRegion(aRegion); 1.53 + } 1.54 + virtual void InvalidateRegion(const nsIntRegion& aRegion) 1.55 + { 1.56 + NS_ASSERTION(BasicManager()->InConstruction(), 1.57 + "Can only set properties in construction phase"); 1.58 + mInvalidRegion.Or(mInvalidRegion, aRegion); 1.59 + mInvalidRegion.SimplifyOutward(20); 1.60 + mValidRegion.Sub(mValidRegion, mInvalidRegion); 1.61 + } 1.62 + 1.63 + virtual void PaintThebes(gfxContext* aContext, 1.64 + Layer* aMaskLayer, 1.65 + LayerManager::DrawThebesLayerCallback aCallback, 1.66 + void* aCallbackData, 1.67 + ReadbackProcessor* aReadback); 1.68 + 1.69 + virtual void Validate(LayerManager::DrawThebesLayerCallback aCallback, 1.70 + void* aCallbackData) MOZ_OVERRIDE; 1.71 + 1.72 + virtual void ClearCachedResources() 1.73 + { 1.74 + if (mContentClient) { 1.75 + mContentClient->Clear(); 1.76 + } 1.77 + mValidRegion.SetEmpty(); 1.78 + } 1.79 + 1.80 + virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface) 1.81 + { 1.82 + if (!BasicManager()->IsRetained()) { 1.83 + // Don't do any snapping of our transform, since we're just going to 1.84 + // draw straight through without intermediate buffers. 1.85 + mEffectiveTransform = GetLocalTransform() * aTransformToSurface; 1.86 + if (gfxPoint(0,0) != mResidualTranslation) { 1.87 + mResidualTranslation = gfxPoint(0,0); 1.88 + mValidRegion.SetEmpty(); 1.89 + } 1.90 + ComputeEffectiveTransformForMaskLayer(aTransformToSurface); 1.91 + return; 1.92 + } 1.93 + ThebesLayer::ComputeEffectiveTransforms(aTransformToSurface); 1.94 + } 1.95 + 1.96 + BasicLayerManager* BasicManager() 1.97 + { 1.98 + return static_cast<BasicLayerManager*>(mManager); 1.99 + } 1.100 + 1.101 +protected: 1.102 + virtual void 1.103 + PaintBuffer(gfxContext* aContext, 1.104 + const nsIntRegion& aRegionToDraw, 1.105 + const nsIntRegion& aExtendedRegionToDraw, 1.106 + const nsIntRegion& aRegionToInvalidate, 1.107 + bool aDidSelfCopy, 1.108 + DrawRegionClip aClip, 1.109 + LayerManager::DrawThebesLayerCallback aCallback, 1.110 + void* aCallbackData) 1.111 + { 1.112 + if (!aCallback) { 1.113 + BasicManager()->SetTransactionIncomplete(); 1.114 + return; 1.115 + } 1.116 + aCallback(this, aContext, aExtendedRegionToDraw, aClip, 1.117 + aRegionToInvalidate, aCallbackData); 1.118 + // Everything that's visible has been validated. Do this instead of just 1.119 + // OR-ing with aRegionToDraw, since that can lead to a very complex region 1.120 + // here (OR doesn't automatically simplify to the simplest possible 1.121 + // representation of a region.) 1.122 + nsIntRegion tmp; 1.123 + tmp.Or(mVisibleRegion, aExtendedRegionToDraw); 1.124 + mValidRegion.Or(mValidRegion, tmp); 1.125 + } 1.126 + 1.127 + RefPtr<ContentClientBasic> mContentClient; 1.128 +}; 1.129 + 1.130 +} 1.131 +} 1.132 + 1.133 +#endif