1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/layers/composite/ThebesLayerComposite.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,208 @@ 1.4 +/* -*- Mode: C++; tab-width: 20; 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 "ThebesLayerComposite.h" 1.10 +#include "CompositableHost.h" // for TiledLayerProperties, etc 1.11 +#include "FrameMetrics.h" // for FrameMetrics 1.12 +#include "Units.h" // for CSSRect, LayerPixel, etc 1.13 +#include "gfx2DGlue.h" // for ToMatrix4x4 1.14 +#include "gfxUtils.h" // for gfxUtils, etc 1.15 +#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc 1.16 +#include "mozilla/gfx/Matrix.h" // for Matrix4x4 1.17 +#include "mozilla/gfx/Point.h" // for Point 1.18 +#include "mozilla/gfx/Rect.h" // for RoundedToInt, Rect 1.19 +#include "mozilla/gfx/Types.h" // for Filter::Filter::LINEAR 1.20 +#include "mozilla/layers/Compositor.h" // for Compositor 1.21 +#include "mozilla/layers/ContentHost.h" // for ContentHost 1.22 +#include "mozilla/layers/Effects.h" // for EffectChain 1.23 +#include "mozilla/mozalloc.h" // for operator delete 1.24 +#include "nsAString.h" 1.25 +#include "nsAutoPtr.h" // for nsRefPtr 1.26 +#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc 1.27 +#include "nsMathUtils.h" // for NS_lround 1.28 +#include "nsPoint.h" // for nsIntPoint 1.29 +#include "nsRect.h" // for nsIntRect 1.30 +#include "nsSize.h" // for nsIntSize 1.31 +#include "nsString.h" // for nsAutoCString 1.32 +#include "TextRenderer.h" 1.33 +#include "GeckoProfiler.h" 1.34 + 1.35 +namespace mozilla { 1.36 +namespace layers { 1.37 + 1.38 +class TiledLayerComposer; 1.39 + 1.40 +ThebesLayerComposite::ThebesLayerComposite(LayerManagerComposite *aManager) 1.41 + : ThebesLayer(aManager, nullptr) 1.42 + , LayerComposite(aManager) 1.43 + , mBuffer(nullptr) 1.44 + , mRequiresTiledProperties(false) 1.45 +{ 1.46 + MOZ_COUNT_CTOR(ThebesLayerComposite); 1.47 + mImplData = static_cast<LayerComposite*>(this); 1.48 +} 1.49 + 1.50 +ThebesLayerComposite::~ThebesLayerComposite() 1.51 +{ 1.52 + MOZ_COUNT_DTOR(ThebesLayerComposite); 1.53 + CleanupResources(); 1.54 +} 1.55 + 1.56 +bool 1.57 +ThebesLayerComposite::SetCompositableHost(CompositableHost* aHost) 1.58 +{ 1.59 + switch (aHost->GetType()) { 1.60 + case BUFFER_CONTENT_INC: 1.61 + case BUFFER_TILED: 1.62 + case COMPOSITABLE_CONTENT_SINGLE: 1.63 + case COMPOSITABLE_CONTENT_DOUBLE: 1.64 + mBuffer = static_cast<ContentHost*>(aHost); 1.65 + return true; 1.66 + default: 1.67 + return false; 1.68 + } 1.69 +} 1.70 + 1.71 +void 1.72 +ThebesLayerComposite::Disconnect() 1.73 +{ 1.74 + Destroy(); 1.75 +} 1.76 + 1.77 +void 1.78 +ThebesLayerComposite::Destroy() 1.79 +{ 1.80 + if (!mDestroyed) { 1.81 + CleanupResources(); 1.82 + mDestroyed = true; 1.83 + } 1.84 +} 1.85 + 1.86 +Layer* 1.87 +ThebesLayerComposite::GetLayer() 1.88 +{ 1.89 + return this; 1.90 +} 1.91 + 1.92 +TiledLayerComposer* 1.93 +ThebesLayerComposite::GetTiledLayerComposer() 1.94 +{ 1.95 + if (!mBuffer) { 1.96 + return nullptr; 1.97 + } 1.98 + MOZ_ASSERT(mBuffer->IsAttached()); 1.99 + return mBuffer->AsTiledLayerComposer(); 1.100 +} 1.101 + 1.102 +LayerRenderState 1.103 +ThebesLayerComposite::GetRenderState() 1.104 +{ 1.105 + if (!mBuffer || !mBuffer->IsAttached() || mDestroyed) { 1.106 + return LayerRenderState(); 1.107 + } 1.108 + return mBuffer->GetRenderState(); 1.109 +} 1.110 + 1.111 +void 1.112 +ThebesLayerComposite::RenderLayer(const nsIntRect& aClipRect) 1.113 +{ 1.114 + if (!mBuffer || !mBuffer->IsAttached()) { 1.115 + return; 1.116 + } 1.117 + PROFILER_LABEL("ThebesLayerComposite", "RenderLayer"); 1.118 + 1.119 + MOZ_ASSERT(mBuffer->GetCompositor() == mCompositeManager->GetCompositor() && 1.120 + mBuffer->GetLayer() == this, 1.121 + "buffer is corrupted"); 1.122 + 1.123 + gfx::Rect clipRect(aClipRect.x, aClipRect.y, aClipRect.width, aClipRect.height); 1.124 + 1.125 +#ifdef MOZ_DUMP_PAINTING 1.126 + if (gfxUtils::sDumpPainting) { 1.127 + RefPtr<gfx::DataSourceSurface> surf = mBuffer->GetAsSurface(); 1.128 + if (surf) { 1.129 + WriteSnapshotToDumpFile(this, surf); 1.130 + } 1.131 + } 1.132 +#endif 1.133 + 1.134 + EffectChain effectChain(this); 1.135 + LayerManagerComposite::AutoAddMaskEffect autoMaskEffect(mMaskLayer, effectChain); 1.136 + 1.137 + nsIntRegion visibleRegion = GetEffectiveVisibleRegion(); 1.138 + 1.139 + TiledLayerProperties tiledLayerProps; 1.140 + if (mRequiresTiledProperties) { 1.141 + tiledLayerProps.mVisibleRegion = visibleRegion; 1.142 + tiledLayerProps.mEffectiveResolution = GetEffectiveResolution(); 1.143 + tiledLayerProps.mValidRegion = mValidRegion; 1.144 + } 1.145 + 1.146 + mBuffer->SetPaintWillResample(MayResample()); 1.147 + 1.148 + mBuffer->Composite(effectChain, 1.149 + GetEffectiveOpacity(), 1.150 + GetEffectiveTransform(), 1.151 + gfx::Filter::LINEAR, 1.152 + clipRect, 1.153 + &visibleRegion, 1.154 + mRequiresTiledProperties ? &tiledLayerProps 1.155 + : nullptr); 1.156 + mBuffer->BumpFlashCounter(); 1.157 + 1.158 + if (mRequiresTiledProperties) { 1.159 + mValidRegion = tiledLayerProps.mValidRegion; 1.160 + } 1.161 + 1.162 + mCompositeManager->GetCompositor()->MakeCurrent(); 1.163 +} 1.164 + 1.165 +CompositableHost* 1.166 +ThebesLayerComposite::GetCompositableHost() 1.167 +{ 1.168 + if (mBuffer && mBuffer->IsAttached()) { 1.169 + return mBuffer.get(); 1.170 + } 1.171 + 1.172 + return nullptr; 1.173 +} 1.174 + 1.175 +void 1.176 +ThebesLayerComposite::CleanupResources() 1.177 +{ 1.178 + if (mBuffer) { 1.179 + mBuffer->Detach(this); 1.180 + } 1.181 + mBuffer = nullptr; 1.182 +} 1.183 + 1.184 +CSSToScreenScale 1.185 +ThebesLayerComposite::GetEffectiveResolution() 1.186 +{ 1.187 + for (ContainerLayer* parent = GetParent(); parent; parent = parent->GetParent()) { 1.188 + const FrameMetrics& metrics = parent->GetFrameMetrics(); 1.189 + if (metrics.GetScrollId() != FrameMetrics::NULL_SCROLL_ID) { 1.190 + return metrics.GetZoom(); 1.191 + } 1.192 + } 1.193 + 1.194 + return CSSToScreenScale(1.0); 1.195 +} 1.196 + 1.197 +nsACString& 1.198 +ThebesLayerComposite::PrintInfo(nsACString& aTo, const char* aPrefix) 1.199 +{ 1.200 + ThebesLayer::PrintInfo(aTo, aPrefix); 1.201 + aTo += "\n"; 1.202 + if (mBuffer && mBuffer->IsAttached()) { 1.203 + nsAutoCString pfx(aPrefix); 1.204 + pfx += " "; 1.205 + mBuffer->PrintInfo(aTo, pfx.get()); 1.206 + } 1.207 + return aTo; 1.208 +} 1.209 + 1.210 +} /* layers */ 1.211 +} /* mozilla */