2017-01-10 09:17:30 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set sw=2 sts=2 ts=8 et tw=99 : */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#ifndef MOZILLA_LAYERS_WEBRENDERAPI_H
|
|
|
|
#define MOZILLA_LAYERS_WEBRENDERAPI_H
|
|
|
|
|
|
|
|
#include "mozilla/AlreadyAddRefed.h"
|
2017-01-13 10:25:07 +00:00
|
|
|
#include "mozilla/Range.h"
|
2017-01-17 00:22:01 +00:00
|
|
|
#include "mozilla/webrender/webrender_ffi.h"
|
2017-01-17 00:21:52 +00:00
|
|
|
#include "mozilla/webrender/WebRenderTypes.h"
|
2017-03-03 15:45:29 +00:00
|
|
|
#include "GLTypes.h"
|
2017-01-16 14:22:47 +00:00
|
|
|
#include "Units.h"
|
2017-01-10 09:17:30 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
namespace widget {
|
|
|
|
class CompositorWidget;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace layers {
|
2017-01-17 00:22:09 +00:00
|
|
|
class CompositorBridgeParentBase;
|
2017-03-07 10:37:28 +00:00
|
|
|
class WebRenderBridgeParent;
|
2017-01-17 00:22:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace wr {
|
2017-01-10 09:17:30 +00:00
|
|
|
|
2017-01-13 10:25:07 +00:00
|
|
|
class DisplayListBuilder;
|
2017-01-10 09:17:30 +00:00
|
|
|
class RendererOGL;
|
2017-01-17 19:46:31 +00:00
|
|
|
class RendererEvent;
|
2017-01-10 09:17:30 +00:00
|
|
|
|
|
|
|
class WebRenderAPI
|
|
|
|
{
|
2017-01-24 21:06:17 +00:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(WebRenderAPI);
|
|
|
|
|
2017-01-10 09:17:30 +00:00
|
|
|
public:
|
2017-01-24 21:06:17 +00:00
|
|
|
/// This can be called on the compositor thread only.
|
2017-01-10 09:17:30 +00:00
|
|
|
static already_AddRefed<WebRenderAPI> Create(bool aEnableProfiler,
|
2017-01-17 00:22:09 +00:00
|
|
|
layers::CompositorBridgeParentBase* aBridge,
|
2017-03-06 23:46:30 +00:00
|
|
|
RefPtr<widget::CompositorWidget>&& aWidget,
|
|
|
|
LayoutDeviceIntSize aSize);
|
2017-01-10 09:17:30 +00:00
|
|
|
|
2017-01-17 00:22:09 +00:00
|
|
|
wr::WindowId GetId() const { return mId; }
|
2017-02-27 00:27:04 +00:00
|
|
|
|
|
|
|
void GenerateFrame();
|
2017-03-29 09:23:08 +00:00
|
|
|
void GenerateFrame(const nsTArray<WrOpacityProperty>& aOpacityArray,
|
|
|
|
const nsTArray<WrTransformProperty>& aTransformArray);
|
2017-01-10 09:17:30 +00:00
|
|
|
|
2017-03-06 22:41:51 +00:00
|
|
|
void SetWindowParameters(LayoutDeviceIntSize size);
|
2017-01-16 14:22:47 +00:00
|
|
|
void SetRootDisplayList(gfx::Color aBgColor,
|
2017-03-01 14:10:53 +00:00
|
|
|
Epoch aEpoch,
|
2017-01-16 14:22:47 +00:00
|
|
|
LayerSize aViewportSize,
|
2017-03-01 14:10:53 +00:00
|
|
|
WrPipelineId pipeline_id,
|
|
|
|
WrBuiltDisplayListDescriptor dl_descriptor,
|
|
|
|
uint8_t *dl_data,
|
2017-05-08 17:52:16 +00:00
|
|
|
size_t dl_size);
|
2017-01-16 14:22:47 +00:00
|
|
|
|
2017-03-06 01:42:17 +00:00
|
|
|
void ClearRootDisplayList(Epoch aEpoch,
|
|
|
|
WrPipelineId pipeline_id);
|
|
|
|
|
2017-01-17 00:22:09 +00:00
|
|
|
void SetRootPipeline(wr::PipelineId aPipeline);
|
2017-01-16 14:22:47 +00:00
|
|
|
|
2017-02-22 18:19:57 +00:00
|
|
|
void AddImage(wr::ImageKey aKey,
|
|
|
|
const ImageDescriptor& aDescriptor,
|
|
|
|
Range<uint8_t> aBytes);
|
2017-01-16 14:22:47 +00:00
|
|
|
|
2017-03-27 11:44:52 +00:00
|
|
|
void AddBlobImage(wr::ImageKey aKey,
|
|
|
|
const ImageDescriptor& aDescriptor,
|
|
|
|
Range<uint8_t> aBytes);
|
|
|
|
|
2017-03-02 01:22:40 +00:00
|
|
|
void AddExternalImageHandle(ImageKey key,
|
2017-03-31 14:29:14 +00:00
|
|
|
const ImageDescriptor& aDescriptor,
|
2017-04-19 09:59:53 +00:00
|
|
|
ExternalImageId aHandle);
|
2017-03-02 01:22:40 +00:00
|
|
|
|
|
|
|
void AddExternalImageBuffer(ImageKey key,
|
2017-03-09 02:10:09 +00:00
|
|
|
const ImageDescriptor& aDescriptor,
|
2017-04-19 09:59:53 +00:00
|
|
|
ExternalImageId aHandle);
|
2017-01-16 14:22:47 +00:00
|
|
|
|
2017-01-17 00:22:09 +00:00
|
|
|
void UpdateImageBuffer(wr::ImageKey aKey,
|
2017-02-14 18:34:15 +00:00
|
|
|
const ImageDescriptor& aDescriptor,
|
2017-01-16 14:22:47 +00:00
|
|
|
Range<uint8_t> aBytes);
|
|
|
|
|
2017-01-17 00:22:09 +00:00
|
|
|
void DeleteImage(wr::ImageKey aKey);
|
2017-01-16 14:22:47 +00:00
|
|
|
|
2017-04-21 15:50:21 +00:00
|
|
|
void AddRawFont(wr::FontKey aKey, Range<uint8_t> aBytes, uint32_t aIndex);
|
2017-01-16 14:22:47 +00:00
|
|
|
|
2017-01-17 00:22:09 +00:00
|
|
|
void DeleteFont(wr::FontKey aKey);
|
2017-01-16 14:22:47 +00:00
|
|
|
|
|
|
|
void SetProfilerEnabled(bool aEnabled);
|
|
|
|
|
2017-01-27 21:08:17 +00:00
|
|
|
void RunOnRenderThread(UniquePtr<RendererEvent> aEvent);
|
2017-01-25 04:29:34 +00:00
|
|
|
void Readback(gfx::IntSize aSize, uint8_t *aBuffer, uint32_t aBufferSize);
|
2017-01-17 19:46:31 +00:00
|
|
|
|
2017-04-05 14:12:11 +00:00
|
|
|
void Pause();
|
|
|
|
bool Resume();
|
|
|
|
|
2017-02-22 18:19:57 +00:00
|
|
|
WrIdNamespace GetNamespace();
|
2017-01-18 19:50:00 +00:00
|
|
|
GLint GetMaxTextureSize() const { return mMaxTextureSize; }
|
2017-02-23 08:46:56 +00:00
|
|
|
bool GetUseANGLE() const { return mUseANGLE; }
|
2017-01-18 19:50:00 +00:00
|
|
|
|
2017-01-10 09:17:30 +00:00
|
|
|
protected:
|
2017-02-23 08:46:56 +00:00
|
|
|
WebRenderAPI(WrAPI* aRawApi, wr::WindowId aId, GLint aMaxTextureSize, bool aUseANGLE)
|
2017-01-24 21:06:17 +00:00
|
|
|
: mWrApi(aRawApi)
|
|
|
|
, mId(aId)
|
|
|
|
, mMaxTextureSize(aMaxTextureSize)
|
2017-02-23 08:46:56 +00:00
|
|
|
, mUseANGLE(aUseANGLE)
|
2017-01-10 09:17:30 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
~WebRenderAPI();
|
2017-03-07 10:37:28 +00:00
|
|
|
// Should be used only for shutdown handling
|
|
|
|
void WaitFlushed();
|
2017-01-10 09:17:30 +00:00
|
|
|
|
2017-01-17 19:48:00 +00:00
|
|
|
WrAPI* mWrApi;
|
2017-01-17 00:22:09 +00:00
|
|
|
wr::WindowId mId;
|
2017-01-18 19:50:00 +00:00
|
|
|
GLint mMaxTextureSize;
|
2017-02-23 08:46:56 +00:00
|
|
|
bool mUseANGLE;
|
2017-01-11 12:51:27 +00:00
|
|
|
|
2017-01-13 10:25:07 +00:00
|
|
|
friend class DisplayListBuilder;
|
2017-03-07 10:37:28 +00:00
|
|
|
friend class layers::WebRenderBridgeParent;
|
2017-01-13 10:25:07 +00:00
|
|
|
};
|
|
|
|
|
2017-01-17 14:32:25 +00:00
|
|
|
/// This is a simple C++ wrapper around WrState defined in the rust bindings.
|
2017-01-13 10:25:07 +00:00
|
|
|
/// We may want to turn this into a direct wrapper on top of WebRenderFrameBuilder
|
|
|
|
/// instead, so the interface may change a bit.
|
|
|
|
class DisplayListBuilder {
|
|
|
|
public:
|
2017-02-23 21:12:40 +00:00
|
|
|
explicit DisplayListBuilder(wr::PipelineId aId);
|
2017-01-13 10:25:07 +00:00
|
|
|
DisplayListBuilder(DisplayListBuilder&&) = default;
|
|
|
|
|
|
|
|
~DisplayListBuilder();
|
|
|
|
|
|
|
|
void Begin(const LayerIntSize& aSize);
|
|
|
|
|
2017-02-23 21:12:40 +00:00
|
|
|
void End();
|
2017-03-03 15:45:29 +00:00
|
|
|
wr::BuiltDisplayList Finalize();
|
2017-01-13 10:25:07 +00:00
|
|
|
|
2017-01-17 14:32:16 +00:00
|
|
|
void PushStackingContext(const WrRect& aBounds, // TODO: We should work with strongly typed rects
|
2017-02-02 07:09:09 +00:00
|
|
|
const float aOpacity,
|
2017-01-19 23:57:18 +00:00
|
|
|
const gfx::Matrix4x4& aTransform,
|
|
|
|
const WrMixBlendMode& aMixBlendMode);
|
2017-01-13 10:25:07 +00:00
|
|
|
|
2017-03-29 09:23:08 +00:00
|
|
|
void PushStackingContext(const WrRect& aBounds, // TODO: We should work with strongly typed rects
|
|
|
|
const uint64_t& aAnimationId,
|
|
|
|
const float* aOpacity,
|
|
|
|
const gfx::Matrix4x4* aTransform,
|
|
|
|
const WrMixBlendMode& aMixBlendMode);
|
2017-01-13 10:25:07 +00:00
|
|
|
void PopStackingContext();
|
|
|
|
|
2017-04-18 15:09:39 +00:00
|
|
|
void PushClip(const WrRect& aClipRect,
|
|
|
|
const WrImageMask* aMask);
|
|
|
|
void PopClip();
|
|
|
|
|
2017-03-03 15:45:29 +00:00
|
|
|
void PushBuiltDisplayList(wr::BuiltDisplayList dl);
|
|
|
|
|
2017-04-18 15:09:29 +00:00
|
|
|
void PushScrollLayer(const WrRect& aContentRect, // TODO: We should work with strongly typed rects
|
|
|
|
const WrRect& aClipRect,
|
2017-02-14 18:34:15 +00:00
|
|
|
const WrImageMask* aMask); // TODO: needs a wrapper.
|
|
|
|
void PopScrollLayer();
|
|
|
|
|
|
|
|
|
2017-01-17 14:32:16 +00:00
|
|
|
void PushRect(const WrRect& aBounds,
|
2017-05-08 17:52:16 +00:00
|
|
|
const WrClipRegionToken aClip,
|
2017-02-09 08:49:38 +00:00
|
|
|
const WrColor& aColor);
|
2017-01-13 10:25:07 +00:00
|
|
|
|
2017-02-17 00:51:32 +00:00
|
|
|
void PushLinearGradient(const WrRect& aBounds,
|
2017-05-08 17:52:16 +00:00
|
|
|
const WrClipRegionToken aClip,
|
2017-02-17 00:51:32 +00:00
|
|
|
const WrPoint& aStartPoint,
|
|
|
|
const WrPoint& aEndPoint,
|
|
|
|
const nsTArray<WrGradientStop>& aStops,
|
2017-04-12 19:20:52 +00:00
|
|
|
wr::GradientExtendMode aExtendMode,
|
|
|
|
const WrSize aTileSize,
|
|
|
|
const WrSize aTileSpacing);
|
2017-02-17 00:51:32 +00:00
|
|
|
|
|
|
|
void PushRadialGradient(const WrRect& aBounds,
|
2017-05-08 17:52:16 +00:00
|
|
|
const WrClipRegionToken aClip,
|
2017-03-31 23:18:44 +00:00
|
|
|
const WrPoint& aCenter,
|
|
|
|
const WrSize& aRadius,
|
2017-02-17 00:51:32 +00:00
|
|
|
const nsTArray<WrGradientStop>& aStops,
|
2017-04-12 19:20:52 +00:00
|
|
|
wr::GradientExtendMode aExtendMode,
|
|
|
|
const WrSize aTileSize,
|
|
|
|
const WrSize aTileSpacing);
|
2017-02-17 00:51:32 +00:00
|
|
|
|
2017-01-17 14:32:16 +00:00
|
|
|
void PushImage(const WrRect& aBounds,
|
2017-05-08 17:52:16 +00:00
|
|
|
const WrClipRegionToken aClip,
|
2017-02-14 18:34:15 +00:00
|
|
|
wr::ImageRendering aFilter,
|
2017-01-17 19:48:00 +00:00
|
|
|
wr::ImageKey aImage);
|
2017-01-13 10:25:07 +00:00
|
|
|
|
2017-04-07 06:53:16 +00:00
|
|
|
void PushImage(const WrRect& aBounds,
|
2017-05-08 17:52:16 +00:00
|
|
|
const WrClipRegionToken aClip,
|
2017-04-07 06:53:16 +00:00
|
|
|
const WrSize& aStretchSize,
|
|
|
|
const WrSize& aTileSpacing,
|
|
|
|
wr::ImageRendering aFilter,
|
|
|
|
wr::ImageKey aImage);
|
|
|
|
|
2017-04-28 21:00:57 +00:00
|
|
|
void PushYCbCrPlanarImage(const WrRect& aBounds,
|
2017-05-08 17:52:16 +00:00
|
|
|
const WrClipRegionToken aClip,
|
2017-04-28 21:00:57 +00:00
|
|
|
wr::ImageKey aImageChannel0,
|
|
|
|
wr::ImageKey aImageChannel1,
|
|
|
|
wr::ImageKey aImageChannel2,
|
|
|
|
WrYuvColorSpace aColorSpace);
|
|
|
|
|
|
|
|
void PushNV12Image(const WrRect& aBounds,
|
2017-05-08 17:52:16 +00:00
|
|
|
const WrClipRegionToken aClip,
|
2017-04-28 21:00:57 +00:00
|
|
|
wr::ImageKey aImageChannel0,
|
|
|
|
wr::ImageKey aImageChannel1,
|
|
|
|
WrYuvColorSpace aColorSpace);
|
|
|
|
|
2017-01-17 14:32:16 +00:00
|
|
|
void PushIFrame(const WrRect& aBounds,
|
2017-05-08 17:52:16 +00:00
|
|
|
const WrClipRegionToken aClip,
|
2017-01-17 00:22:09 +00:00
|
|
|
wr::PipelineId aPipeline);
|
2017-01-13 10:25:07 +00:00
|
|
|
|
2017-02-09 08:49:37 +00:00
|
|
|
void PushBorder(const WrRect& aBounds,
|
2017-05-08 17:52:16 +00:00
|
|
|
const WrClipRegionToken aClip,
|
2017-03-13 03:46:03 +00:00
|
|
|
const WrBorderWidths& aWidths,
|
2017-02-09 08:49:37 +00:00
|
|
|
const WrBorderSide& aTop,
|
|
|
|
const WrBorderSide& aRight,
|
|
|
|
const WrBorderSide& aBbottom,
|
|
|
|
const WrBorderSide& aLeft,
|
|
|
|
const WrBorderRadius& aRadius);
|
2017-01-13 10:25:07 +00:00
|
|
|
|
2017-03-13 03:46:03 +00:00
|
|
|
void PushBorderImage(const WrRect& aBounds,
|
2017-05-08 17:52:16 +00:00
|
|
|
const WrClipRegionToken aClip,
|
2017-03-13 03:46:03 +00:00
|
|
|
const WrBorderWidths& aWidths,
|
|
|
|
wr::ImageKey aImage,
|
|
|
|
const WrNinePatchDescriptor& aPatch,
|
|
|
|
const WrSideOffsets2Df32& aOutset,
|
|
|
|
const WrRepeatMode& aRepeatHorizontal,
|
|
|
|
const WrRepeatMode& aRepeatVertical);
|
|
|
|
|
2017-04-10 09:27:30 +00:00
|
|
|
void PushBorderGradient(const WrRect& aBounds,
|
2017-05-08 17:52:16 +00:00
|
|
|
const WrClipRegionToken aClip,
|
2017-04-10 09:27:30 +00:00
|
|
|
const WrBorderWidths& aWidths,
|
|
|
|
const WrPoint& aStartPoint,
|
|
|
|
const WrPoint& aEndPoint,
|
|
|
|
const nsTArray<WrGradientStop>& aStops,
|
|
|
|
wr::GradientExtendMode aExtendMode,
|
|
|
|
const WrSideOffsets2Df32& aOutset);
|
|
|
|
|
|
|
|
void PushBorderRadialGradient(const WrRect& aBounds,
|
2017-05-08 17:52:16 +00:00
|
|
|
const WrClipRegionToken aClip,
|
2017-04-10 09:27:30 +00:00
|
|
|
const WrBorderWidths& aWidths,
|
|
|
|
const WrPoint& aCenter,
|
|
|
|
const WrSize& aRadius,
|
|
|
|
const nsTArray<WrGradientStop>& aStops,
|
|
|
|
wr::GradientExtendMode aExtendMode,
|
|
|
|
const WrSideOffsets2Df32& aOutset);
|
|
|
|
|
2017-01-17 14:32:16 +00:00
|
|
|
void PushText(const WrRect& aBounds,
|
2017-05-08 17:52:16 +00:00
|
|
|
const WrClipRegionToken aClip,
|
2017-01-13 10:25:07 +00:00
|
|
|
const gfx::Color& aColor,
|
2017-01-17 00:22:09 +00:00
|
|
|
wr::FontKey aFontKey,
|
2017-01-24 13:44:23 +00:00
|
|
|
Range<const WrGlyphInstance> aGlyphBuffer,
|
2017-01-13 10:25:07 +00:00
|
|
|
float aGlyphSize);
|
|
|
|
|
2017-02-16 18:23:22 +00:00
|
|
|
void PushBoxShadow(const WrRect& aRect,
|
2017-05-08 17:52:16 +00:00
|
|
|
const WrClipRegionToken aClip,
|
2017-02-16 18:23:22 +00:00
|
|
|
const WrRect& aBoxBounds,
|
|
|
|
const WrPoint& aOffset,
|
|
|
|
const WrColor& aColor,
|
|
|
|
const float& aBlurRadius,
|
|
|
|
const float& aSpreadRadius,
|
|
|
|
const float& aBorderRadius,
|
|
|
|
const WrBoxShadowClipMode& aClipMode);
|
|
|
|
|
2017-05-08 17:52:16 +00:00
|
|
|
WrClipRegionToken PushClipRegion(const WrRect& aMain,
|
|
|
|
const WrImageMask* aMask = nullptr);
|
|
|
|
WrClipRegionToken PushClipRegion(const WrRect& aMain,
|
|
|
|
const nsTArray<WrComplexClipRegion>& aComplex,
|
|
|
|
const WrImageMask* aMask = nullptr);
|
2017-03-09 16:54:16 +00:00
|
|
|
|
2017-01-13 10:25:07 +00:00
|
|
|
// Try to avoid using this when possible.
|
2017-01-17 14:32:25 +00:00
|
|
|
WrState* Raw() { return mWrState; }
|
2017-01-13 10:25:07 +00:00
|
|
|
protected:
|
2017-01-17 14:32:25 +00:00
|
|
|
WrState* mWrState;
|
2017-01-16 14:22:47 +00:00
|
|
|
|
|
|
|
friend class WebRenderAPI;
|
2017-01-10 09:17:30 +00:00
|
|
|
};
|
|
|
|
|
2017-01-17 20:13:41 +00:00
|
|
|
Maybe<WrImageFormat>
|
|
|
|
SurfaceFormatToWrImageFormat(gfx::SurfaceFormat aFormat);
|
|
|
|
|
2017-01-24 21:06:17 +00:00
|
|
|
} // namespace wr
|
|
|
|
} // namespace mozilla
|
2017-01-10 09:17:30 +00:00
|
|
|
|
2017-01-24 13:44:23 +00:00
|
|
|
#endif
|