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_LAYERS_RENDEREROGL_H
8 #define MOZILLA_LAYERS_RENDEREROGL_H
10 #include "mozilla/ipc/FileDescriptor.h"
11 #include "mozilla/layers/CompositorTypes.h"
12 #include "mozilla/gfx/Point.h"
13 #include "mozilla/webrender/RenderThread.h"
14 #include "mozilla/webrender/WebRenderTypes.h"
15 #include "mozilla/webrender/webrender_ffi.h"
16 #include "mozilla/webrender/RendererScreenshotGrabber.h"
29 class CompositorBridgeParent
;
34 class CompositorWidget
;
39 class RenderCompositor
;
40 class RenderTextureHost
;
42 /// Owns the WebRender renderer and GL context.
44 /// There is one renderer per window, all owned by the render thread.
45 /// This class is a similar abstraction to CompositorOGL except that it is used
46 /// on the render thread instead of the compositor thread.
48 friend wr::WrExternalImage
LockExternalImage(void* aObj
,
49 wr::ExternalImageId aId
,
50 uint8_t aChannelIndex
,
52 friend void UnlockExternalImage(void* aObj
, wr::ExternalImageId aId
,
53 uint8_t aChannelIndex
);
56 wr::WrExternalImageHandler
GetExternalImageHandler();
58 void SetFramePublishId(FramePublishId aPublishId
);
60 /// This can be called on the render thread only.
63 /// This can be called on the render thread only.
64 RenderedFrameId
UpdateAndRender(const Maybe
<gfx::IntSize
>& aReadbackSize
,
65 const Maybe
<wr::ImageFormat
>& aReadbackFormat
,
66 const Maybe
<Range
<uint8_t>>& aReadbackBuffer
,
67 bool* aNeedsYFlip
, RendererStats
* aOutStats
);
69 /// This can be called on the render thread only.
72 /// This can be called on the render thread only.
73 ipc::FileDescriptor
GetAndResetReleaseFence();
75 /// This can be called on the render thread only.
76 RenderedFrameId
GetLastCompletedFrameId();
78 /// This can be called on the render thread only.
79 RenderedFrameId
UpdateFrameId();
81 /// This can be called on the render thread only.
82 void SetProfilerEnabled(bool aEnabled
);
84 /// This can be called on the render thread only.
85 void SetFrameStartTime(const TimeStamp
& aTime
);
87 /// These can be called on the render thread only.
88 void BeginRecording(const TimeStamp
& aRecordingStart
,
89 wr::PipelineId aPipelineId
);
90 void MaybeRecordFrame(const WebRenderPipelineInfo
* aPipelineInfo
);
92 Maybe
<layers::FrameRecording
> EndRecording();
94 /// This can be called on the render thread only.
97 /// This can be called on the render thread only.
98 RendererOGL(RefPtr
<RenderThread
>&& aThread
,
99 UniquePtr
<RenderCompositor
> aCompositor
, wr::WindowId aWindowId
,
100 wr::Renderer
* aRenderer
, layers::CompositorBridgeParent
* aBridge
);
102 /// This can be called on the render thread only.
105 /// This can be called on the render thread only.
108 /// This can be called on the render thread only.
111 /// This can be called on the render thread only.
112 void CheckGraphicsResetStatus(const char* aCaller
, bool aForce
);
114 layers::SyncObjectHost
* GetSyncObject() const;
116 layers::CompositorBridgeParent
* GetCompositorBridge() { return mBridge
; }
118 void FlushPipelineInfo();
120 RefPtr
<const WebRenderPipelineInfo
> GetLastPipelineInfo() const {
121 return mLastPipelineInfo
;
124 RenderTextureHost
* GetRenderTexture(wr::ExternalImageId aExternalImageId
);
126 RenderCompositor
* GetCompositor() { return mCompositor
.get(); }
128 void AccumulateMemoryReport(MemoryReport
* aReport
);
130 void SetProfilerUI(const nsACString
& aUI
);
132 wr::Renderer
* GetRenderer() { return mRenderer
; }
134 gl::GLContext
* gl() const;
138 bool EnsureAsyncScreenshot();
142 * Determine if any content pipelines updated, and update
143 * mContentPipelineEpochs.
145 bool DidPaintContent(const wr::WebRenderPipelineInfo
* aFrameEpochs
);
147 RefPtr
<RenderThread
> mThread
;
148 UniquePtr
<RenderCompositor
> mCompositor
;
149 UniquePtr
<layers::CompositionRecorder
> mCompositionRecorder
; // can be null
150 wr::Renderer
* mRenderer
;
151 layers::CompositorBridgeParent
* mBridge
;
152 wr::WindowId mWindowId
;
153 TimeStamp mFrameStartTime
;
155 bool mDisableNativeCompositor
;
157 RendererScreenshotGrabber mScreenshotGrabber
;
159 // The id of the root WebRender pipeline.
161 // All other pipelines are considered content.
162 wr::PipelineId mRootPipelineId
;
164 // A mapping of wr::PipelineId to the epochs when last they updated.
166 // We need to use uint64_t here since wr::PipelineId is not default
168 std::unordered_map
<uint64_t, wr::Epoch
> mContentPipelineEpochs
;
170 RefPtr
<WebRenderPipelineInfo
> mLastPipelineInfo
;
174 } // namespace mozilla