Bug 1874684 - Part 28: Return DateDuration from DifferenceISODateTime. r=mgaudet
[gecko.git] / gfx / webrender_bindings / RendererOGL.h
blobbf79f70d1658cf4e05832925ecbd2cdf29196b0f
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"
18 namespace mozilla {
20 namespace gfx {
21 class DrawTarget;
24 namespace gl {
25 class GLContext;
28 namespace layers {
29 class CompositorBridgeParent;
30 class SyncObjectHost;
31 } // namespace layers
33 namespace widget {
34 class CompositorWidget;
37 namespace wr {
39 class RenderCompositor;
40 class RenderTextureHost;
42 /// Owns the WebRender renderer and GL context.
43 ///
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.
47 class RendererOGL {
48 friend wr::WrExternalImage LockExternalImage(void* aObj,
49 wr::ExternalImageId aId,
50 uint8_t aChannelIndex,
51 wr::ImageRendering);
52 friend void UnlockExternalImage(void* aObj, wr::ExternalImageId aId,
53 uint8_t aChannelIndex);
55 public:
56 wr::WrExternalImageHandler GetExternalImageHandler();
58 void SetFramePublishId(FramePublishId aPublishId);
60 /// This can be called on the render thread only.
61 void Update();
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.
70 void WaitForGPU();
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.
95 ~RendererOGL();
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.
103 void Pause();
105 /// This can be called on the render thread only.
106 bool Resume();
108 /// This can be called on the render thread only.
109 bool IsPaused();
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;
136 void* swgl() const;
138 bool EnsureAsyncScreenshot();
140 protected:
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
167 // constructable.
168 std::unordered_map<uint64_t, wr::Epoch> mContentPipelineEpochs;
170 RefPtr<WebRenderPipelineInfo> mLastPipelineInfo;
173 } // namespace wr
174 } // namespace mozilla
176 #endif