2013-05-01 09:03:25 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "ClientLayerManager.h" // for ClientLayerManager, etc
|
|
|
|
#include "ImageContainer.h" // for AutoLockImage, etc
|
|
|
|
#include "ImageLayers.h" // for ImageLayer
|
2015-03-21 19:28:04 +03:00
|
|
|
#include "mozilla/Attributes.h" // for override
|
2015-10-18 08:24:48 +03:00
|
|
|
#include "mozilla/RefPtr.h" // for RefPtr
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "mozilla/layers/CompositorTypes.h"
|
|
|
|
#include "mozilla/layers/ImageClient.h" // for ImageClient, etc
|
2013-09-06 19:41:00 +04:00
|
|
|
#include "mozilla/layers/LayersMessages.h" // for ImageLayerAttributes, etc
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "mozilla/mozalloc.h" // for operator delete, etc
|
|
|
|
#include "nsAutoPtr.h" // for nsRefPtr, getter_AddRefs, etc
|
|
|
|
#include "nsCOMPtr.h" // for already_AddRefed
|
|
|
|
#include "nsDebug.h" // for NS_ASSERTION
|
|
|
|
#include "nsISupportsImpl.h" // for Layer::AddRef, etc
|
|
|
|
#include "nsRegion.h" // for nsIntRegion
|
2013-05-01 09:03:25 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2014-05-22 14:11:45 +04:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2015-01-07 08:39:46 +03:00
|
|
|
class ClientImageLayer : public ImageLayer,
|
2013-05-01 09:03:25 +04:00
|
|
|
public ClientLayer {
|
|
|
|
public:
|
2014-08-20 08:55:14 +04:00
|
|
|
explicit ClientImageLayer(ClientLayerManager* aLayerManager)
|
2015-01-07 08:39:46 +03:00
|
|
|
: ImageLayer(aLayerManager, static_cast<ClientLayer*>(this))
|
2014-11-26 04:00:34 +03:00
|
|
|
, mImageClientTypeContainer(CompositableType::UNKNOWN)
|
2013-05-01 09:03:25 +04:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(ClientImageLayer);
|
|
|
|
}
|
2014-07-15 19:37:45 +04:00
|
|
|
|
|
|
|
protected:
|
2013-05-01 09:03:25 +04:00
|
|
|
virtual ~ClientImageLayer()
|
|
|
|
{
|
|
|
|
DestroyBackBuffer();
|
|
|
|
MOZ_COUNT_DTOR(ClientImageLayer);
|
|
|
|
}
|
2014-07-15 19:37:45 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void SetContainer(ImageContainer* aContainer) override
|
2013-05-01 09:03:25 +04:00
|
|
|
{
|
|
|
|
ImageLayer::SetContainer(aContainer);
|
2014-11-26 04:00:34 +03:00
|
|
|
mImageClientTypeContainer = CompositableType::UNKNOWN;
|
2013-05-01 09:03:25 +04:00
|
|
|
}
|
|
|
|
|
2015-11-29 10:07:55 +03:00
|
|
|
virtual void SetVisibleRegion(const LayerIntRegion& aRegion) override
|
2013-05-01 09:03:25 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(ClientManager()->InConstruction(),
|
|
|
|
"Can only set properties in construction phase");
|
|
|
|
ImageLayer::SetVisibleRegion(aRegion);
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void RenderLayer() override;
|
2013-05-01 09:03:25 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void ClearCachedResources() override
|
2013-05-01 09:03:25 +04:00
|
|
|
{
|
|
|
|
DestroyBackBuffer();
|
|
|
|
}
|
|
|
|
|
2016-04-07 04:44:05 +03:00
|
|
|
virtual void HandleMemoryPressure() override
|
|
|
|
{
|
|
|
|
if (mImageClient) {
|
|
|
|
mImageClient->HandleMemoryPressure();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void FillSpecificAttributes(SpecificLayerAttributes& aAttrs) override
|
2013-05-01 09:03:25 +04:00
|
|
|
{
|
2013-05-10 01:02:50 +04:00
|
|
|
aAttrs = ImageLayerAttributes(mFilter, mScaleToSize, mScaleMode);
|
2013-05-01 09:03:25 +04:00
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual Layer* AsLayer() override { return this; }
|
|
|
|
virtual ShadowableLayer* AsShadowableLayer() override { return this; }
|
2013-05-01 09:03:25 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void Disconnect() override
|
2013-05-01 09:03:25 +04:00
|
|
|
{
|
|
|
|
DestroyBackBuffer();
|
|
|
|
ClientLayer::Disconnect();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DestroyBackBuffer()
|
|
|
|
{
|
2013-07-30 13:59:51 +04:00
|
|
|
if (mImageClient) {
|
2015-03-25 12:02:04 +03:00
|
|
|
mImageClient->SetLayer(nullptr);
|
2013-08-08 16:53:12 +04:00
|
|
|
mImageClient->OnDetach();
|
2013-07-30 13:59:51 +04:00
|
|
|
mImageClient = nullptr;
|
|
|
|
}
|
2013-05-01 09:03:25 +04:00
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual CompositableClient* GetCompositableClient() override
|
2013-05-01 09:03:25 +04:00
|
|
|
{
|
|
|
|
return mImageClient;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
ClientLayerManager* ClientManager()
|
|
|
|
{
|
|
|
|
return static_cast<ClientLayerManager*>(mManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
CompositableType GetImageClientType()
|
|
|
|
{
|
2014-11-26 04:00:34 +03:00
|
|
|
if (mImageClientTypeContainer != CompositableType::UNKNOWN) {
|
2013-05-01 09:03:25 +04:00
|
|
|
return mImageClientTypeContainer;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mContainer->IsAsync()) {
|
2014-11-20 21:49:51 +03:00
|
|
|
mImageClientTypeContainer = CompositableType::IMAGE_BRIDGE;
|
2014-10-03 13:25:07 +04:00
|
|
|
return mImageClientTypeContainer;
|
|
|
|
}
|
|
|
|
|
2014-06-21 16:15:41 +04:00
|
|
|
AutoLockImage autoLock(mContainer);
|
2013-05-01 09:03:25 +04:00
|
|
|
|
2015-03-27 02:07:53 +03:00
|
|
|
mImageClientTypeContainer = autoLock.HasImage()
|
|
|
|
? CompositableType::IMAGE : CompositableType::UNKNOWN;
|
2013-05-01 09:03:25 +04:00
|
|
|
return mImageClientTypeContainer;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ImageClient> mImageClient;
|
2013-05-01 09:03:25 +04:00
|
|
|
CompositableType mImageClientTypeContainer;
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
ClientImageLayer::RenderLayer()
|
|
|
|
{
|
2015-06-21 19:27:31 +03:00
|
|
|
RenderMaskLayers(this);
|
2013-05-01 09:03:25 +04:00
|
|
|
|
|
|
|
if (!mContainer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mImageClient ||
|
|
|
|
!mImageClient->UpdateImage(mContainer, GetContentFlags())) {
|
2013-05-10 01:02:49 +04:00
|
|
|
CompositableType type = GetImageClientType();
|
2014-11-26 04:00:34 +03:00
|
|
|
if (type == CompositableType::UNKNOWN) {
|
2013-05-10 01:02:49 +04:00
|
|
|
return;
|
|
|
|
}
|
2014-11-25 22:19:04 +03:00
|
|
|
TextureFlags flags = TextureFlags::DEFAULT;
|
2013-08-20 03:39:56 +04:00
|
|
|
if (mDisallowBigImage) {
|
2014-04-26 06:34:05 +04:00
|
|
|
flags |= TextureFlags::DISALLOW_BIGIMAGE;
|
2013-08-20 03:39:56 +04:00
|
|
|
}
|
2013-05-10 01:02:49 +04:00
|
|
|
mImageClient = ImageClient::CreateImageClient(type,
|
2013-11-27 19:19:34 +04:00
|
|
|
ClientManager()->AsShadowForwarder(),
|
2013-08-20 03:39:56 +04:00
|
|
|
flags);
|
2013-05-01 09:03:25 +04:00
|
|
|
if (!mImageClient) {
|
|
|
|
return;
|
|
|
|
}
|
2015-03-25 12:02:04 +03:00
|
|
|
mImageClient->SetLayer(this);
|
2013-05-01 09:03:25 +04:00
|
|
|
if (HasShadow() && !mContainer->IsAsync()) {
|
|
|
|
mImageClient->Connect();
|
2013-11-27 19:19:34 +04:00
|
|
|
ClientManager()->AsShadowForwarder()->Attach(mImageClient, this);
|
2013-05-01 09:03:25 +04:00
|
|
|
}
|
|
|
|
if (!mImageClient->UpdateImage(mContainer, GetContentFlags())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ClientManager()->Hold(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<ImageLayer>
|
|
|
|
ClientLayerManager::CreateImageLayer()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ClientImageLayer> layer =
|
2013-05-01 09:03:25 +04:00
|
|
|
new ClientImageLayer(this);
|
|
|
|
CREATE_SHADOW(Image);
|
|
|
|
return layer.forget();
|
|
|
|
}
|
2015-01-07 08:39:46 +03:00
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|