gfx/layers/client/ClientImageLayer.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 2; 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 "ClientLayerManager.h" // for ClientLayerManager, etc
michael@0 7 #include "ImageContainer.h" // for AutoLockImage, etc
michael@0 8 #include "ImageLayers.h" // for ImageLayer
michael@0 9 #include "mozilla/Attributes.h" // for MOZ_OVERRIDE
michael@0 10 #include "mozilla/RefPtr.h" // for RefPtr
michael@0 11 #include "mozilla/layers/CompositorTypes.h"
michael@0 12 #include "mozilla/layers/ImageClient.h" // for ImageClient, etc
michael@0 13 #include "mozilla/layers/LayersMessages.h" // for ImageLayerAttributes, etc
michael@0 14 #include "mozilla/mozalloc.h" // for operator delete, etc
michael@0 15 #include "nsAutoPtr.h" // for nsRefPtr, getter_AddRefs, etc
michael@0 16 #include "nsCOMPtr.h" // for already_AddRefed
michael@0 17 #include "nsDebug.h" // for NS_ASSERTION
michael@0 18 #include "nsISupportsImpl.h" // for Layer::AddRef, etc
michael@0 19 #include "nsRegion.h" // for nsIntRegion
michael@0 20
michael@0 21 using namespace mozilla::gfx;
michael@0 22
michael@0 23 namespace mozilla {
michael@0 24 namespace layers {
michael@0 25
michael@0 26 class ClientImageLayer : public ImageLayer,
michael@0 27 public ClientLayer {
michael@0 28 public:
michael@0 29 ClientImageLayer(ClientLayerManager* aLayerManager)
michael@0 30 : ImageLayer(aLayerManager,
michael@0 31 static_cast<ClientLayer*>(MOZ_THIS_IN_INITIALIZER_LIST()))
michael@0 32 , mImageClientTypeContainer(BUFFER_UNKNOWN)
michael@0 33 {
michael@0 34 MOZ_COUNT_CTOR(ClientImageLayer);
michael@0 35 }
michael@0 36 virtual ~ClientImageLayer()
michael@0 37 {
michael@0 38 DestroyBackBuffer();
michael@0 39 MOZ_COUNT_DTOR(ClientImageLayer);
michael@0 40 }
michael@0 41
michael@0 42 virtual void SetContainer(ImageContainer* aContainer) MOZ_OVERRIDE
michael@0 43 {
michael@0 44 ImageLayer::SetContainer(aContainer);
michael@0 45 mImageClientTypeContainer = BUFFER_UNKNOWN;
michael@0 46 }
michael@0 47
michael@0 48 virtual void SetVisibleRegion(const nsIntRegion& aRegion)
michael@0 49 {
michael@0 50 NS_ASSERTION(ClientManager()->InConstruction(),
michael@0 51 "Can only set properties in construction phase");
michael@0 52 ImageLayer::SetVisibleRegion(aRegion);
michael@0 53 }
michael@0 54
michael@0 55 virtual void RenderLayer();
michael@0 56
michael@0 57 virtual void ClearCachedResources() MOZ_OVERRIDE
michael@0 58 {
michael@0 59 DestroyBackBuffer();
michael@0 60 }
michael@0 61
michael@0 62 virtual void FillSpecificAttributes(SpecificLayerAttributes& aAttrs)
michael@0 63 {
michael@0 64 aAttrs = ImageLayerAttributes(mFilter, mScaleToSize, mScaleMode);
michael@0 65 }
michael@0 66
michael@0 67 virtual Layer* AsLayer() { return this; }
michael@0 68 virtual ShadowableLayer* AsShadowableLayer() { return this; }
michael@0 69
michael@0 70 virtual void Disconnect()
michael@0 71 {
michael@0 72 DestroyBackBuffer();
michael@0 73 ClientLayer::Disconnect();
michael@0 74 }
michael@0 75
michael@0 76 void DestroyBackBuffer()
michael@0 77 {
michael@0 78 if (mImageClient) {
michael@0 79 mImageClient->OnDetach();
michael@0 80 mImageClient = nullptr;
michael@0 81 }
michael@0 82 }
michael@0 83
michael@0 84 virtual CompositableClient* GetCompositableClient() MOZ_OVERRIDE
michael@0 85 {
michael@0 86 return mImageClient;
michael@0 87 }
michael@0 88
michael@0 89 protected:
michael@0 90 ClientLayerManager* ClientManager()
michael@0 91 {
michael@0 92 return static_cast<ClientLayerManager*>(mManager);
michael@0 93 }
michael@0 94
michael@0 95 CompositableType GetImageClientType()
michael@0 96 {
michael@0 97 if (mImageClientTypeContainer != BUFFER_UNKNOWN) {
michael@0 98 return mImageClientTypeContainer;
michael@0 99 }
michael@0 100
michael@0 101 if (mContainer->IsAsync()) {
michael@0 102 mImageClientTypeContainer = BUFFER_BRIDGE;
michael@0 103 return mImageClientTypeContainer;
michael@0 104 }
michael@0 105
michael@0 106 RefPtr<gfx::SourceSurface> surface;
michael@0 107 AutoLockImage autoLock(mContainer, &surface);
michael@0 108
michael@0 109 #ifdef MOZ_WIDGET_GONK
michael@0 110 // gralloc buffer needs BUFFER_IMAGE_BUFFERED to prevent
michael@0 111 // the buffer's usage conflict.
michael@0 112 mImageClientTypeContainer = autoLock.GetImage() ?
michael@0 113 BUFFER_IMAGE_BUFFERED : BUFFER_UNKNOWN;
michael@0 114 #else
michael@0 115 mImageClientTypeContainer = autoLock.GetImage() ?
michael@0 116 BUFFER_IMAGE_SINGLE : BUFFER_UNKNOWN;
michael@0 117 #endif
michael@0 118 return mImageClientTypeContainer;
michael@0 119 }
michael@0 120
michael@0 121 RefPtr<ImageClient> mImageClient;
michael@0 122 CompositableType mImageClientTypeContainer;
michael@0 123 };
michael@0 124
michael@0 125 void
michael@0 126 ClientImageLayer::RenderLayer()
michael@0 127 {
michael@0 128 if (GetMaskLayer()) {
michael@0 129 ToClientLayer(GetMaskLayer())->RenderLayer();
michael@0 130 }
michael@0 131
michael@0 132 if (!mContainer) {
michael@0 133 return;
michael@0 134 }
michael@0 135
michael@0 136 if (mImageClient) {
michael@0 137 mImageClient->OnTransaction();
michael@0 138 }
michael@0 139
michael@0 140 if (!mImageClient ||
michael@0 141 !mImageClient->UpdateImage(mContainer, GetContentFlags())) {
michael@0 142 CompositableType type = GetImageClientType();
michael@0 143 if (type == BUFFER_UNKNOWN) {
michael@0 144 return;
michael@0 145 }
michael@0 146 TextureFlags flags = TEXTURE_FRONT;
michael@0 147 if (mDisallowBigImage) {
michael@0 148 flags |= TEXTURE_DISALLOW_BIGIMAGE;
michael@0 149 }
michael@0 150 mImageClient = ImageClient::CreateImageClient(type,
michael@0 151 ClientManager()->AsShadowForwarder(),
michael@0 152 flags);
michael@0 153 if (type == BUFFER_BRIDGE) {
michael@0 154 static_cast<ImageClientBridge*>(mImageClient.get())->SetLayer(this);
michael@0 155 }
michael@0 156
michael@0 157 if (!mImageClient) {
michael@0 158 return;
michael@0 159 }
michael@0 160 if (HasShadow() && !mContainer->IsAsync()) {
michael@0 161 mImageClient->Connect();
michael@0 162 ClientManager()->AsShadowForwarder()->Attach(mImageClient, this);
michael@0 163 }
michael@0 164 if (!mImageClient->UpdateImage(mContainer, GetContentFlags())) {
michael@0 165 return;
michael@0 166 }
michael@0 167 }
michael@0 168 if (mImageClient) {
michael@0 169 mImageClient->OnTransaction();
michael@0 170 }
michael@0 171 ClientManager()->Hold(this);
michael@0 172 }
michael@0 173
michael@0 174 already_AddRefed<ImageLayer>
michael@0 175 ClientLayerManager::CreateImageLayer()
michael@0 176 {
michael@0 177 NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
michael@0 178 nsRefPtr<ClientImageLayer> layer =
michael@0 179 new ClientImageLayer(this);
michael@0 180 CREATE_SHADOW(Image);
michael@0 181 return layer.forget();
michael@0 182 }
michael@0 183 }
michael@0 184 }

mercurial