tor-browser

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

CanvasTranslator.h (21004B)


      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 https://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef mozilla_layers_CanvasTranslator_h
      8 #define mozilla_layers_CanvasTranslator_h
      9 
     10 #include <deque>
     11 #include <map>
     12 #include <memory>
     13 #include <unordered_map>
     14 
     15 #include "mozilla/dom/ipc/IdType.h"
     16 #include "mozilla/gfx/InlineTranslator.h"
     17 #include "mozilla/gfx/RecordedEvent.h"
     18 #include "CanvasChild.h"
     19 #include "mozilla/ipc/SharedMemoryHandle.h"
     20 #include "mozilla/layers/CanvasDrawEventRecorder.h"
     21 #include "mozilla/layers/LayersSurfaces.h"
     22 #include "mozilla/layers/PCanvasParent.h"
     23 #include "mozilla/layers/RemoteTextureMap.h"
     24 #include "mozilla/ipc/CrossProcessSemaphore.h"
     25 #include "mozilla/ipc/SharedMemoryMapping.h"
     26 #include "mozilla/Monitor.h"
     27 #include "mozilla/UniquePtr.h"
     28 #include "mozilla/Variant.h"
     29 #include "mozilla/WeakPtr.h"
     30 
     31 namespace mozilla {
     32 
     33 using EventType = gfx::RecordedEvent::EventType;
     34 
     35 class WebGLContext;
     36 
     37 namespace gl {
     38 class SharedSurface;
     39 }  // namespace gl
     40 
     41 namespace gfx {
     42 class DataSourceSurfaceWrapper;
     43 class DrawTargetWebgl;
     44 class SharedContextWebgl;
     45 }  // namespace gfx
     46 
     47 namespace layers {
     48 
     49 class SharedSurfacesHolder;
     50 class TextureData;
     51 class TextureHost;
     52 
     53 class CanvasTranslator final : public gfx::InlineTranslator,
     54                               public PCanvasParent {
     55 public:
     56  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CanvasTranslator)
     57 
     58  friend class PProtocolParent;
     59 
     60  CanvasTranslator(layers::SharedSurfacesHolder* aSharedSurfacesHolder,
     61                   const dom::ContentParentId& aContentId, uint32_t aManagerId);
     62 
     63  const dom::ContentParentId& GetContentId() const { return mContentId; }
     64 
     65  uint32_t GetManagerId() const { return mManagerId; }
     66 
     67  /**
     68   * Dispatches a runnable to the preferred task queue or thread.
     69   *
     70   * @param aRunnable the runnable to dispatch
     71   */
     72  void DispatchToTaskQueue(already_AddRefed<nsIRunnable> aRunnable);
     73 
     74  /**
     75   * @returns true if running in the preferred task queue or thread for
     76   * translation.
     77   */
     78  bool IsInTaskQueue() const;
     79 
     80  /**
     81   * Initialize the canvas translator for a particular TextureType and
     82   * CanvasEventRingBuffer.
     83   *
     84   * @param aTextureType the TextureType the translator will create
     85   * @param aWebglTextureType the TextureType of any WebGL buffers
     86   * @param aBackendType the BackendType for texture data
     87   * @param aHeaderHandle handle for the control header
     88   * @param aBufferHandles handles for the initial buffers for translation
     89   * @param aBufferSize size of buffers and the default size
     90   * @param aReaderSem reading blocked semaphore for the CanvasEventRingBuffer
     91   * @param aWriterSem writing blocked semaphore for the CanvasEventRingBuffer
     92   */
     93  ipc::IPCResult RecvInitTranslator(
     94      TextureType aTextureType, TextureType aWebglTextureType,
     95      gfx::BackendType aBackendType,
     96      ipc::MutableSharedMemoryHandle&& aReadHandle,
     97      nsTArray<ipc::ReadOnlySharedMemoryHandle>&& aBufferHandles,
     98      CrossProcessSemaphoreHandle&& aReaderSem,
     99      CrossProcessSemaphoreHandle&& aWriterSem);
    100 
    101  /**
    102   * Restart the translation from a Stopped state.
    103   */
    104  ipc::IPCResult RecvRestartTranslation();
    105 
    106  /**
    107   * Adds a new buffer to be translated. The current buffer will be recycled if
    108   * it is of the default size. The translation will then be restarted.
    109   */
    110  ipc::IPCResult RecvAddBuffer(ipc::ReadOnlySharedMemoryHandle&& aBufferHandle);
    111 
    112  /**
    113   * Sets the shared memory to be used for readback.
    114   */
    115  ipc::IPCResult RecvSetDataSurfaceBuffer(
    116      uint32_t aId, ipc::MutableSharedMemoryHandle&& aBufferHandle);
    117 
    118  ipc::IPCResult RecvClearCachedResources();
    119 
    120  ipc::IPCResult RecvDropFreeBuffersWhenDormant();
    121 
    122  void ActorDestroy(ActorDestroyReason why) final;
    123 
    124  void CheckAndSignalWriter();
    125 
    126  /**
    127   * Translates events until no more are available or the end of a transaction
    128   * If this returns false the caller of this is responsible for re-calling
    129   * this function.
    130   * @returns true if next HandleCanvasTranslatorEvents() needs to call
    131   * TranslateRecording().
    132   */
    133  bool TranslateRecording();
    134 
    135  /**
    136   * Marks the beginning of rendering for a transaction. While in a transaction
    137   * the translator will wait for a short time for events before returning.
    138   * When not in a transaction the translator will only translate one event at a
    139   * time.
    140   */
    141  void BeginTransaction();
    142 
    143  /**
    144   * Marks the end of a transaction.
    145   */
    146  void EndTransaction();
    147 
    148  /**
    149   * Flushes canvas drawing, for example to a device.
    150   */
    151  void Flush();
    152 
    153  /**
    154   * Marks that device reset processing in the writing process has finished.
    155   */
    156  void DeviceResetAcknowledged();
    157 
    158  /**
    159   * Used during playback of events to create DrawTargets. For the
    160   * CanvasTranslator this means creating TextureDatas and getting the
    161   * DrawTargets from those.
    162   *
    163   * @param aRefPtr the key to store the created DrawTarget against
    164   * @param aTextureOwnerId texture owner ID for this DrawTarget
    165   * @param aSize the size of the DrawTarget
    166   * @param aFormat the surface format for the DrawTarget
    167   * @returns the new DrawTarget
    168   */
    169  already_AddRefed<gfx::DrawTarget> CreateDrawTarget(
    170      gfx::ReferencePtr aRefPtr, RemoteTextureOwnerId aTextureOwnerId,
    171      const gfx::IntSize& aSize, gfx::SurfaceFormat aFormat);
    172 
    173  already_AddRefed<gfx::DrawTarget> CreateDrawTarget(
    174      gfx::ReferencePtr aRefPtr, const gfx::IntSize& aSize,
    175      gfx::SurfaceFormat aFormat) final;
    176 
    177  already_AddRefed<gfx::GradientStops> GetOrCreateGradientStops(
    178      gfx::DrawTarget* aDrawTarget, gfx::GradientStop* aRawStops,
    179      uint32_t aNumStops, gfx::ExtendMode aExtendMode) final;
    180 
    181  void CheckpointReached();
    182 
    183  void PauseTranslation();
    184 
    185  /**
    186   * Wait for a given sync-id to be encountered before resume translation.
    187   */
    188  void AwaitTranslationSync(uint64_t aSyncId);
    189 
    190  /**
    191   * Signal that translation should resume if waiting on the given sync-id.
    192   */
    193  void SyncTranslation(uint64_t aSyncId);
    194 
    195  /**
    196   * Snapshot an external canvas and label it for later lookup under a sync-id.
    197   */
    198  mozilla::ipc::IPCResult RecvSnapshotExternalCanvas(uint64_t aSyncId,
    199                                                     uint32_t aManagerId,
    200                                                     ActorId aCanvasId);
    201 
    202  /**
    203   * Resolves the given sync-id from the recording stream to a snapshot from
    204   * an external canvas that was received from an IPDL message.
    205   */
    206  bool ResolveExternalSnapshot(uint64_t aSyncId, gfx::ReferencePtr aRefPtr,
    207                               const gfx::IntSize& aSize,
    208                               gfx::SurfaceFormat aFormat,
    209                               gfx::DrawTarget* aDT);
    210 
    211  /**
    212   * Removes the texture and other objects associated with a texture ID.
    213   *
    214   * @param aTextureOwnerId the texture ID to remove
    215   */
    216  void RemoveTexture(const RemoteTextureOwnerId aTextureOwnerId,
    217                     RemoteTextureTxnType aTxnType, RemoteTextureTxnId aTxnId,
    218                     bool aFinalize = true);
    219 
    220  bool LockTexture(const RemoteTextureOwnerId aTextureOwnerId, OpenMode aMode,
    221                   bool aInvalidContents = false);
    222  bool UnlockTexture(const RemoteTextureOwnerId aTextureOwnerId);
    223 
    224  bool PresentTexture(const RemoteTextureOwnerId aTextureOwnerId,
    225                      RemoteTextureId aId);
    226 
    227  bool PushRemoteTexture(const RemoteTextureOwnerId aTextureOwnerId,
    228                         TextureData* aData, RemoteTextureId aId,
    229                         RemoteTextureOwnerId aOwnerId);
    230 
    231  /**
    232   * Overriden to remove any DataSourceSurfaces associated with the RefPtr.
    233   *
    234   * @param aRefPtr the key to the surface
    235   * @param aSurface the surface to store
    236   */
    237  void AddSourceSurface(gfx::ReferencePtr aRefPtr,
    238                        gfx::SourceSurface* aSurface) final {
    239    RemoveDataSurface(aRefPtr);
    240    InlineTranslator::AddSourceSurface(aRefPtr, aSurface);
    241  }
    242 
    243  /**
    244   * Removes the SourceSurface and other objects associated with a SourceSurface
    245   * from another process.
    246   *
    247   * @param aRefPtr the key to the objects to remove
    248   */
    249  void RemoveSourceSurface(gfx::ReferencePtr aRefPtr) final {
    250    InlineTranslator::RemoveSourceSurface(aRefPtr);
    251    RemoveDataSurface(aRefPtr);
    252  }
    253 
    254  already_AddRefed<gfx::SourceSurface> LookupExternalSurface(
    255      uint64_t aKey) final;
    256 
    257  already_AddRefed<gfx::SourceSurface> LookupSourceSurfaceFromSurfaceDescriptor(
    258      const SurfaceDescriptor& aDesc) final;
    259 
    260  /**
    261   * Gets the cached DataSourceSurface, if it exists, associated with a
    262   * SourceSurface from another process.
    263   *
    264   * @param aRefPtr the key used to find the DataSourceSurface
    265   * @returns the DataSourceSurface or nullptr if not found
    266   */
    267  gfx::DataSourceSurface* LookupDataSurface(gfx::ReferencePtr aRefPtr);
    268 
    269  /**
    270   * Used to cache the DataSourceSurface from a SourceSurface associated with a
    271   * SourceSurface from another process. This is to improve performance if we
    272   * require the data for that SourceSurface.
    273   *
    274   * @param aRefPtr the key used to store the DataSourceSurface
    275   * @param aSurface the DataSourceSurface to store
    276   */
    277  void AddDataSurface(gfx::ReferencePtr aRefPtr,
    278                      RefPtr<gfx::DataSourceSurface>&& aSurface);
    279 
    280  /**
    281   * Gets the cached DataSourceSurface, if it exists, associated with a
    282   * SourceSurface from another process.
    283   *
    284   * @param aRefPtr the key used to find the DataSourceSurface
    285   * @returns the DataSourceSurface or nullptr if not found
    286   */
    287  void RemoveDataSurface(gfx::ReferencePtr aRefPtr);
    288 
    289  void PrepareShmem(const RemoteTextureOwnerId aTextureOwnerId);
    290 
    291  void RecycleBuffer();
    292 
    293  void NextBuffer();
    294 
    295  void GetDataSurface(uint32_t aId, uint64_t aSurfaceRef);
    296 
    297  /**
    298   * Wait for a canvas to produce the designated surface. If necessary,
    299   * this may flush out canvas commands to ensure the surface is created.
    300   * This should only be called from within the canvas task queue thread
    301   * so that it can force event processing to occur if necessary.
    302   */
    303  already_AddRefed<gfx::SourceSurface> WaitForSurface(
    304      uintptr_t aId, Maybe<layers::SurfaceDescriptor>* aDesc = nullptr);
    305 
    306  static void Shutdown();
    307 
    308  struct ExportSurface {
    309    RefPtr<gfx::SourceSurface> mData;
    310    std::shared_ptr<gl::SharedSurface> mSharedSurface;
    311  };
    312 
    313  void AddExportSurface(gfx::ReferencePtr aRefPtr,
    314                        gfx::SourceSurface* aSurface) {
    315    mExportSurfaces[aRefPtr].mData = aSurface;
    316  }
    317 
    318  void RemoveExportSurface(gfx::ReferencePtr aRefPtr);
    319 
    320  ExportSurface* LookupExportSurface(gfx::ReferencePtr aRefPtr) {
    321    auto it = mExportSurfaces.find(aRefPtr);
    322    return it != mExportSurfaces.end() ? &it->second : nullptr;
    323  }
    324 
    325 private:
    326  ~CanvasTranslator();
    327 
    328  class CanvasTranslatorEvent {
    329   public:
    330    enum class Tag {
    331      TranslateRecording,
    332      AddBuffer,
    333      SetDataSurfaceBuffer,
    334      ClearCachedResources,
    335      DropFreeBuffersWhenDormant,
    336    };
    337    const Tag mTag;
    338 
    339   private:
    340    Variant<ipc::ReadOnlySharedMemoryHandle, ipc::MutableSharedMemoryHandle>
    341        mBufferHandle;
    342 
    343   public:
    344    explicit CanvasTranslatorEvent(const Tag aTag)
    345        : mTag(aTag), mBufferHandle(ipc::ReadOnlySharedMemoryHandle()) {
    346      MOZ_ASSERT(mTag == Tag::TranslateRecording ||
    347                 mTag == Tag::ClearCachedResources ||
    348                 mTag == Tag::DropFreeBuffersWhenDormant);
    349    }
    350    CanvasTranslatorEvent(const Tag aTag,
    351                          ipc::ReadOnlySharedMemoryHandle&& aBufferHandle)
    352        : mTag(aTag), mBufferHandle(std::move(aBufferHandle)) {
    353      MOZ_ASSERT(mTag == Tag::AddBuffer);
    354    }
    355    CanvasTranslatorEvent(const Tag aTag,
    356                          ipc::MutableSharedMemoryHandle&& aBufferHandle,
    357                          uint32_t aId = 0)
    358        : mTag(aTag), mBufferHandle(std::move(aBufferHandle)), mId(aId) {
    359      MOZ_ASSERT(mTag == Tag::SetDataSurfaceBuffer);
    360    }
    361 
    362    static UniquePtr<CanvasTranslatorEvent> TranslateRecording() {
    363      return MakeUnique<CanvasTranslatorEvent>(Tag::TranslateRecording);
    364    }
    365 
    366    static UniquePtr<CanvasTranslatorEvent> AddBuffer(
    367        ipc::ReadOnlySharedMemoryHandle&& aBufferHandle) {
    368      return MakeUnique<CanvasTranslatorEvent>(Tag::AddBuffer,
    369                                               std::move(aBufferHandle));
    370    }
    371 
    372    static UniquePtr<CanvasTranslatorEvent> SetDataSurfaceBuffer(
    373        uint32_t aId, ipc::MutableSharedMemoryHandle&& aBufferHandle) {
    374      return MakeUnique<CanvasTranslatorEvent>(Tag::SetDataSurfaceBuffer,
    375                                               std::move(aBufferHandle), aId);
    376    }
    377 
    378    static UniquePtr<CanvasTranslatorEvent> ClearCachedResources() {
    379      return MakeUnique<CanvasTranslatorEvent>(Tag::ClearCachedResources);
    380    }
    381 
    382    static UniquePtr<CanvasTranslatorEvent> DropFreeBuffersWhenDormant() {
    383      return MakeUnique<CanvasTranslatorEvent>(Tag::DropFreeBuffersWhenDormant);
    384    }
    385 
    386    ipc::ReadOnlySharedMemoryHandle TakeBufferHandle() {
    387      if (mTag == Tag::AddBuffer) {
    388        return std::move(mBufferHandle).as<ipc::ReadOnlySharedMemoryHandle>();
    389      }
    390      MOZ_ASSERT_UNREACHABLE("unexpected to be called");
    391      return nullptr;
    392    }
    393 
    394    ipc::MutableSharedMemoryHandle TakeDataSurfaceBufferHandle() {
    395      if (mTag == Tag::SetDataSurfaceBuffer) {
    396        return std::move(mBufferHandle).as<ipc::MutableSharedMemoryHandle>();
    397      }
    398      MOZ_ASSERT_UNREACHABLE("unexpected to be called");
    399      return nullptr;
    400    }
    401 
    402    uint32_t mId = 0;
    403  };
    404 
    405  /*
    406   * @returns true if next HandleCanvasTranslatorEvents() needs to call
    407   * TranslateRecording().
    408   */
    409  bool AddBuffer(ipc::ReadOnlySharedMemoryHandle&& aBufferHandle);
    410 
    411  /*
    412   * @returns true if next HandleCanvasTranslatorEvents() needs to call
    413   * TranslateRecording().
    414   */
    415  bool SetDataSurfaceBuffer(uint32_t aId,
    416                            ipc::MutableSharedMemoryHandle&& aBufferHandle);
    417 
    418  void UnlinkDataSurfaceShmemOwner(
    419      const RefPtr<gfx::DataSourceSurface>& aSurface);
    420 
    421  void DataSurfaceBufferWillChange(uint32_t aId = 0, bool aKeepAlive = true,
    422                                   size_t aLimit = 0);
    423 
    424  bool ReadNextEvent(EventType& aEventType);
    425 
    426  bool HasPendingEvent();
    427 
    428  bool ReadPendingEvent(EventType& aEventType);
    429 
    430  void Deactivate();
    431 
    432  bool TryDrawTargetWebglFallback(const RemoteTextureOwnerId aTextureOwnerId,
    433                                  gfx::DrawTargetWebgl* aWebgl);
    434  void ForceDrawTargetWebglFallback();
    435 
    436  void BlockCanvas();
    437 
    438  UniquePtr<TextureData> CreateTextureData(const gfx::IntSize& aSize,
    439                                           gfx::SurfaceFormat aFormat,
    440                                           bool aClear);
    441 
    442  void EnsureRemoteTextureOwner(
    443      RemoteTextureOwnerId aOwnerId = RemoteTextureOwnerId());
    444 
    445  UniquePtr<TextureData> CreateOrRecycleTextureData(const gfx::IntSize& aSize,
    446                                                    gfx::SurfaceFormat aFormat);
    447 
    448  already_AddRefed<gfx::DrawTarget> CreateFallbackDrawTarget(
    449      gfx::ReferencePtr aRefPtr, RemoteTextureOwnerId aTextureOwnerId,
    450      const gfx::IntSize& aSize, gfx::SurfaceFormat aFormat);
    451 
    452  void ClearTextureInfo();
    453 
    454  bool HandleExtensionEvent(int32_t aType);
    455 
    456  bool CreateReferenceTexture();
    457 
    458  void NotifyDeviceReset(const RemoteTextureOwnerIdSet& aIds);
    459  bool EnsureSharedContextWebgl();
    460  gfx::DrawTargetWebgl* GetDrawTargetWebgl(
    461      const RemoteTextureOwnerId aTextureOwnerId,
    462      bool aCheckForFallback = true) const;
    463  void NotifyRequiresRefresh(const RemoteTextureOwnerId aTextureOwnerId,
    464                             bool aDispatch = true);
    465  void CacheSnapshotShmem(const RemoteTextureOwnerId aTextureOwnerId,
    466                          bool aDispatch = true);
    467 
    468  void CacheDataSnapshots();
    469 
    470  void ClearCachedResources();
    471 
    472  void DropFreeBuffersWhenDormant();
    473 
    474  already_AddRefed<gfx::DataSourceSurface>
    475  MaybeRecycleDataSurfaceForSurfaceDescriptor(
    476      TextureHost* aTextureHost,
    477      const SurfaceDescriptorRemoteDecoder& aSurfaceDescriptor);
    478 
    479  bool UsePendingCanvasTranslatorEvents();
    480  void PostCanvasTranslatorEvents(const MutexAutoLock& aProofOfLock);
    481  void HandleCanvasTranslatorEvents();
    482 
    483  void NotifyTextureDestruction(const RemoteTextureOwnerId aTextureOwnerId);
    484 
    485  const RefPtr<SharedSurfacesHolder> mSharedSurfacesHolder;
    486  static StaticRefPtr<gfx::SharedContextWebgl> sSharedContext;
    487  RefPtr<gfx::SharedContextWebgl> mSharedContext;
    488  RefPtr<RemoteTextureOwnerClient> mRemoteTextureOwner;
    489 
    490  size_t mDefaultBufferSize = 0;
    491  uint32_t mMaxSpinCount;
    492  TimeDuration mNextEventTimeout;
    493 
    494  using State = CanvasDrawEventRecorder::State;
    495  using Header = CanvasDrawEventRecorder::Header;
    496 
    497  ipc::SharedMemoryMapping mHeaderShmem;
    498  Header* mHeader = nullptr;
    499  // Limit event processing to stop at the designated checkpoint, rather than
    500  // proceed beyond it. This also forces processing to continue, even when it
    501  // would normally have been interrupted, so long as not error is produced and
    502  // so long as the checkpoint has not yet been reached.
    503  int64_t mFlushCheckpoint = 0;
    504 
    505  // The sync-id that the translator is awaiting and must be encountered before
    506  // it is ready to resume translation.
    507  uint64_t mAwaitSyncId = 0;
    508  // The last sync-id that was actually encountered.
    509  uint64_t mLastSyncId = 0;
    510  // A table of external canvas snapshots associated with a given sync-id.
    511  struct ExternalSnapshot {
    512    std::shared_ptr<gl::SharedSurface> mSharedSurface;
    513    WeakPtr<WebGLContext> mWebgl;
    514    Maybe<layers::SurfaceDescriptor> mDescriptor;
    515    RefPtr<gfx::SourceSurface> mData;
    516  };
    517  // Surface decriptors, if available, associated with a given sync-id.
    518  std::unordered_map<uint64_t, ExternalSnapshot> mExternalSnapshots;
    519 
    520  // Signal that translation should pause because it is still awaiting a sync-id
    521  // that has not been encountered yet.
    522  bool PauseUntilSync() const { return mAwaitSyncId > mLastSyncId; }
    523 
    524  struct CanvasShmem {
    525    ipc::ReadOnlySharedMemoryMapping shmem;
    526    bool IsValid() const { return shmem.IsValid(); }
    527    auto Size() { return shmem ? shmem.Size() : 0; }
    528    gfx::MemReader CreateMemReader() {
    529      if (!shmem) {
    530        return {nullptr, 0};
    531      }
    532      return {shmem.DataAs<char>(), Size()};
    533    }
    534  };
    535  std::queue<CanvasShmem> mCanvasShmems;
    536  CanvasShmem mCurrentShmem;
    537  gfx::MemReader mCurrentMemReader{0, 0};
    538  // Track any data surfaces pointing to a shmem mapping.
    539  struct DataSurfaceShmem {
    540    ipc::SharedMemoryMapping mShmem;
    541    ThreadSafeWeakPtr<gfx::DataSourceSurface> mOwner;
    542  };
    543  std::map<uint32_t, DataSurfaceShmem> mDataSurfaceShmems;
    544  // The last shmem id that was assigned to a mapping.
    545  uint32_t mLastDataSurfaceShmemId = 0;
    546  UniquePtr<CrossProcessSemaphore> mWriterSemaphore;
    547  UniquePtr<CrossProcessSemaphore> mReaderSemaphore;
    548  TextureType mTextureType = TextureType::Unknown;
    549  TextureType mWebglTextureType = TextureType::Unknown;
    550  UniquePtr<TextureData> mReferenceTextureData;
    551  dom::ContentParentId mContentId;
    552  uint32_t mManagerId;
    553  // Sometimes during device reset our reference DrawTarget can be null, so we
    554  // hold the BackendType separately.
    555  gfx::BackendType mBackendType = gfx::BackendType::NONE;
    556  base::ProcessId mOtherPid = base::kInvalidProcessId;
    557  struct TextureInfo {
    558    gfx::ReferencePtr mRefPtr;
    559    UniquePtr<TextureData> mTextureData;
    560    RefPtr<gfx::DrawTarget> mDrawTarget;
    561    RefPtr<gfx::DrawTarget> mFallbackDrawTarget;
    562    bool mNotifiedRequiresRefresh = false;
    563    // Ref-count of how active uses of the DT. Avoids deletion when locked.
    564    int32_t mKeepAlive = 1;
    565    OpenMode mTextureLockMode = OpenMode::OPEN_NONE;
    566 
    567    gfx::DrawTargetWebgl* GetDrawTargetWebgl(
    568        bool aCheckForFallback = true) const;
    569  };
    570  std::unordered_map<RemoteTextureOwnerId, TextureInfo,
    571                     RemoteTextureOwnerId::HashFn>
    572      mTextureInfo;
    573 
    574  void AddTextureKeepAlive(const RemoteTextureOwnerId& aId);
    575  void RemoveTextureKeepAlive(const RemoteTextureOwnerId& aId);
    576 
    577  nsRefPtrHashtable<nsPtrHashKey<void>, gfx::DataSourceSurface> mDataSurfaces;
    578  Atomic<bool> mDeactivated{false};
    579  Atomic<bool> mBlocked{false};
    580  Atomic<bool> mIPDLClosed{false};
    581  bool mIsInTransaction = false;
    582 
    583  RefPtr<gfx::DataSourceSurface> mUsedDataSurfaceForSurfaceDescriptor;
    584  RefPtr<gfx::DataSourceSurfaceWrapper> mUsedWrapperForSurfaceDescriptor;
    585  Maybe<SurfaceDescriptorRemoteDecoder>
    586      mUsedSurfaceDescriptorForSurfaceDescriptor;
    587 
    588  Mutex mCanvasTranslatorEventsLock;
    589  RefPtr<nsIRunnable> mCanvasTranslatorEventsRunnable;
    590  std::deque<UniquePtr<CanvasTranslatorEvent>> mPendingCanvasTranslatorEvents;
    591 
    592  std::unordered_map<gfx::ReferencePtr, ExportSurface> mExportSurfaces;
    593 
    594  gfx::UserDataKey mDataSurfaceShmemIdKey = {0};
    595 };
    596 
    597 }  // namespace layers
    598 }  // namespace mozilla
    599 
    600 #endif  // mozilla_layers_CanvasTranslator_h