Bug 1632310 [wpt PR 23186] - Add test for computed versus resolved style., a=testonly
[gecko.git] / gfx / layers / wr / WebRenderCanvasRenderer.cpp
blob8acdef7103190a9468d1fba19475c675d28ff9a3
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"
9 #include "GLContext.h"
10 #include "GLScreenBuffer.h"
11 #include "mozilla/layers/CompositorBridgeChild.h"
12 #include "SharedSurfaceGL.h"
13 #include "WebRenderBridgeChild.h"
14 #include "RenderRootStateManager.h"
16 namespace mozilla {
17 namespace layers {
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() {
37 if (!mCanvasClient) {
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);
49 if (!mCanvasClient) {
50 return false;
53 mCanvasClient->Connect();
56 if (!mPipelineId) {
57 // Alloc async image pipeline id.
58 mPipelineId = Some(
59 mManager->WrBridge()->GetCompositorBridgeChild()->GetNextPipelineId());
60 mManager->AddPipelineIdForCompositable(mPipelineId.ref(),
61 mCanvasClient->GetIPCHandle());
64 return true;
67 void WebRenderCanvasRendererAsync::ClearCachedResources() {
68 if (mPipelineId.isSome()) {
69 mManager->RemovePipelineIdForCompositable(mPipelineId.ref());
70 mPipelineId.reset();
74 void WebRenderCanvasRendererAsync::Destroy() {
75 if (mPipelineId.isSome()) {
76 mManager->RemovePipelineIdForCompositable(mPipelineId.ref());
77 mPipelineId.reset();
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()));
96 } // namespace layers
97 } // namespace mozilla