1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/layers/composite/ImageLayerComposite.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,177 @@ 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 "ImageLayerComposite.h" 1.10 +#include "CompositableHost.h" // for CompositableHost 1.11 +#include "Layers.h" // for WriteSnapshotToDumpFile, etc 1.12 +#include "gfx2DGlue.h" // for ToFilter, ToMatrix4x4 1.13 +#include "gfxRect.h" // for gfxRect 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 IntSize, Point 1.18 +#include "mozilla/gfx/Rect.h" // for Rect 1.19 +#include "mozilla/layers/Compositor.h" // for Compositor 1.20 +#include "mozilla/layers/Effects.h" // for EffectChain 1.21 +#include "mozilla/layers/TextureHost.h" // for TextureHost, etc 1.22 +#include "mozilla/mozalloc.h" // for operator delete 1.23 +#include "nsAString.h" 1.24 +#include "nsAutoPtr.h" // for nsRefPtr 1.25 +#include "nsDebug.h" // for NS_ASSERTION 1.26 +#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc 1.27 +#include "nsPoint.h" // for nsIntPoint 1.28 +#include "nsRect.h" // for nsIntRect 1.29 +#include "nsString.h" // for nsAutoCString 1.30 + 1.31 +using namespace mozilla::gfx; 1.32 + 1.33 +namespace mozilla { 1.34 +namespace layers { 1.35 + 1.36 +ImageLayerComposite::ImageLayerComposite(LayerManagerComposite* aManager) 1.37 + : ImageLayer(aManager, nullptr) 1.38 + , LayerComposite(aManager) 1.39 + , mImageHost(nullptr) 1.40 +{ 1.41 + MOZ_COUNT_CTOR(ImageLayerComposite); 1.42 + mImplData = static_cast<LayerComposite*>(this); 1.43 +} 1.44 + 1.45 +ImageLayerComposite::~ImageLayerComposite() 1.46 +{ 1.47 + MOZ_COUNT_DTOR(ImageLayerComposite); 1.48 + MOZ_ASSERT(mDestroyed); 1.49 + 1.50 + CleanupResources(); 1.51 +} 1.52 + 1.53 +bool 1.54 +ImageLayerComposite::SetCompositableHost(CompositableHost* aHost) 1.55 +{ 1.56 + switch (aHost->GetType()) { 1.57 + case BUFFER_IMAGE_SINGLE: 1.58 + case BUFFER_IMAGE_BUFFERED: 1.59 + case COMPOSITABLE_IMAGE: 1.60 + mImageHost = aHost; 1.61 + return true; 1.62 + default: 1.63 + return false; 1.64 + } 1.65 +} 1.66 + 1.67 +void 1.68 +ImageLayerComposite::Disconnect() 1.69 +{ 1.70 + Destroy(); 1.71 +} 1.72 + 1.73 +LayerRenderState 1.74 +ImageLayerComposite::GetRenderState() 1.75 +{ 1.76 + if (mImageHost && mImageHost->IsAttached()) { 1.77 + return mImageHost->GetRenderState(); 1.78 + } 1.79 + return LayerRenderState(); 1.80 +} 1.81 + 1.82 +Layer* 1.83 +ImageLayerComposite::GetLayer() 1.84 +{ 1.85 + return this; 1.86 +} 1.87 + 1.88 +void 1.89 +ImageLayerComposite::RenderLayer(const nsIntRect& aClipRect) 1.90 +{ 1.91 + if (!mImageHost || !mImageHost->IsAttached()) { 1.92 + return; 1.93 + } 1.94 + 1.95 +#ifdef MOZ_DUMP_PAINTING 1.96 + if (gfxUtils::sDumpPainting) { 1.97 + RefPtr<gfx::DataSourceSurface> surf = mImageHost->GetAsSurface(); 1.98 + WriteSnapshotToDumpFile(this, surf); 1.99 + } 1.100 +#endif 1.101 + 1.102 + mCompositor->MakeCurrent(); 1.103 + 1.104 + EffectChain effectChain(this); 1.105 + LayerManagerComposite::AutoAddMaskEffect autoMaskEffect(mMaskLayer, effectChain); 1.106 + 1.107 + gfx::Rect clipRect(aClipRect.x, aClipRect.y, aClipRect.width, aClipRect.height); 1.108 + mImageHost->SetCompositor(mCompositor); 1.109 + mImageHost->Composite(effectChain, 1.110 + GetEffectiveOpacity(), 1.111 + GetEffectiveTransform(), 1.112 + gfx::ToFilter(mFilter), 1.113 + clipRect); 1.114 + mImageHost->BumpFlashCounter(); 1.115 +} 1.116 + 1.117 +void 1.118 +ImageLayerComposite::ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface) 1.119 +{ 1.120 + gfx::Matrix4x4 local = GetLocalTransform(); 1.121 + 1.122 + // Snap image edges to pixel boundaries 1.123 + gfxRect sourceRect(0, 0, 0, 0); 1.124 + if (mImageHost && 1.125 + mImageHost->IsAttached() && 1.126 + mImageHost->GetAsTextureHost()) { 1.127 + IntSize size = mImageHost->GetAsTextureHost()->GetSize(); 1.128 + sourceRect.SizeTo(size.width, size.height); 1.129 + if (mScaleMode != ScaleMode::SCALE_NONE && 1.130 + sourceRect.width != 0.0 && sourceRect.height != 0.0) { 1.131 + NS_ASSERTION(mScaleMode == ScaleMode::STRETCH, 1.132 + "No other scalemodes than stretch and none supported yet."); 1.133 + local.Scale(mScaleToSize.width / sourceRect.width, 1.134 + mScaleToSize.height / sourceRect.height, 1.0); 1.135 + } 1.136 + } 1.137 + // Snap our local transform first, and snap the inherited transform as well. 1.138 + // This makes our snapping equivalent to what would happen if our content 1.139 + // was drawn into a ThebesLayer (gfxContext would snap using the local 1.140 + // transform, then we'd snap again when compositing the ThebesLayer). 1.141 + mEffectiveTransform = 1.142 + SnapTransform(local, sourceRect, nullptr) * 1.143 + SnapTransformTranslation(aTransformToSurface, nullptr); 1.144 + ComputeEffectiveTransformForMaskLayer(aTransformToSurface); 1.145 +} 1.146 + 1.147 +CompositableHost* 1.148 +ImageLayerComposite::GetCompositableHost() 1.149 +{ 1.150 + if (mImageHost && mImageHost->IsAttached()) { 1.151 + return mImageHost.get(); 1.152 + } 1.153 + 1.154 + return nullptr; 1.155 +} 1.156 + 1.157 +void 1.158 +ImageLayerComposite::CleanupResources() 1.159 +{ 1.160 + if (mImageHost) { 1.161 + mImageHost->Detach(this); 1.162 + } 1.163 + mImageHost = nullptr; 1.164 +} 1.165 + 1.166 +nsACString& 1.167 +ImageLayerComposite::PrintInfo(nsACString& aTo, const char* aPrefix) 1.168 +{ 1.169 + ImageLayer::PrintInfo(aTo, aPrefix); 1.170 + aTo += "\n"; 1.171 + if (mImageHost && mImageHost->IsAttached()) { 1.172 + nsAutoCString pfx(aPrefix); 1.173 + pfx += " "; 1.174 + mImageHost->PrintInfo(aTo, pfx.get()); 1.175 + } 1.176 + return aTo; 1.177 +} 1.178 + 1.179 +} /* layers */ 1.180 +} /* mozilla */