2017-01-10 12:17:30 +03: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 13:25:07 +03:00
|
|
|
#include "mozilla/Range.h"
|
2017-01-17 03:22:01 +03:00
|
|
|
#include "mozilla/webrender/webrender_ffi.h"
|
2017-01-17 03:21:52 +03:00
|
|
|
#include "mozilla/webrender/WebRenderTypes.h"
|
2017-01-16 17:22:47 +03:00
|
|
|
#include "Units.h"
|
2017-01-10 12:17:30 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
namespace widget {
|
|
|
|
class CompositorWidget;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace layers {
|
2017-01-17 03:22:09 +03:00
|
|
|
class CompositorBridgeParentBase;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace wr {
|
2017-01-10 12:17:30 +03:00
|
|
|
|
2017-01-13 13:25:07 +03:00
|
|
|
class DisplayListBuilder;
|
2017-01-10 12:17:30 +03:00
|
|
|
class RendererOGL;
|
2017-01-17 22:46:31 +03:00
|
|
|
class RendererEvent;
|
2017-01-10 12:17:30 +03:00
|
|
|
|
|
|
|
class WebRenderAPI
|
|
|
|
{
|
2017-01-25 00:06:17 +03:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(WebRenderAPI);
|
|
|
|
|
2017-01-10 12:17:30 +03:00
|
|
|
public:
|
2017-01-25 00:06:17 +03:00
|
|
|
/// This can be called on the compositor thread only.
|
2017-01-10 12:17:30 +03:00
|
|
|
static already_AddRefed<WebRenderAPI> Create(bool aEnableProfiler,
|
2017-01-17 03:22:09 +03:00
|
|
|
layers::CompositorBridgeParentBase* aBridge,
|
2017-01-10 12:17:30 +03:00
|
|
|
RefPtr<widget::CompositorWidget>&& aWidget);
|
|
|
|
|
2017-01-17 03:22:09 +03:00
|
|
|
wr::WindowId GetId() const { return mId; }
|
2017-01-10 12:17:30 +03:00
|
|
|
|
2017-01-16 17:22:47 +03:00
|
|
|
void SetRootDisplayList(gfx::Color aBgColor,
|
2017-01-17 03:22:09 +03:00
|
|
|
wr::Epoch aEpoch,
|
2017-01-16 17:22:47 +03:00
|
|
|
LayerSize aViewportSize,
|
|
|
|
DisplayListBuilder& aBuilder);
|
|
|
|
|
2017-01-17 03:22:09 +03:00
|
|
|
void SetRootPipeline(wr::PipelineId aPipeline);
|
2017-01-16 17:22:47 +03:00
|
|
|
|
2017-01-17 03:22:09 +03:00
|
|
|
wr::ImageKey AddImageBuffer(gfx::IntSize aSize,
|
|
|
|
uint32_t aStride,
|
|
|
|
gfx::SurfaceFormat aFormat,
|
|
|
|
Range<uint8_t> aBytes);
|
2017-01-16 17:22:47 +03:00
|
|
|
|
2017-01-17 03:22:09 +03:00
|
|
|
wr::ImageKey AddExternalImageHandle(gfx::IntSize aSize,
|
|
|
|
gfx::SurfaceFormat aFormat,
|
|
|
|
uint64_t aHandle);
|
2017-01-16 17:22:47 +03:00
|
|
|
|
2017-01-17 03:22:09 +03:00
|
|
|
void UpdateImageBuffer(wr::ImageKey aKey,
|
2017-01-16 17:22:47 +03:00
|
|
|
gfx::IntSize aSize,
|
|
|
|
gfx::SurfaceFormat aFormat,
|
|
|
|
Range<uint8_t> aBytes);
|
|
|
|
|
2017-01-17 03:22:09 +03:00
|
|
|
void DeleteImage(wr::ImageKey aKey);
|
2017-01-16 17:22:47 +03:00
|
|
|
|
2017-01-17 03:22:09 +03:00
|
|
|
wr::FontKey AddRawFont(Range<uint8_t> aBytes);
|
2017-01-16 17:22:47 +03:00
|
|
|
|
2017-01-17 03:22:09 +03:00
|
|
|
void DeleteFont(wr::FontKey aKey);
|
2017-01-16 17:22:47 +03:00
|
|
|
|
|
|
|
void SetProfilerEnabled(bool aEnabled);
|
|
|
|
|
2017-01-28 00:08:17 +03:00
|
|
|
void RunOnRenderThread(UniquePtr<RendererEvent> aEvent);
|
2017-01-25 07:29:34 +03:00
|
|
|
void Readback(gfx::IntSize aSize, uint8_t *aBuffer, uint32_t aBufferSize);
|
2017-01-17 22:46:31 +03:00
|
|
|
|
2017-01-18 22:50:00 +03:00
|
|
|
GLint GetMaxTextureSize() const { return mMaxTextureSize; }
|
|
|
|
|
2017-01-10 12:17:30 +03:00
|
|
|
protected:
|
2017-01-18 22:50:00 +03:00
|
|
|
WebRenderAPI(WrAPI* aRawApi, wr::WindowId aId, GLint aMaxTextureSize)
|
2017-01-25 00:06:17 +03:00
|
|
|
: mWrApi(aRawApi)
|
|
|
|
, mId(aId)
|
|
|
|
, mMaxTextureSize(aMaxTextureSize)
|
2017-01-10 12:17:30 +03:00
|
|
|
{}
|
|
|
|
|
|
|
|
~WebRenderAPI();
|
|
|
|
|
2017-01-17 22:48:00 +03:00
|
|
|
WrAPI* mWrApi;
|
2017-01-17 03:22:09 +03:00
|
|
|
wr::WindowId mId;
|
2017-01-18 22:50:00 +03:00
|
|
|
GLint mMaxTextureSize;
|
2017-01-11 15:51:27 +03:00
|
|
|
|
2017-01-13 13:25:07 +03:00
|
|
|
friend class DisplayListBuilder;
|
|
|
|
};
|
|
|
|
|
2017-01-17 17:32:25 +03:00
|
|
|
/// This is a simple C++ wrapper around WrState defined in the rust bindings.
|
2017-01-13 13:25:07 +03: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-01-17 03:22:09 +03:00
|
|
|
DisplayListBuilder(const LayerIntSize& aSize, wr::PipelineId aId);
|
2017-01-13 13:25:07 +03:00
|
|
|
DisplayListBuilder(DisplayListBuilder&&) = default;
|
|
|
|
|
|
|
|
~DisplayListBuilder();
|
|
|
|
|
|
|
|
void Begin(const LayerIntSize& aSize);
|
|
|
|
|
2017-01-17 03:22:09 +03:00
|
|
|
void End(WebRenderAPI& aApi, wr::Epoch aEpoch);
|
2017-01-13 13:25:07 +03:00
|
|
|
|
2017-01-17 17:32:16 +03:00
|
|
|
void PushStackingContext(const WrRect& aBounds, // TODO: We should work with strongly typed rects
|
|
|
|
const WrRect& aOverflow,
|
2017-01-17 17:53:57 +03:00
|
|
|
const WrImageMask* aMask, // TODO: needs a wrapper.
|
2017-02-02 10:09:09 +03:00
|
|
|
const float aOpacity,
|
2017-01-20 02:57:18 +03:00
|
|
|
const gfx::Matrix4x4& aTransform,
|
|
|
|
const WrMixBlendMode& aMixBlendMode);
|
2017-01-13 13:25:07 +03:00
|
|
|
|
|
|
|
void PopStackingContext();
|
|
|
|
|
2017-01-17 17:32:16 +03:00
|
|
|
void PushRect(const WrRect& aBounds,
|
|
|
|
const WrRect& aClip,
|
2017-01-13 13:25:07 +03:00
|
|
|
const gfx::Color& aColor);
|
|
|
|
|
2017-01-17 17:32:16 +03:00
|
|
|
void PushImage(const WrRect& aBounds,
|
|
|
|
const WrRect& aClip,
|
2017-01-17 17:53:57 +03:00
|
|
|
const WrImageMask* aMask,
|
|
|
|
const WrTextureFilter aFilter,
|
2017-01-17 22:48:00 +03:00
|
|
|
wr::ImageKey aImage);
|
2017-01-13 13:25:07 +03:00
|
|
|
|
2017-01-17 17:32:16 +03:00
|
|
|
void PushIFrame(const WrRect& aBounds,
|
|
|
|
const WrRect& aClip,
|
2017-01-17 03:22:09 +03:00
|
|
|
wr::PipelineId aPipeline);
|
2017-01-13 13:25:07 +03:00
|
|
|
|
2017-01-17 17:32:16 +03:00
|
|
|
void PushBorder(const WrRect& bounds,
|
|
|
|
const WrRect& clip,
|
2017-01-17 17:53:57 +03:00
|
|
|
const WrBorderSide& top,
|
|
|
|
const WrBorderSide& right,
|
|
|
|
const WrBorderSide& bottom,
|
|
|
|
const WrBorderSide& left,
|
2017-01-17 17:32:20 +03:00
|
|
|
const WrLayoutSize& top_left_radius,
|
|
|
|
const WrLayoutSize& top_right_radius,
|
|
|
|
const WrLayoutSize& bottom_left_radius,
|
|
|
|
const WrLayoutSize& bottom_right_radius);
|
2017-01-13 13:25:07 +03:00
|
|
|
|
2017-01-17 17:32:16 +03:00
|
|
|
void PushText(const WrRect& aBounds,
|
|
|
|
const WrRect& aClip,
|
2017-01-13 13:25:07 +03:00
|
|
|
const gfx::Color& aColor,
|
2017-01-17 03:22:09 +03:00
|
|
|
wr::FontKey aFontKey,
|
2017-01-24 16:44:23 +03:00
|
|
|
Range<const WrGlyphInstance> aGlyphBuffer,
|
2017-01-13 13:25:07 +03:00
|
|
|
float aGlyphSize);
|
|
|
|
|
|
|
|
// Try to avoid using this when possible.
|
2017-01-17 17:32:25 +03:00
|
|
|
WrState* Raw() { return mWrState; }
|
2017-01-13 13:25:07 +03:00
|
|
|
protected:
|
2017-01-17 17:32:25 +03:00
|
|
|
WrState* mWrState;
|
2017-01-16 17:22:47 +03:00
|
|
|
|
|
|
|
friend class WebRenderAPI;
|
2017-01-10 12:17:30 +03:00
|
|
|
};
|
|
|
|
|
2017-01-17 23:13:41 +03:00
|
|
|
Maybe<WrImageFormat>
|
|
|
|
SurfaceFormatToWrImageFormat(gfx::SurfaceFormat aFormat);
|
|
|
|
|
2017-01-25 00:06:17 +03:00
|
|
|
} // namespace wr
|
|
|
|
} // namespace mozilla
|
2017-01-10 12:17:30 +03:00
|
|
|
|
2017-01-24 16:44:23 +03:00
|
|
|
#endif
|