gfx/layers/composite/ImageLayerComposite.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "ImageLayerComposite.h"
michael@0 7 #include "CompositableHost.h" // for CompositableHost
michael@0 8 #include "Layers.h" // for WriteSnapshotToDumpFile, etc
michael@0 9 #include "gfx2DGlue.h" // for ToFilter, ToMatrix4x4
michael@0 10 #include "gfxRect.h" // for gfxRect
michael@0 11 #include "gfxUtils.h" // for gfxUtils, etc
michael@0 12 #include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
michael@0 13 #include "mozilla/gfx/Matrix.h" // for Matrix4x4
michael@0 14 #include "mozilla/gfx/Point.h" // for IntSize, Point
michael@0 15 #include "mozilla/gfx/Rect.h" // for Rect
michael@0 16 #include "mozilla/layers/Compositor.h" // for Compositor
michael@0 17 #include "mozilla/layers/Effects.h" // for EffectChain
michael@0 18 #include "mozilla/layers/TextureHost.h" // for TextureHost, etc
michael@0 19 #include "mozilla/mozalloc.h" // for operator delete
michael@0 20 #include "nsAString.h"
michael@0 21 #include "nsAutoPtr.h" // for nsRefPtr
michael@0 22 #include "nsDebug.h" // for NS_ASSERTION
michael@0 23 #include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc
michael@0 24 #include "nsPoint.h" // for nsIntPoint
michael@0 25 #include "nsRect.h" // for nsIntRect
michael@0 26 #include "nsString.h" // for nsAutoCString
michael@0 27
michael@0 28 using namespace mozilla::gfx;
michael@0 29
michael@0 30 namespace mozilla {
michael@0 31 namespace layers {
michael@0 32
michael@0 33 ImageLayerComposite::ImageLayerComposite(LayerManagerComposite* aManager)
michael@0 34 : ImageLayer(aManager, nullptr)
michael@0 35 , LayerComposite(aManager)
michael@0 36 , mImageHost(nullptr)
michael@0 37 {
michael@0 38 MOZ_COUNT_CTOR(ImageLayerComposite);
michael@0 39 mImplData = static_cast<LayerComposite*>(this);
michael@0 40 }
michael@0 41
michael@0 42 ImageLayerComposite::~ImageLayerComposite()
michael@0 43 {
michael@0 44 MOZ_COUNT_DTOR(ImageLayerComposite);
michael@0 45 MOZ_ASSERT(mDestroyed);
michael@0 46
michael@0 47 CleanupResources();
michael@0 48 }
michael@0 49
michael@0 50 bool
michael@0 51 ImageLayerComposite::SetCompositableHost(CompositableHost* aHost)
michael@0 52 {
michael@0 53 switch (aHost->GetType()) {
michael@0 54 case BUFFER_IMAGE_SINGLE:
michael@0 55 case BUFFER_IMAGE_BUFFERED:
michael@0 56 case COMPOSITABLE_IMAGE:
michael@0 57 mImageHost = aHost;
michael@0 58 return true;
michael@0 59 default:
michael@0 60 return false;
michael@0 61 }
michael@0 62 }
michael@0 63
michael@0 64 void
michael@0 65 ImageLayerComposite::Disconnect()
michael@0 66 {
michael@0 67 Destroy();
michael@0 68 }
michael@0 69
michael@0 70 LayerRenderState
michael@0 71 ImageLayerComposite::GetRenderState()
michael@0 72 {
michael@0 73 if (mImageHost && mImageHost->IsAttached()) {
michael@0 74 return mImageHost->GetRenderState();
michael@0 75 }
michael@0 76 return LayerRenderState();
michael@0 77 }
michael@0 78
michael@0 79 Layer*
michael@0 80 ImageLayerComposite::GetLayer()
michael@0 81 {
michael@0 82 return this;
michael@0 83 }
michael@0 84
michael@0 85 void
michael@0 86 ImageLayerComposite::RenderLayer(const nsIntRect& aClipRect)
michael@0 87 {
michael@0 88 if (!mImageHost || !mImageHost->IsAttached()) {
michael@0 89 return;
michael@0 90 }
michael@0 91
michael@0 92 #ifdef MOZ_DUMP_PAINTING
michael@0 93 if (gfxUtils::sDumpPainting) {
michael@0 94 RefPtr<gfx::DataSourceSurface> surf = mImageHost->GetAsSurface();
michael@0 95 WriteSnapshotToDumpFile(this, surf);
michael@0 96 }
michael@0 97 #endif
michael@0 98
michael@0 99 mCompositor->MakeCurrent();
michael@0 100
michael@0 101 EffectChain effectChain(this);
michael@0 102 LayerManagerComposite::AutoAddMaskEffect autoMaskEffect(mMaskLayer, effectChain);
michael@0 103
michael@0 104 gfx::Rect clipRect(aClipRect.x, aClipRect.y, aClipRect.width, aClipRect.height);
michael@0 105 mImageHost->SetCompositor(mCompositor);
michael@0 106 mImageHost->Composite(effectChain,
michael@0 107 GetEffectiveOpacity(),
michael@0 108 GetEffectiveTransform(),
michael@0 109 gfx::ToFilter(mFilter),
michael@0 110 clipRect);
michael@0 111 mImageHost->BumpFlashCounter();
michael@0 112 }
michael@0 113
michael@0 114 void
michael@0 115 ImageLayerComposite::ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface)
michael@0 116 {
michael@0 117 gfx::Matrix4x4 local = GetLocalTransform();
michael@0 118
michael@0 119 // Snap image edges to pixel boundaries
michael@0 120 gfxRect sourceRect(0, 0, 0, 0);
michael@0 121 if (mImageHost &&
michael@0 122 mImageHost->IsAttached() &&
michael@0 123 mImageHost->GetAsTextureHost()) {
michael@0 124 IntSize size = mImageHost->GetAsTextureHost()->GetSize();
michael@0 125 sourceRect.SizeTo(size.width, size.height);
michael@0 126 if (mScaleMode != ScaleMode::SCALE_NONE &&
michael@0 127 sourceRect.width != 0.0 && sourceRect.height != 0.0) {
michael@0 128 NS_ASSERTION(mScaleMode == ScaleMode::STRETCH,
michael@0 129 "No other scalemodes than stretch and none supported yet.");
michael@0 130 local.Scale(mScaleToSize.width / sourceRect.width,
michael@0 131 mScaleToSize.height / sourceRect.height, 1.0);
michael@0 132 }
michael@0 133 }
michael@0 134 // Snap our local transform first, and snap the inherited transform as well.
michael@0 135 // This makes our snapping equivalent to what would happen if our content
michael@0 136 // was drawn into a ThebesLayer (gfxContext would snap using the local
michael@0 137 // transform, then we'd snap again when compositing the ThebesLayer).
michael@0 138 mEffectiveTransform =
michael@0 139 SnapTransform(local, sourceRect, nullptr) *
michael@0 140 SnapTransformTranslation(aTransformToSurface, nullptr);
michael@0 141 ComputeEffectiveTransformForMaskLayer(aTransformToSurface);
michael@0 142 }
michael@0 143
michael@0 144 CompositableHost*
michael@0 145 ImageLayerComposite::GetCompositableHost()
michael@0 146 {
michael@0 147 if (mImageHost && mImageHost->IsAttached()) {
michael@0 148 return mImageHost.get();
michael@0 149 }
michael@0 150
michael@0 151 return nullptr;
michael@0 152 }
michael@0 153
michael@0 154 void
michael@0 155 ImageLayerComposite::CleanupResources()
michael@0 156 {
michael@0 157 if (mImageHost) {
michael@0 158 mImageHost->Detach(this);
michael@0 159 }
michael@0 160 mImageHost = nullptr;
michael@0 161 }
michael@0 162
michael@0 163 nsACString&
michael@0 164 ImageLayerComposite::PrintInfo(nsACString& aTo, const char* aPrefix)
michael@0 165 {
michael@0 166 ImageLayer::PrintInfo(aTo, aPrefix);
michael@0 167 aTo += "\n";
michael@0 168 if (mImageHost && mImageHost->IsAttached()) {
michael@0 169 nsAutoCString pfx(aPrefix);
michael@0 170 pfx += " ";
michael@0 171 mImageHost->PrintInfo(aTo, pfx.get());
michael@0 172 }
michael@0 173 return aTo;
michael@0 174 }
michael@0 175
michael@0 176 } /* layers */
michael@0 177 } /* mozilla */

mercurial