tor-browser

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

RenderCompositorSWGL.h (2944B)


      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 #ifndef MOZILLA_GFX_RENDERCOMPOSITOR_SWGL_H
      8 #define MOZILLA_GFX_RENDERCOMPOSITOR_SWGL_H
      9 
     10 #include "mozilla/gfx/2D.h"
     11 #include "mozilla/webrender/RenderCompositor.h"
     12 
     13 namespace mozilla {
     14 
     15 namespace wr {
     16 
     17 class RenderCompositorSWGL : public RenderCompositor {
     18 public:
     19  static UniquePtr<RenderCompositor> Create(
     20      const RefPtr<widget::CompositorWidget>& aWidget, nsACString& aError);
     21 
     22  RenderCompositorSWGL(const RefPtr<widget::CompositorWidget>& aWidget,
     23                       void* aContext);
     24  virtual ~RenderCompositorSWGL();
     25 
     26  void* swgl() const override { return mContext; }
     27 
     28  bool MakeCurrent() override;
     29 
     30  bool BeginFrame() override;
     31  void CancelFrame() override;
     32  RenderedFrameId EndFrame(const nsTArray<DeviceIntRect>& aDirtyRects) final;
     33 
     34  void StartCompositing(wr::ColorF aClearColor,
     35                        const wr::DeviceIntRect* aDirtyRects,
     36                        size_t aNumDirtyRects,
     37                        const wr::DeviceIntRect* aOpaqueRects,
     38                        size_t aNumOpaqueRects) override;
     39 
     40  bool UsePartialPresent() override { return true; }
     41  bool RequestFullRender() override;
     42 
     43  void Pause() override;
     44  bool Resume() override;
     45 
     46  layers::WebRenderBackend BackendType() const override {
     47    return layers::WebRenderBackend::SOFTWARE;
     48  }
     49  layers::WebRenderCompositor CompositorType() const override {
     50    return layers::WebRenderCompositor::SOFTWARE;
     51  }
     52 
     53  bool SurfaceOriginIsTopLeft() override { return true; }
     54 
     55  LayoutDeviceIntSize GetBufferSize() override;
     56 
     57  bool SupportsExternalBufferTextures() const override { return true; }
     58 
     59  // Interface for wr::Compositor
     60  void GetCompositorCapabilities(CompositorCapabilities* aCaps) override;
     61 
     62 private:
     63  void* mContext = nullptr;
     64  RefPtr<gfx::DrawTarget> mDT;
     65  LayoutDeviceIntRegion mDirtyRegion;
     66  // Keep consistent buffer size between BeginFrame and EndFrame/CancelFrame
     67  // calls to make sure we don't change buffer size during rendering.
     68  Maybe<LayoutDeviceIntSize> mRenderWidgetSize;
     69  RefPtr<gfx::DataSourceSurface> mSurface;
     70  uint8_t* mMappedData = nullptr;
     71  int32_t mMappedStride = 0;
     72 #ifdef MOZ_WIDGET_GTK
     73  // On Wayland we need to request full render if widget size is changed
     74  // because SW rendering backend reallocates and clears target surface.
     75  LayoutDeviceIntSize mLastRenderWidgetSize;
     76  bool mRequestFullRender = false;
     77 #endif
     78 
     79  void ClearMappedBuffer();
     80 
     81  bool AllocateMappedBuffer(const wr::DeviceIntRect* aOpaqueRects,
     82                            size_t aNumOpaqueRects);
     83 
     84  void CommitMappedBuffer(bool aDirty = true);
     85 };
     86 
     87 }  // namespace wr
     88 }  // namespace mozilla
     89 
     90 #endif