2017-10-28 02:10:06 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2017-06-29 01:03:27 +03:00
|
|
|
* 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/. */
|
|
|
|
|
|
|
|
#include "WebRenderUserData.h"
|
2017-08-03 08:55:13 +03:00
|
|
|
|
|
|
|
#include "mozilla/layers/ImageClient.h"
|
|
|
|
#include "mozilla/layers/WebRenderBridgeChild.h"
|
|
|
|
#include "mozilla/layers/WebRenderLayerManager.h"
|
|
|
|
#include "mozilla/layers/WebRenderMessages.h"
|
2017-09-20 11:56:20 +03:00
|
|
|
#include "mozilla/layers/IpcResourceUpdateQueue.h"
|
2017-10-30 20:10:29 +03:00
|
|
|
#include "mozilla/layers/SharedSurfacesChild.h"
|
2017-07-05 19:29:41 +03:00
|
|
|
#include "nsDisplayListInvalidation.h"
|
2017-08-03 08:55:14 +03:00
|
|
|
#include "WebRenderCanvasRenderer.h"
|
2017-06-29 01:03:27 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2017-09-25 10:48:29 +03:00
|
|
|
WebRenderUserData::WebRenderUserData(WebRenderLayerManager* aWRManager, nsDisplayItem* aItem)
|
2017-08-03 06:20:53 +03:00
|
|
|
: mWRManager(aWRManager)
|
2017-09-14 09:38:12 +03:00
|
|
|
, mFrame(aItem->Frame())
|
|
|
|
, mDisplayItemKey(aItem->GetPerFrameKey())
|
2017-09-25 10:48:29 +03:00
|
|
|
, mTable(aWRManager->GetWebRenderUserDataTable())
|
2017-09-14 09:38:12 +03:00
|
|
|
, mUsed(false)
|
2017-08-03 06:20:53 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
WebRenderUserData::~WebRenderUserData()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-08-18 10:21:20 +03:00
|
|
|
bool
|
|
|
|
WebRenderUserData::IsDataValid(WebRenderLayerManager* aManager)
|
|
|
|
{
|
|
|
|
return aManager == mWRManager;
|
|
|
|
}
|
|
|
|
|
2017-09-14 09:38:12 +03:00
|
|
|
void
|
|
|
|
WebRenderUserData::RemoveFromTable()
|
|
|
|
{
|
|
|
|
mTable->RemoveEntry(this);
|
|
|
|
}
|
|
|
|
|
2017-06-29 01:03:27 +03:00
|
|
|
WebRenderBridgeChild*
|
|
|
|
WebRenderUserData::WrBridge() const
|
|
|
|
{
|
|
|
|
return mWRManager->WrBridge();
|
|
|
|
}
|
|
|
|
|
2017-09-25 10:48:29 +03:00
|
|
|
WebRenderImageData::WebRenderImageData(WebRenderLayerManager* aWRManager, nsDisplayItem* aItem)
|
|
|
|
: WebRenderUserData(aWRManager, aItem)
|
2017-11-15 22:31:13 +03:00
|
|
|
, mOwnsKey(false)
|
2017-06-29 01:03:27 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
WebRenderImageData::~WebRenderImageData()
|
2017-10-19 07:03:08 +03:00
|
|
|
{
|
|
|
|
ClearCachedResources();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-11-15 22:31:13 +03:00
|
|
|
WebRenderImageData::ClearImageKey()
|
2017-06-29 01:03:27 +03:00
|
|
|
{
|
|
|
|
if (mKey) {
|
2017-11-15 22:31:13 +03:00
|
|
|
// If we don't own the key, then the owner is responsible for discarding the
|
|
|
|
// key when appropriate.
|
|
|
|
if (mOwnsKey) {
|
|
|
|
mWRManager->AddImageKeyForDiscard(mKey.value());
|
|
|
|
}
|
2017-10-19 07:03:08 +03:00
|
|
|
mKey.reset();
|
2017-06-29 01:03:27 +03:00
|
|
|
}
|
2017-11-15 22:31:13 +03:00
|
|
|
mOwnsKey = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebRenderImageData::ClearCachedResources()
|
|
|
|
{
|
|
|
|
ClearImageKey();
|
2017-06-29 01:03:27 +03:00
|
|
|
|
|
|
|
if (mExternalImageId) {
|
|
|
|
WrBridge()->DeallocExternalImageId(mExternalImageId.ref());
|
2017-10-19 07:03:08 +03:00
|
|
|
mExternalImageId.reset();
|
2017-06-29 01:03:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mPipelineId) {
|
2017-08-03 08:55:13 +03:00
|
|
|
WrBridge()->RemovePipelineIdForCompositable(mPipelineId.ref());
|
2017-10-19 07:03:08 +03:00
|
|
|
mPipelineId.reset();
|
2017-06-29 01:03:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Maybe<wr::ImageKey>
|
2017-09-20 11:56:20 +03:00
|
|
|
WebRenderImageData::UpdateImageKey(ImageContainer* aContainer,
|
|
|
|
wr::IpcResourceUpdateQueue& aResources,
|
2017-11-20 05:36:14 +03:00
|
|
|
bool aFallback)
|
2017-06-29 01:03:27 +03:00
|
|
|
{
|
2017-10-30 20:10:29 +03:00
|
|
|
MOZ_ASSERT(aContainer);
|
2017-06-29 01:03:27 +03:00
|
|
|
|
2017-08-31 12:30:36 +03:00
|
|
|
if (mContainer != aContainer) {
|
|
|
|
mContainer = aContainer;
|
|
|
|
}
|
|
|
|
|
2017-11-15 22:31:13 +03:00
|
|
|
wr::WrImageKey key;
|
2017-11-20 05:36:14 +03:00
|
|
|
if (!aFallback) {
|
|
|
|
nsresult rv = SharedSurfacesChild::Share(aContainer, mWRManager, aResources, key);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// Ensure that any previously owned keys are released before replacing. We
|
|
|
|
// don't own this key, the surface itself owns it, so that it can be shared
|
|
|
|
// across multiple elements.
|
|
|
|
ClearImageKey();
|
|
|
|
mKey = Some(key);
|
|
|
|
return mKey;
|
|
|
|
}
|
2017-11-15 22:31:13 +03:00
|
|
|
|
2017-11-20 05:36:14 +03:00
|
|
|
if (rv != NS_ERROR_NOT_IMPLEMENTED) {
|
|
|
|
// We should be using the shared surface but somehow sharing it failed.
|
|
|
|
ClearImageKey();
|
|
|
|
return Nothing();
|
|
|
|
}
|
2017-11-15 22:31:13 +03:00
|
|
|
}
|
2017-06-29 01:03:27 +03:00
|
|
|
|
2017-11-15 22:31:13 +03:00
|
|
|
CreateImageClientIfNeeded();
|
|
|
|
CreateExternalImageIfNeeded();
|
2017-06-29 01:03:27 +03:00
|
|
|
|
2017-11-15 22:31:13 +03:00
|
|
|
if (!mImageClient || !mExternalImageId) {
|
|
|
|
return Nothing();
|
|
|
|
}
|
2017-06-29 01:03:27 +03:00
|
|
|
|
2017-11-15 22:31:13 +03:00
|
|
|
MOZ_ASSERT(mImageClient->AsImageClientSingle());
|
2017-10-30 20:10:29 +03:00
|
|
|
|
2017-11-15 22:31:13 +03:00
|
|
|
ImageClientSingle* imageClient = mImageClient->AsImageClientSingle();
|
|
|
|
uint32_t oldCounter = imageClient->GetLastUpdateGenerationCounter();
|
2017-10-30 20:10:29 +03:00
|
|
|
|
2017-11-15 22:31:13 +03:00
|
|
|
bool ret = imageClient->UpdateImage(aContainer, /* unused */0);
|
|
|
|
if (!ret || imageClient->IsEmpty()) {
|
|
|
|
// Delete old key
|
|
|
|
ClearImageKey();
|
|
|
|
return Nothing();
|
|
|
|
}
|
2017-06-29 01:03:27 +03:00
|
|
|
|
2017-11-15 22:31:13 +03:00
|
|
|
// Reuse old key if generation is not updated.
|
2017-11-20 05:36:14 +03:00
|
|
|
if (!aFallback && oldCounter == imageClient->GetLastUpdateGenerationCounter() && mKey) {
|
2017-11-15 22:31:13 +03:00
|
|
|
return mKey;
|
2017-06-29 01:03:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Delete old key, we are generating a new key.
|
2017-09-20 11:56:20 +03:00
|
|
|
// TODO(nical): noooo... we need to reuse image keys.
|
2017-06-29 01:03:27 +03:00
|
|
|
if (mKey) {
|
|
|
|
mWRManager->AddImageKeyForDiscard(mKey.value());
|
|
|
|
}
|
|
|
|
|
2017-11-15 22:31:13 +03:00
|
|
|
key = WrBridge()->GetNextImageKey();
|
2017-09-20 11:56:20 +03:00
|
|
|
aResources.AddExternalImage(mExternalImageId.value(), key);
|
2017-06-29 01:03:27 +03:00
|
|
|
mKey = Some(key);
|
2017-11-15 22:31:13 +03:00
|
|
|
mOwnsKey = true;
|
2017-06-29 01:03:27 +03:00
|
|
|
|
|
|
|
return mKey;
|
|
|
|
}
|
|
|
|
|
2017-07-05 19:29:41 +03:00
|
|
|
already_AddRefed<ImageClient>
|
|
|
|
WebRenderImageData::GetImageClient()
|
|
|
|
{
|
|
|
|
RefPtr<ImageClient> imageClient = mImageClient;
|
|
|
|
return imageClient.forget();
|
|
|
|
}
|
|
|
|
|
2017-06-29 01:03:27 +03:00
|
|
|
void
|
|
|
|
WebRenderImageData::CreateAsyncImageWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder,
|
|
|
|
ImageContainer* aContainer,
|
|
|
|
const StackingContextHelper& aSc,
|
2017-10-19 05:25:11 +03:00
|
|
|
const LayoutDeviceRect& aBounds,
|
|
|
|
const LayoutDeviceRect& aSCBounds,
|
2017-08-03 08:55:13 +03:00
|
|
|
const gfx::Matrix4x4& aSCTransform,
|
|
|
|
const gfx::MaybeIntSize& aScaleToSize,
|
2017-07-19 10:28:58 +03:00
|
|
|
const wr::ImageRendering& aFilter,
|
2017-09-21 09:41:38 +03:00
|
|
|
const wr::MixBlendMode& aMixBlendMode,
|
|
|
|
bool aIsBackfaceVisible)
|
2017-06-29 01:03:27 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aContainer->IsAsync());
|
|
|
|
if (!mPipelineId) {
|
|
|
|
// Alloc async image pipeline id.
|
|
|
|
mPipelineId = Some(WrBridge()->GetCompositorBridgeChild()->GetNextPipelineId());
|
|
|
|
WrBridge()->AddPipelineIdForAsyncCompositable(mPipelineId.ref(),
|
|
|
|
aContainer->GetAsyncContainerHandle());
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(!mImageClient);
|
|
|
|
MOZ_ASSERT(!mExternalImageId);
|
|
|
|
|
|
|
|
// Push IFrame for async image pipeline.
|
|
|
|
//
|
|
|
|
// We don't push a stacking context for this async image pipeline here.
|
|
|
|
// Instead, we do it inside the iframe that hosts the image. As a result,
|
|
|
|
// a bunch of the calculations normally done as part of that stacking
|
|
|
|
// context need to be done manually and pushed over to the parent side,
|
|
|
|
// where it will be done when we build the display list for the iframe.
|
2017-07-25 11:54:36 +03:00
|
|
|
// That happens in AsyncImagePipelineManager.
|
2017-07-19 01:32:46 +03:00
|
|
|
wr::LayoutRect r = aSc.ToRelativeLayoutRect(aBounds);
|
2017-09-21 09:41:38 +03:00
|
|
|
aBuilder.PushIFrame(r, aIsBackfaceVisible, mPipelineId.ref());
|
2017-06-29 01:03:27 +03:00
|
|
|
|
|
|
|
WrBridge()->AddWebRenderParentCommand(OpUpdateAsyncImagePipeline(mPipelineId.value(),
|
|
|
|
aSCBounds,
|
|
|
|
aSCTransform,
|
|
|
|
aScaleToSize,
|
|
|
|
aFilter,
|
|
|
|
aMixBlendMode));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebRenderImageData::CreateImageClientIfNeeded()
|
|
|
|
{
|
|
|
|
if (!mImageClient) {
|
|
|
|
mImageClient = ImageClient::CreateImageClient(CompositableType::IMAGE,
|
|
|
|
WrBridge(),
|
|
|
|
TextureFlags::DEFAULT);
|
|
|
|
if (!mImageClient) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mImageClient->Connect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebRenderImageData::CreateExternalImageIfNeeded()
|
|
|
|
{
|
|
|
|
if (!mExternalImageId) {
|
|
|
|
mExternalImageId = Some(WrBridge()->AllocExternalImageIdForCompositable(mImageClient));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-25 10:48:29 +03:00
|
|
|
WebRenderFallbackData::WebRenderFallbackData(WebRenderLayerManager* aWRManager, nsDisplayItem* aItem)
|
|
|
|
: WebRenderImageData(aWRManager, aItem)
|
2017-07-24 09:43:55 +03:00
|
|
|
, mInvalid(false)
|
2017-07-05 19:29:41 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-07-24 09:43:55 +03:00
|
|
|
WebRenderFallbackData::~WebRenderFallbackData()
|
2017-07-05 19:29:41 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoPtr<nsDisplayItemGeometry>
|
|
|
|
WebRenderFallbackData::GetGeometry()
|
|
|
|
{
|
|
|
|
return mGeometry;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebRenderFallbackData::SetGeometry(nsAutoPtr<nsDisplayItemGeometry> aGeometry)
|
|
|
|
{
|
|
|
|
mGeometry = aGeometry;
|
|
|
|
}
|
|
|
|
|
2017-09-25 10:48:29 +03:00
|
|
|
WebRenderAnimationData::WebRenderAnimationData(WebRenderLayerManager* aWRManager, nsDisplayItem* aItem)
|
|
|
|
: WebRenderUserData(aWRManager, aItem)
|
2017-09-14 09:38:12 +03:00
|
|
|
, mAnimationInfo(aWRManager)
|
2017-07-21 09:21:47 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-09-22 23:39:57 +03:00
|
|
|
WebRenderAnimationData::~WebRenderAnimationData()
|
|
|
|
{
|
|
|
|
// It may be the case that nsDisplayItem that created this WebRenderUserData
|
|
|
|
// gets destroyed without getting a chance to discard the compositor animation
|
|
|
|
// id, so we should do it as part of cleanup here.
|
|
|
|
uint64_t animationId = mAnimationInfo.GetCompositorAnimationsId();
|
|
|
|
// animationId might be 0 if mAnimationInfo never held any active animations.
|
|
|
|
if (animationId) {
|
|
|
|
mWRManager->AddCompositorAnimationsIdForDiscard(animationId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-25 10:48:29 +03:00
|
|
|
WebRenderCanvasData::WebRenderCanvasData(WebRenderLayerManager* aWRManager, nsDisplayItem* aItem)
|
|
|
|
: WebRenderUserData(aWRManager, aItem)
|
2017-08-03 08:55:14 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
WebRenderCanvasData::~WebRenderCanvasData()
|
|
|
|
{
|
2017-10-19 07:03:08 +03:00
|
|
|
ClearCachedResources();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebRenderCanvasData::ClearCachedResources()
|
|
|
|
{
|
|
|
|
if (mCanvasRenderer) {
|
|
|
|
mCanvasRenderer->ClearCachedResources();
|
|
|
|
}
|
2017-08-03 08:55:14 +03:00
|
|
|
}
|
|
|
|
|
2017-10-28 13:07:27 +03:00
|
|
|
void
|
|
|
|
WebRenderCanvasData::ClearCanvasRenderer()
|
|
|
|
{
|
|
|
|
mCanvasRenderer = nullptr;
|
|
|
|
}
|
|
|
|
|
2017-08-03 08:55:14 +03:00
|
|
|
WebRenderCanvasRendererAsync*
|
|
|
|
WebRenderCanvasData::GetCanvasRenderer()
|
|
|
|
{
|
2017-10-28 13:07:27 +03:00
|
|
|
return mCanvasRenderer.get();
|
|
|
|
}
|
2017-08-03 08:55:14 +03:00
|
|
|
|
2017-10-28 13:07:27 +03:00
|
|
|
WebRenderCanvasRendererAsync*
|
|
|
|
WebRenderCanvasData::CreateCanvasRenderer()
|
|
|
|
{
|
|
|
|
mCanvasRenderer = MakeUnique<WebRenderCanvasRendererAsync>(mWRManager);
|
2017-08-03 08:55:14 +03:00
|
|
|
return mCanvasRenderer.get();
|
|
|
|
}
|
|
|
|
|
2017-06-29 01:03:27 +03:00
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|