tor-browser

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

RenderCompositorOGLSWGL.h (3485B)


      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_OGL_SWGL_H
      8 #define MOZILLA_GFX_RENDERCOMPOSITOR_OGL_SWGL_H
      9 
     10 #include "mozilla/layers/Compositor.h"
     11 #include "mozilla/webrender/RenderCompositorLayersSWGL.h"
     12 
     13 namespace mozilla {
     14 
     15 namespace layers {
     16 class TextureImageTextureSourceOGL;
     17 }
     18 
     19 namespace wr {
     20 
     21 class RenderCompositorOGLSWGL : public RenderCompositorLayersSWGL {
     22 public:
     23  static UniquePtr<RenderCompositor> Create(
     24      const RefPtr<widget::CompositorWidget>& aWidget, nsACString& aError);
     25 
     26  RenderCompositorOGLSWGL(layers::Compositor* aCompositor,
     27                          const RefPtr<widget::CompositorWidget>& aWidget,
     28                          void* aContext);
     29  virtual ~RenderCompositorOGLSWGL();
     30 
     31  gl::GLContext* GetGLContext();
     32 
     33  bool MakeCurrent() override;
     34 
     35  bool BeginFrame() override;
     36  RenderedFrameId EndFrame(const nsTArray<DeviceIntRect>& aDirtyRects) override;
     37 
     38  void GetCompositorCapabilities(CompositorCapabilities* aCaps) override;
     39 
     40  // Returns true for requesting rendering during readback.
     41  // RenderCompositorOGLSWGL::MaybeReadback() requests rendering.
     42  // This value is not used by WebRender, since native compositor API is used
     43  // for sw-wr.
     44  bool UsePartialPresent() override { return true; }
     45  bool RequestFullRender() override;
     46 
     47  void Pause() override;
     48  bool Resume() override;
     49  bool IsPaused() override;
     50 
     51  LayoutDeviceIntSize GetBufferSize() override;
     52 
     53  layers::WebRenderCompositor CompositorType() const override {
     54    return layers::WebRenderCompositor::OPENGL;
     55  }
     56 
     57  bool MaybeReadback(const gfx::IntSize& aReadbackSize,
     58                     const wr::ImageFormat& aReadbackFormat,
     59                     const Range<uint8_t>& aReadbackBuffer,
     60                     bool* aNeedsYFlip) override;
     61 
     62 private:
     63  void HandleExternalImage(RenderTextureHost* aExternalImage,
     64                           FrameSurface& aFrameSurface) override;
     65  UniquePtr<RenderCompositorLayersSWGL::Tile> DoCreateTile(
     66      Surface* aSurface) override;
     67 
     68  EGLSurface CreateEGLSurface();
     69  void DestroyEGLSurface();
     70 
     71  EGLSurface mEGLSurface = EGL_NO_SURFACE;
     72  bool mFullRender = false;
     73 
     74 #ifdef MOZ_WIDGET_ANDROID
     75  // Whether we are in the process of handling a NEW_SURFACE error. On Android
     76  // this is used to allow the widget an opportunity to recover from the first
     77  // instance, before raising a WebRenderError on subsequent occurences.
     78  bool mHandlingNewSurfaceError = false;
     79 #endif
     80 
     81  class TileOGL : public RenderCompositorLayersSWGL::Tile {
     82   public:
     83    TileOGL(RefPtr<layers::TextureImageTextureSourceOGL>&& aTexture,
     84            const gfx::IntSize& aSize);
     85    virtual ~TileOGL();
     86 
     87    bool Map(wr::DeviceIntRect aDirtyRect, wr::DeviceIntRect aValidRect,
     88             void** aData, int32_t* aStride) override;
     89    void Unmap(const gfx::IntRect& aDirtyRect) override;
     90    layers::DataTextureSource* GetTextureSource() override;
     91    bool IsValid() override { return true; }
     92 
     93   private:
     94    RefPtr<layers::TextureImageTextureSourceOGL> mTexture;
     95    RefPtr<gfx::DataSourceSurface> mSurface;
     96    RefPtr<gfx::DataSourceSurface> mSubSurface;
     97    GLuint mPBO = 0;
     98  };
     99 };
    100 
    101 }  // namespace wr
    102 }  // namespace mozilla
    103 
    104 #endif