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/. */
7 #ifndef MOZILLA_GFX_RENDERCOMPOSITOR_OGL_SWGL_H
8 #define MOZILLA_GFX_RENDERCOMPOSITOR_OGL_SWGL_H
10 #include "mozilla/layers/Compositor.h"
11 #include "mozilla/webrender/RenderCompositorLayersSWGL.h"
16 class TextureImageTextureSourceOGL
;
21 class RenderCompositorOGLSWGL
: public RenderCompositorLayersSWGL
{
23 static UniquePtr
<RenderCompositor
> Create(
24 const RefPtr
<widget::CompositorWidget
>& aWidget
, nsACString
& aError
);
26 RenderCompositorOGLSWGL(layers::Compositor
* aCompositor
,
27 const RefPtr
<widget::CompositorWidget
>& aWidget
,
29 virtual ~RenderCompositorOGLSWGL();
31 gl::GLContext
* GetGLContext();
33 bool MakeCurrent() override
;
35 bool BeginFrame() override
;
36 RenderedFrameId
EndFrame(const nsTArray
<DeviceIntRect
>& aDirtyRects
) override
;
38 void GetCompositorCapabilities(CompositorCapabilities
* aCaps
) override
;
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
44 bool UsePartialPresent() override
{ return true; }
45 bool RequestFullRender() override
;
47 void Pause() override
;
48 bool Resume() override
;
49 bool IsPaused() override
;
51 LayoutDeviceIntSize
GetBufferSize() override
;
53 layers::WebRenderCompositor
CompositorType() const override
{
54 return layers::WebRenderCompositor::OPENGL
;
57 bool MaybeReadback(const gfx::IntSize
& aReadbackSize
,
58 const wr::ImageFormat
& aReadbackFormat
,
59 const Range
<uint8_t>& aReadbackBuffer
,
60 bool* aNeedsYFlip
) override
;
63 void HandleExternalImage(RenderTextureHost
* aExternalImage
,
64 FrameSurface
& aFrameSurface
) override
;
65 UniquePtr
<RenderCompositorLayersSWGL::Tile
> DoCreateTile(
66 Surface
* aSurface
) override
;
68 EGLSurface
CreateEGLSurface();
69 void DestroyEGLSurface();
71 EGLSurface mEGLSurface
= EGL_NO_SURFACE
;
72 bool mFullRender
= false;
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;
81 class TileOGL
: public RenderCompositorLayersSWGL::Tile
{
83 TileOGL(RefPtr
<layers::TextureImageTextureSourceOGL
>&& aTexture
,
84 const gfx::IntSize
& aSize
);
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; }
94 RefPtr
<layers::TextureImageTextureSourceOGL
> mTexture
;
95 RefPtr
<gfx::DataSourceSurface
> mSurface
;
96 RefPtr
<gfx::DataSourceSurface
> mSubSurface
;
102 } // namespace mozilla