tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

WebRenderCanvasRenderer.cpp (2899B)


      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/. */
      6 
      7 #include "WebRenderCanvasRenderer.h"
      8 
      9 #include "GLContext.h"
     10 #include "GLScreenBuffer.h"
     11 #include "mozilla/layers/CompositorBridgeChild.h"
     12 #include "mozilla/StaticPrefs_webgl.h"
     13 #include "SharedSurfaceGL.h"
     14 #include "WebRenderBridgeChild.h"
     15 
     16 namespace mozilla {
     17 namespace layers {
     18 
     19 CompositableForwarder* WebRenderCanvasRenderer::GetForwarder() {
     20  return mManager->WrBridge();
     21 }
     22 
     23 WebRenderCanvasRendererAsync::~WebRenderCanvasRendererAsync() {
     24  if (mPipelineId.isSome()) {
     25    mManager->RemovePipelineIdForCompositable(mPipelineId.ref());
     26    mPipelineId.reset();
     27  }
     28 }
     29 
     30 void WebRenderCanvasRendererAsync::Initialize(const CanvasRendererData& aData) {
     31  WebRenderCanvasRenderer::Initialize(aData);
     32 
     33  ClearCachedResources();
     34 }
     35 
     36 bool WebRenderCanvasRendererAsync::CreateCompositable() {
     37  if (!mCanvasClient) {
     38    auto compositableFlags = TextureFlags::NO_FLAGS;
     39    if (!mData.mIsAlphaPremult) {
     40      // WR needs this flag marked on the compositable, not just the texture.
     41      compositableFlags |= TextureFlags::NON_PREMULTIPLIED;
     42    }
     43    mCanvasClient = new CanvasClient(GetForwarder(), compositableFlags);
     44    mCanvasClient->Connect();
     45  }
     46  return true;
     47 }
     48 
     49 void WebRenderCanvasRendererAsync::EnsurePipeline() {
     50  MOZ_ASSERT(mCanvasClient);
     51  if (!mCanvasClient) {
     52    return;
     53  }
     54 
     55  if (mPipelineId) {
     56    return;
     57  }
     58 
     59  // Alloc async image pipeline id.
     60  mPipelineId = Some(
     61      mManager->WrBridge()->GetCompositorBridgeChild()->GetNextPipelineId());
     62  mManager->AddPipelineIdForCompositable(
     63      mPipelineId.ref(), mCanvasClient->GetIPCHandle(),
     64      CompositableHandleOwner::WebRenderBridge);
     65 }
     66 
     67 bool WebRenderCanvasRendererAsync::HasPipeline() {
     68  return mPipelineId.isSome();
     69 }
     70 
     71 void WebRenderCanvasRendererAsync::ClearCachedResources() {
     72  if (mPipelineId.isSome()) {
     73    mManager->RemovePipelineIdForCompositable(mPipelineId.ref());
     74    mPipelineId.reset();
     75  }
     76 }
     77 
     78 void WebRenderCanvasRendererAsync::
     79    UpdateCompositableClientForEmptyTransaction() {
     80  bool wasDirty = IsDirty();
     81  UpdateCompositableClient();
     82  if (wasDirty && mPipelineId.isSome()) {
     83    // Notify an update of async image pipeline during empty transaction.
     84    // During non empty transaction, WebRenderBridgeParent receives
     85    // OpUpdateAsyncImagePipeline message, but during empty transaction, the
     86    // message is not sent to WebRenderBridgeParent. Then
     87    // OpUpdatedAsyncImagePipeline is used to notify the update.
     88    mManager->AddWebRenderParentCommand(
     89        OpUpdatedAsyncImagePipeline(mPipelineId.ref()));
     90  }
     91 }
     92 
     93 }  // namespace layers
     94 }  // namespace mozilla