Bug 1699062 - Flatten toolkit/themes/*/global/alerts/. r=desktop-theme-reviewers,dao
[gecko.git] / gfx / webrender_bindings / RendererOGL.h
blob97af04c4e1814b86678d49213533ea3752cd5417
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 /// This can be called on the render thread only.
59 void Update();
61 /// This can be called on the render thread only.
62 RenderedFrameId UpdateAndRender(const Maybe<gfx::IntSize>& aReadbackSize,
63 const Maybe<wr::ImageFormat>& aReadbackFormat,
64 const Maybe<Range<uint8_t>>& aReadbackBuffer,
65 bool* aNeedsYFlip, RendererStats* aOutStats);
67 /// This can be called on the render thread only.
68 void WaitForGPU();
70 /// This can be called on the render thread only.
71 ipc::FileDescriptor GetAndResetReleaseFence();
73 /// This can be called on the render thread only.
74 RenderedFrameId GetLastCompletedFrameId();
76 /// This can be called on the render thread only.
77 RenderedFrameId UpdateFrameId();
79 /// This can be called on the render thread only.
80 void SetProfilerEnabled(bool aEnabled);
82 /// This can be called on the render thread only.
83 void SetFrameStartTime(const TimeStamp& aTime);
85 /// These can be called on the render thread only.
86 void BeginRecording(const TimeStamp& aRecordingStart,
87 wr::PipelineId aPipelineId);
88 void MaybeRecordFrame(const WebRenderPipelineInfo* aPipelineInfo);
89 void WriteCollectedFrames();
90 Maybe<layers::CollectedFrames> GetCollectedFrames();
92 /// This can be called on the render thread only.
93 ~RendererOGL();
95 /// This can be called on the render thread only.
96 RendererOGL(RefPtr<RenderThread>&& aThread,
97 UniquePtr<RenderCompositor> aCompositor, wr::WindowId aWindowId,
98 wr::Renderer* aRenderer, layers::CompositorBridgeParent* aBridge);
100 /// This can be called on the render thread only.
101 void Pause();
103 /// This can be called on the render thread only.
104 bool Resume();
106 /// This can be called on the render thread only.
107 bool IsPaused();
109 /// This can be called on the render thread only.
110 void CheckGraphicsResetStatus(const char* aCaller, bool aForce);
112 layers::SyncObjectHost* GetSyncObject() const;
114 layers::CompositorBridgeParent* GetCompositorBridge() { return mBridge; }
116 RefPtr<WebRenderPipelineInfo> FlushPipelineInfo();
118 RenderTextureHost* GetRenderTexture(wr::ExternalImageId aExternalImageId);
120 RenderCompositor* GetCompositor() { return mCompositor.get(); }
122 void AccumulateMemoryReport(MemoryReport* aReport);
124 void SetProfilerUI(const nsCString& aUI);
126 wr::Renderer* GetRenderer() { return mRenderer; }
128 gl::GLContext* gl() const;
130 void* swgl() const;
132 bool EnsureAsyncScreenshot();
134 protected:
136 * Determine if any content pipelines updated, and update
137 * mContentPipelineEpochs.
139 bool DidPaintContent(const wr::WebRenderPipelineInfo* aFrameEpochs);
141 RefPtr<RenderThread> mThread;
142 UniquePtr<RenderCompositor> mCompositor;
143 UniquePtr<layers::CompositionRecorder> mCompositionRecorder; // can be null
144 wr::Renderer* mRenderer;
145 layers::CompositorBridgeParent* mBridge;
146 wr::WindowId mWindowId;
147 TimeStamp mFrameStartTime;
149 bool mDisableNativeCompositor;
151 RendererScreenshotGrabber mScreenshotGrabber;
153 // The id of the root WebRender pipeline.
155 // All other pipelines are considered content.
156 wr::PipelineId mRootPipelineId;
158 // A mapping of wr::PipelineId to the epochs when last they updated.
160 // We need to use uint64_t here since wr::PipelineId is not default
161 // constructable.
162 std::unordered_map<uint64_t, wr::Epoch> mContentPipelineEpochs;
165 } // namespace wr
166 } // namespace mozilla
168 #endif