2017-10-27 16:10:06 -07: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-28 15:03:27 -07: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/. */
|
|
|
|
|
|
|
|
#ifndef GFX_WEBRENDERUSERDATA_H
|
|
|
|
#define GFX_WEBRENDERUSERDATA_H
|
|
|
|
|
2017-09-07 15:04:30 +08:00
|
|
|
#include "BasicLayers.h" // for BasicLayerManager
|
2017-06-28 15:03:27 -07:00
|
|
|
#include "mozilla/layers/StackingContextHelper.h"
|
|
|
|
#include "mozilla/webrender/WebRenderAPI.h"
|
2017-07-21 14:21:47 +08:00
|
|
|
#include "mozilla/layers/AnimationInfo.h"
|
2017-06-28 15:03:27 -07:00
|
|
|
|
2017-07-06 00:29:41 +08:00
|
|
|
class nsDisplayItemGeometry;
|
|
|
|
|
2017-06-28 15:03:27 -07:00
|
|
|
namespace mozilla {
|
2017-09-20 10:56:20 +02:00
|
|
|
namespace wr {
|
|
|
|
class IpcResourceUpdateQueue;
|
|
|
|
}
|
|
|
|
|
2017-06-28 15:03:27 -07:00
|
|
|
namespace layers {
|
2017-08-03 13:55:14 +08:00
|
|
|
class CanvasLayer;
|
2017-06-28 15:03:27 -07:00
|
|
|
class ImageClient;
|
|
|
|
class ImageContainer;
|
|
|
|
class WebRenderBridgeChild;
|
2017-08-03 13:55:14 +08:00
|
|
|
class WebRenderCanvasData;
|
|
|
|
class WebRenderCanvasRendererAsync;
|
2017-06-28 15:03:27 -07:00
|
|
|
class WebRenderImageData;
|
2017-07-24 14:43:55 +08:00
|
|
|
class WebRenderFallbackData;
|
2017-06-28 15:03:27 -07:00
|
|
|
class WebRenderLayerManager;
|
|
|
|
|
|
|
|
class WebRenderUserData
|
|
|
|
{
|
|
|
|
public:
|
2017-09-14 14:38:12 +08:00
|
|
|
typedef nsTHashtable<nsRefPtrHashKey<WebRenderUserData> > WebRenderUserDataRefTable;
|
|
|
|
|
2017-06-28 15:03:27 -07:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(WebRenderUserData)
|
|
|
|
|
2017-09-25 15:48:29 +08:00
|
|
|
WebRenderUserData(WebRenderLayerManager* aWRManager, nsDisplayItem* aItem);
|
2017-06-28 15:03:27 -07:00
|
|
|
|
|
|
|
virtual WebRenderImageData* AsImageData() { return nullptr; }
|
2017-07-24 14:43:55 +08:00
|
|
|
virtual WebRenderFallbackData* AsFallbackData() { return nullptr; }
|
2017-08-03 13:55:14 +08:00
|
|
|
virtual WebRenderCanvasData* AsCanvasData() { return nullptr; }
|
2017-06-28 15:03:27 -07:00
|
|
|
|
|
|
|
enum class UserDataType {
|
|
|
|
eImage,
|
2017-07-06 00:29:41 +08:00
|
|
|
eFallback,
|
2017-07-21 14:21:47 +08:00
|
|
|
eAnimation,
|
2017-08-03 13:55:14 +08:00
|
|
|
eCanvas,
|
2017-06-28 15:03:27 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual UserDataType GetType() = 0;
|
2017-08-18 15:21:20 +08:00
|
|
|
bool IsDataValid(WebRenderLayerManager* aManager);
|
2017-09-14 14:38:12 +08:00
|
|
|
bool IsUsed() { return mUsed; }
|
|
|
|
void SetUsed(bool aUsed) { mUsed = aUsed; }
|
|
|
|
nsIFrame* GetFrame() { return mFrame; }
|
|
|
|
uint32_t GetDisplayItemKey() { return mDisplayItemKey; }
|
|
|
|
void RemoveFromTable();
|
2017-10-19 13:03:08 +09:00
|
|
|
virtual void ClearCachedResources() {};
|
2017-12-04 11:12:25 +08:00
|
|
|
virtual nsDisplayItemGeometry* GetGeometry() { return nullptr; }
|
2017-06-28 15:03:27 -07:00
|
|
|
protected:
|
2017-08-03 11:20:53 +08:00
|
|
|
virtual ~WebRenderUserData();
|
2017-06-28 15:03:27 -07:00
|
|
|
|
|
|
|
WebRenderBridgeChild* WrBridge() const;
|
|
|
|
|
2017-08-03 11:20:53 +08:00
|
|
|
RefPtr<WebRenderLayerManager> mWRManager;
|
2017-09-14 14:38:12 +08:00
|
|
|
nsIFrame* mFrame;
|
|
|
|
uint32_t mDisplayItemKey;
|
|
|
|
WebRenderUserDataRefTable* mTable;
|
|
|
|
bool mUsed;
|
2017-06-28 15:03:27 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class WebRenderImageData : public WebRenderUserData
|
|
|
|
{
|
|
|
|
public:
|
2017-09-25 15:48:29 +08:00
|
|
|
explicit WebRenderImageData(WebRenderLayerManager* aWRManager, nsDisplayItem* aItem);
|
2017-06-28 15:03:27 -07:00
|
|
|
virtual ~WebRenderImageData();
|
|
|
|
|
|
|
|
virtual WebRenderImageData* AsImageData() override { return this; }
|
|
|
|
virtual UserDataType GetType() override { return UserDataType::eImage; }
|
|
|
|
static UserDataType Type() { return UserDataType::eImage; }
|
2017-07-06 00:29:41 +08:00
|
|
|
Maybe<wr::ImageKey> GetKey() { return mKey; }
|
2017-11-21 11:49:42 +08:00
|
|
|
void SetKey(const wr::ImageKey& aKey);
|
2017-07-06 00:29:41 +08:00
|
|
|
already_AddRefed<ImageClient> GetImageClient();
|
2017-06-28 15:03:27 -07:00
|
|
|
|
2017-09-20 10:56:20 +02:00
|
|
|
Maybe<wr::ImageKey> UpdateImageKey(ImageContainer* aContainer,
|
|
|
|
wr::IpcResourceUpdateQueue& aResources,
|
2017-11-20 10:36:14 +08:00
|
|
|
bool aFallback = false);
|
2017-06-28 15:03:27 -07:00
|
|
|
|
|
|
|
void CreateAsyncImageWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder,
|
|
|
|
ImageContainer* aContainer,
|
|
|
|
const StackingContextHelper& aSc,
|
2017-10-18 22:25:11 -04:00
|
|
|
const LayoutDeviceRect& aBounds,
|
|
|
|
const LayoutDeviceRect& aSCBounds,
|
2017-06-28 15:03:27 -07:00
|
|
|
const gfx::Matrix4x4& aSCTransform,
|
|
|
|
const gfx::MaybeIntSize& aScaleToSize,
|
2017-07-19 03:28:58 -04:00
|
|
|
const wr::ImageRendering& aFilter,
|
2017-09-21 14:41:38 +08:00
|
|
|
const wr::MixBlendMode& aMixBlendMode,
|
|
|
|
bool aIsBackfaceVisible);
|
2017-06-28 15:03:27 -07:00
|
|
|
|
|
|
|
void CreateImageClientIfNeeded();
|
2017-10-19 13:03:08 +09:00
|
|
|
void ClearCachedResources() override;
|
2017-07-06 00:29:41 +08:00
|
|
|
protected:
|
2017-11-15 14:31:13 -05:00
|
|
|
void ClearImageKey();
|
2017-06-28 15:03:27 -07:00
|
|
|
void CreateExternalImageIfNeeded();
|
|
|
|
|
|
|
|
wr::MaybeExternalImageId mExternalImageId;
|
|
|
|
Maybe<wr::ImageKey> mKey;
|
|
|
|
RefPtr<ImageClient> mImageClient;
|
|
|
|
Maybe<wr::PipelineId> mPipelineId;
|
|
|
|
RefPtr<ImageContainer> mContainer;
|
2017-11-15 14:31:13 -05:00
|
|
|
bool mOwnsKey;
|
2017-06-28 15:03:27 -07:00
|
|
|
};
|
|
|
|
|
2017-07-06 00:29:41 +08:00
|
|
|
class WebRenderFallbackData : public WebRenderImageData
|
|
|
|
{
|
|
|
|
public:
|
2017-09-25 15:48:29 +08:00
|
|
|
explicit WebRenderFallbackData(WebRenderLayerManager* aWRManager, nsDisplayItem* aItem);
|
2017-07-06 00:29:41 +08:00
|
|
|
virtual ~WebRenderFallbackData();
|
|
|
|
|
2017-07-24 14:43:55 +08:00
|
|
|
virtual WebRenderFallbackData* AsFallbackData() override { return this; }
|
2017-07-06 00:29:41 +08:00
|
|
|
virtual UserDataType GetType() override { return UserDataType::eFallback; }
|
|
|
|
static UserDataType Type() { return UserDataType::eFallback; }
|
2017-12-04 11:12:25 +08:00
|
|
|
nsDisplayItemGeometry* GetGeometry() override;
|
2017-07-06 00:29:41 +08:00
|
|
|
void SetGeometry(nsAutoPtr<nsDisplayItemGeometry> aGeometry);
|
|
|
|
nsRect GetBounds() { return mBounds; }
|
|
|
|
void SetBounds(const nsRect& aRect) { mBounds = aRect; }
|
2017-07-24 14:43:55 +08:00
|
|
|
void SetInvalid(bool aInvalid) { mInvalid = aInvalid; }
|
2017-10-06 14:50:33 +08:00
|
|
|
void SetScale(gfx::Size aScale) { mScale = aScale; }
|
|
|
|
gfx::Size GetScale() { return mScale; }
|
2017-07-24 14:43:55 +08:00
|
|
|
bool IsInvalid() { return mInvalid; }
|
2017-07-06 00:29:41 +08:00
|
|
|
|
2017-09-07 15:04:30 +08:00
|
|
|
RefPtr<BasicLayerManager> mBasicLayerManager;
|
2017-07-06 00:29:41 +08:00
|
|
|
protected:
|
|
|
|
nsAutoPtr<nsDisplayItemGeometry> mGeometry;
|
|
|
|
nsRect mBounds;
|
2017-07-24 14:43:55 +08:00
|
|
|
bool mInvalid;
|
2017-10-06 14:50:33 +08:00
|
|
|
gfx::Size mScale;
|
2017-07-06 00:29:41 +08:00
|
|
|
};
|
|
|
|
|
2017-07-21 14:21:47 +08:00
|
|
|
class WebRenderAnimationData : public WebRenderUserData
|
|
|
|
{
|
|
|
|
public:
|
2017-09-25 15:48:29 +08:00
|
|
|
explicit WebRenderAnimationData(WebRenderLayerManager* aWRManager, nsDisplayItem* aItem);
|
2017-09-22 16:39:57 -04:00
|
|
|
virtual ~WebRenderAnimationData();
|
2017-07-21 14:21:47 +08:00
|
|
|
|
|
|
|
virtual UserDataType GetType() override { return UserDataType::eAnimation; }
|
|
|
|
static UserDataType Type() { return UserDataType::eAnimation; }
|
|
|
|
AnimationInfo& GetAnimationInfo() { return mAnimationInfo; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
AnimationInfo mAnimationInfo;
|
|
|
|
};
|
|
|
|
|
2017-08-03 13:55:14 +08:00
|
|
|
class WebRenderCanvasData : public WebRenderUserData
|
|
|
|
{
|
|
|
|
public:
|
2017-09-25 15:48:29 +08:00
|
|
|
explicit WebRenderCanvasData(WebRenderLayerManager* aWRManager, nsDisplayItem* aItem);
|
2017-08-03 13:55:14 +08:00
|
|
|
virtual ~WebRenderCanvasData();
|
|
|
|
|
|
|
|
virtual WebRenderCanvasData* AsCanvasData() override { return this; }
|
|
|
|
virtual UserDataType GetType() override { return UserDataType::eCanvas; }
|
|
|
|
static UserDataType Type() { return UserDataType::eCanvas; }
|
|
|
|
|
2017-10-28 19:07:27 +09:00
|
|
|
void ClearCanvasRenderer();
|
2017-08-03 13:55:14 +08:00
|
|
|
WebRenderCanvasRendererAsync* GetCanvasRenderer();
|
2017-10-28 19:07:27 +09:00
|
|
|
WebRenderCanvasRendererAsync* CreateCanvasRenderer();
|
2017-10-19 13:03:08 +09:00
|
|
|
void ClearCachedResources() override;
|
2017-08-03 13:55:14 +08:00
|
|
|
protected:
|
|
|
|
UniquePtr<WebRenderCanvasRendererAsync> mCanvasRenderer;
|
|
|
|
};
|
|
|
|
|
2017-06-28 15:03:27 -07:00
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* GFX_WEBRENDERUSERDATA_H */
|