1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "WebRenderCanvasRenderer.h"
10 #include "GLScreenBuffer.h"
11 #include "mozilla/layers/CompositorBridgeChild.h"
12 #include "SharedSurfaceGL.h"
13 #include "WebRenderBridgeChild.h"
14 #include "RenderRootStateManager.h"
19 CompositableForwarder
* WebRenderCanvasRenderer::GetForwarder() {
20 return mManager
->WrBridge();
23 void WebRenderCanvasRenderer::Initialize(const CanvasInitializeData
& aData
) {
24 ShareableCanvasRenderer::Initialize(aData
);
27 WebRenderCanvasRendererAsync::~WebRenderCanvasRendererAsync() { Destroy(); }
29 void WebRenderCanvasRendererAsync::Initialize(
30 const CanvasInitializeData
& aData
) {
31 WebRenderCanvasRenderer::Initialize(aData
);
33 ClearCachedResources();
36 bool WebRenderCanvasRendererAsync::CreateCompositable() {
38 TextureFlags flags
= TextureFlags::DEFAULT
;
39 if (mOriginPos
== gl::OriginPos::BottomLeft
) {
40 flags
|= TextureFlags::ORIGIN_BOTTOM_LEFT
;
43 if (!mIsAlphaPremultiplied
) {
44 flags
|= TextureFlags::NON_PREMULTIPLIED
;
47 mCanvasClient
= CanvasClient::CreateCanvasClient(GetCanvasClientType(),
48 GetForwarder(), flags
);
53 mCanvasClient
->Connect();
57 // Alloc async image pipeline id.
59 mManager
->WrBridge()->GetCompositorBridgeChild()->GetNextPipelineId());
60 mManager
->AddPipelineIdForCompositable(mPipelineId
.ref(),
61 mCanvasClient
->GetIPCHandle());
67 void WebRenderCanvasRendererAsync::ClearCachedResources() {
68 if (mPipelineId
.isSome()) {
69 mManager
->RemovePipelineIdForCompositable(mPipelineId
.ref());
74 void WebRenderCanvasRendererAsync::Destroy() {
75 if (mPipelineId
.isSome()) {
76 mManager
->RemovePipelineIdForCompositable(mPipelineId
.ref());
81 void WebRenderCanvasRendererAsync::
82 UpdateCompositableClientForEmptyTransaction() {
83 bool wasDirty
= IsDirty();
84 UpdateCompositableClient(mManager
->GetRenderRoot());
85 if (wasDirty
&& mPipelineId
.isSome()) {
86 // Notify an update of async image pipeline during empty transaction.
87 // During non empty transaction, WebRenderBridgeParent receives
88 // OpUpdateAsyncImagePipeline message, but during empty transaction, the
89 // message is not sent to WebRenderBridgeParent. Then
90 // OpUpdatedAsyncImagePipeline is used to notify the update.
91 mManager
->AddWebRenderParentCommand(
92 OpUpdatedAsyncImagePipeline(mPipelineId
.ref()));
97 } // namespace mozilla