RendererOGL.h (5546B)
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_LAYERS_RENDEREROGL_H 8 #define MOZILLA_LAYERS_RENDEREROGL_H 9 10 #include "mozilla/layers/CompositorTypes.h" 11 #include "mozilla/gfx/Point.h" 12 #include "mozilla/webrender/RenderThread.h" 13 #include "mozilla/webrender/WebRenderTypes.h" 14 #include "mozilla/webrender/webrender_ffi.h" 15 #include "mozilla/webrender/RendererScreenshotGrabber.h" 16 17 namespace mozilla { 18 19 namespace gfx { 20 class DrawTarget; 21 } 22 23 namespace gl { 24 class GLContext; 25 } 26 27 namespace layers { 28 class CompositorBridgeParent; 29 class Fence; 30 class SyncObjectHost; 31 } // namespace layers 32 33 namespace widget { 34 class CompositorWidget; 35 } 36 37 namespace wr { 38 39 class RenderCompositor; 40 class RenderTextureHost; 41 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); 54 55 public: 56 wr::WrExternalImageHandler GetExternalImageHandler(); 57 58 void SetFramePublishId(FramePublishId aPublishId); 59 60 /// This can be called on the render thread only. 61 void Update(); 62 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, 68 const wr::FrameReadyParams& aFrameParams, 69 RendererStats* aOutStats); 70 71 /// This can be called on the render thread only. 72 void WaitForGPU(); 73 74 /// This can be called on the render thread only. 75 RefPtr<layers::Fence> GetAndResetReleaseFence(); 76 77 /// This can be called on the render thread only. 78 RenderedFrameId GetLastCompletedFrameId(); 79 80 /// This can be called on the render thread only. 81 RenderedFrameId UpdateFrameId(); 82 83 /// This can be called on the render thread only. 84 void SetProfilerEnabled(bool aEnabled); 85 86 /// This can be called on the render thread only. 87 void SetFrameStartTime(const TimeStamp& aTime); 88 89 /// These can be called on the render thread only. 90 void BeginRecording(const TimeStamp& aRecordingStart, 91 wr::PipelineId aPipelineId); 92 void MaybeRecordFrame(const WebRenderPipelineInfo* aPipelineInfo); 93 94 Maybe<layers::FrameRecording> EndRecording(); 95 96 /// This can be called on the render thread only. 97 ~RendererOGL(); 98 99 /// This can be called on the render thread only. 100 RendererOGL(RefPtr<RenderThread>&& aThread, 101 UniquePtr<RenderCompositor> aCompositor, wr::WindowId aWindowId, 102 wr::Renderer* aRenderer, layers::CompositorBridgeParent* aBridge); 103 104 /// This can be called on the render thread only. 105 void Pause(); 106 107 /// This can be called on the render thread only. 108 bool Resume(); 109 110 /// This can be called on the render thread only. 111 bool IsPaused(); 112 113 /// This can be called on the render thread only. 114 void CheckGraphicsResetStatus(gfx::DeviceResetDetectPlace aPlace, 115 bool aForce); 116 117 layers::SyncObjectHost* GetSyncObject() const; 118 119 layers::CompositorBridgeParent* GetCompositorBridge() { return mBridge; } 120 121 void FlushPipelineInfo(); 122 123 RefPtr<const WebRenderPipelineInfo> GetLastPipelineInfo() const { 124 return mLastPipelineInfo; 125 } 126 127 RenderTextureHost* GetRenderTexture(wr::ExternalImageId aExternalImageId); 128 129 RenderCompositor* GetCompositor() { return mCompositor.get(); } 130 131 void AccumulateMemoryReport(MemoryReport* aReport); 132 133 void SetProfilerUI(const nsACString& aUI); 134 135 wr::Renderer* GetRenderer() { return mRenderer; } 136 137 gl::GLContext* gl() const; 138 139 void* swgl() const; 140 141 bool EnsureAsyncScreenshot(); 142 143 protected: 144 /** 145 * Determine if any content pipelines updated, and update 146 * mContentPipelineEpochs. 147 */ 148 bool DidPaintContent(const wr::WebRenderPipelineInfo* aFrameEpochs); 149 150 RefPtr<RenderThread> mThread; 151 UniquePtr<RenderCompositor> mCompositor; 152 UniquePtr<layers::CompositionRecorder> mCompositionRecorder; // can be null 153 wr::Renderer* mRenderer; 154 layers::CompositorBridgeParent* mBridge; 155 wr::WindowId mWindowId; 156 TimeStamp mFrameStartTime; 157 158 bool mDisableNativeCompositor; 159 160 RendererScreenshotGrabber mScreenshotGrabber; 161 162 // The id of the root WebRender pipeline. 163 // 164 // All other pipelines are considered content. 165 wr::PipelineId mRootPipelineId; 166 167 // A mapping of wr::PipelineId to the epochs when last they updated. 168 // 169 // We need to use uint64_t here since wr::PipelineId is not default 170 // constructable. 171 std::unordered_map<uint64_t, wr::Epoch> mContentPipelineEpochs; 172 173 RefPtr<WebRenderPipelineInfo> mLastPipelineInfo; 174 }; 175 176 } // namespace wr 177 } // namespace mozilla 178 179 #endif