tor-browser

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

NativeLayerRootRemoteMacChild.h (4526B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #ifndef mozilla_layers_NativeLayerRootRemoteMacChild_h
      7 #define mozilla_layers_NativeLayerRootRemoteMacChild_h
      8 
      9 #include "mozilla/layers/NativeLayerCommandQueue.h"
     10 #include "mozilla/layers/NativeLayerRemoteChild.h"
     11 #include "mozilla/layers/NativeLayerRemoteMac.h"
     12 
     13 namespace mozilla {
     14 namespace layers {
     15 
     16 // NativeLayerRootRemoteMacChild is a macOS-specific implementation of
     17 // NativeLayerRoot that runs on the GPU process, and sends updates
     18 // to the parent process.
     19 class NativeLayerRootRemoteMacChild final : public NativeLayerRoot {
     20 public:
     21  NativeLayerRootRemoteMacChild();
     22 
     23  already_AddRefed<NativeLayer> CreateLayer(
     24      const gfx::IntSize& aSize, bool aIsOpaque,
     25      SurfacePoolHandle* aSurfacePoolHandle) override;
     26  already_AddRefed<NativeLayer> CreateLayerForExternalTexture(
     27      bool aIsOpaque) override;
     28  already_AddRefed<NativeLayer> CreateLayerForColor(
     29      gfx::DeviceColor aColor) override;
     30 
     31  void AppendLayer(NativeLayer* aLayer) override;
     32  void RemoveLayer(NativeLayer* aLayer) override;
     33  void SetLayers(const nsTArray<RefPtr<NativeLayer>>& aLayers) override;
     34  UniquePtr<NativeLayerRootSnapshotter> CreateSnapshotter() override;
     35 
     36  // Called before any layer content changes.
     37  void PrepareForCommit() override;
     38 
     39  // Publish the layer changes to the screen. Returns whether the commit was
     40  // successful.
     41  bool CommitToScreen() override;
     42 
     43  // Send a sync message to the parent to make sure it has seen our layer
     44  // commands message.
     45  void WaitUntilCommitToScreenHasBeenProcessed() override;
     46 
     47  RefPtr<NativeLayerRemoteChild> GetRemoteChild() { return mRemoteChild; }
     48 
     49 protected:
     50  friend class NativeLayerRootRemoteMacSnapshotter;
     51 
     52  virtual ~NativeLayerRootRemoteMacChild();
     53 
     54  void CommitForSnapshot(CALayer* aRootCALayer);
     55  void OnNativeLayerRootSnapshotterDestroyed(
     56      NativeLayerRootSnapshotterCA* aNativeLayerRootSnapshotter);
     57 
     58  // An implementation of SnapshotterCADelegate, backed by a
     59  // NativeLayerRootRemoteMacChild.
     60  struct SnapshotterDelegate final : public SnapshotterCADelegate {
     61    explicit SnapshotterDelegate(NativeLayerRootRemoteMacChild* aLayerRoot);
     62    virtual ~SnapshotterDelegate() override;
     63    virtual void UpdateSnapshotterLayers(CALayer* aRootCALayer) override {
     64      mLayerRoot->CommitForSnapshot(aRootCALayer);
     65    }
     66    virtual bool DoCustomReadbackForReftestsIfDesired(
     67        const gfx::IntSize& aReadbackSize, gfx::SurfaceFormat aReadbackFormat,
     68        const Range<uint8_t>& aReadbackBuffer) override {
     69      return mLayerRoot->ReadbackPixelsFromParent(
     70          aReadbackSize, aReadbackFormat, aReadbackBuffer);
     71    }
     72    virtual void OnSnapshotterDestroyed(
     73        NativeLayerRootSnapshotterCA* aSnapshotter) override {
     74      mLayerRoot->OnNativeLayerRootSnapshotterDestroyed(aSnapshotter);
     75    }
     76    RefPtr<NativeLayerRootRemoteMacChild> mLayerRoot;
     77  };
     78 
     79  RefPtr<NativeLayerRemoteChild> mRemoteChild;
     80  RefPtr<NativeLayerCommandQueue> mCommandQueue;
     81  nsTArray<RefPtr<NativeLayerRemoteMac>> mNativeLayers;
     82  NativeLayerRootSnapshotterCA* mWeakSnapshotter = nullptr;
     83 
     84  bool mNativeLayersChanged = false;
     85  bool mNativeLayersChangedForSnapshot = false;
     86 
     87  // Send a sync message to the parent to get the window pixels.
     88  // Used for reftests.
     89  //
     90  // This is different from what we do for "window recorder" and
     91  // "profiler screenshot" snapshotting, where we do the snapshotting
     92  // within the GPU process, using CARenderer on a CALayer tree we
     93  // construct within the GPU process.
     94  //
     95  // Here's why we have two different snapshotting paths:
     96  // - Profiler screenshots and window recording care about minimal overhead
     97  //   and need to minimize blocking on the GPU.
     98  // - Reftests care about catching bugs, and don't need maximum performance.
     99  //   By doing the readback in the parent, we can catch more bugs, for
    100  //   example bugs in the IPC serialization of layer updates and how those
    101  //   updates are applied on the parent side.
    102  bool ReadbackPixelsFromParent(const gfx::IntSize& aSize,
    103                                gfx::SurfaceFormat aFormat,
    104                                const Range<uint8_t>& aBuffer);
    105 };
    106 
    107 }  // namespace layers
    108 }  // namespace mozilla
    109 
    110 #endif  // mozilla_layers_NativeLayerRootRemoteMacChild_h