Bug 1333593. Add support for snapshotting with the RenderThread. r=nical

This commit is contained in:
Jeff Muizelaar 2017-01-24 23:29:34 -05:00
Родитель 6297f79dd0
Коммит eb0b758e56
6 изменённых файлов: 55 добавлений и 10 удалений

Просмотреть файл

@ -503,8 +503,13 @@ WebRenderBridgeParent::RecvDPGetSnapshot(PTextureParent* aTexture)
MOZ_ASSERT((uint32_t)(size.width * 4) == stride);
MOZ_ASSERT(mBuilder.isSome());
mGLContext->MakeCurrent();
wr_readback_into_buffer(mWRWindowState, size.width, size.height, buffer, buffer_size);
if (MOZ_USE_RENDER_THREAD) {
mApi->Readback(size, buffer, buffer_size);
} else {
mGLContext->MakeCurrent();
wr_composite_window(mWRWindowState);
wr_readback_into_buffer(size.width, size.height, buffer, buffer_size);
}
return IPC_OK();
}

Просмотреть файл

@ -97,13 +97,13 @@ public:
/// Automatically forwarded to the render thread.
void RunEvent(wr::WindowId aWindowId, UniquePtr<RendererEvent> aCallBack);
/// Can only be called from the render thread.
void UpdateAndRender(wr::WindowId aWindowId);
private:
explicit RenderThread(base::Thread* aThread);
~RenderThread();
/// Can only be called from the render thread.
void UpdateAndRender(wr::WindowId aWindowId);
base::Thread* const mThread;

Просмотреть файл

@ -170,6 +170,49 @@ WebRenderAPI::SetRootDisplayList(gfx::Color aBgColor,
aViewportSize.width, aViewportSize.height);
}
void
WebRenderAPI::Readback(gfx::IntSize size,
uint8_t *buffer,
uint32_t buffer_size)
{
class Readback : public RendererEvent
{
public:
explicit Readback(layers::SynchronousTask* aTask,
gfx::IntSize aSize, uint8_t *aBuffer, uint32_t aBufferSize)
: mTask(aTask)
, mSize(aSize)
, mBuffer(aBuffer)
, mBufferSize(aBufferSize)
{
MOZ_COUNT_CTOR(Readback);
}
~Readback()
{
MOZ_COUNT_DTOR(Readback);
}
virtual void Run(RenderThread& aRenderThread, WindowId aWindowId) override
{
aRenderThread.UpdateAndRender(aWindowId);
wr_readback_into_buffer(mSize.width, mSize.height, mBuffer, mBufferSize);
layers::AutoCompleteTask complete(mTask);
}
layers::SynchronousTask* mTask;
gfx::IntSize mSize;
uint8_t *mBuffer;
uint32_t mBufferSize;
};
layers::SynchronousTask task("Readback");
auto event = MakeUnique<Readback>(&task, size, buffer, buffer_size);
RunOnRenderThread(Move(event));
task.Wait();
}
void
WebRenderAPI::SetRootPipeline(PipelineId aPipeline)
{

Просмотреть файл

@ -71,6 +71,7 @@ public:
void SetProfilerEnabled(bool aEnabled);
void RunOnRenderThread(UniquePtr<RendererEvent>&& aEvent);
void Readback(gfx::IntSize aSize, uint8_t *aBuffer, uint32_t aBufferSize);
GLint GetMaxTextureSize() const { return mMaxTextureSize; }

Просмотреть файл

@ -959,12 +959,8 @@ pub extern fn wr_window_remove_pipeline(window: &mut WrWindowState, state: &WrSt
// TODO: Remove.
#[no_mangle]
pub extern fn wr_readback_into_buffer(window: &mut WrWindowState, width: u32, height: u32,
pub extern fn wr_readback_into_buffer(width: u32, height: u32,
dst_buffer: *mut u8, buffer_size: usize) {
assert!( unsafe { is_in_compositor_thread() });
wr_composite_window(window);
gl::flush();
unsafe {
let mut slice = slice::from_raw_parts_mut(dst_buffer, buffer_size);
gl::read_pixels_into_buffer(0, 0,

Просмотреть файл

@ -484,7 +484,7 @@ WR_FUNC;
// It is the responsibility of the caller to manage the dst_buffer memory
// and also free it at the proper time.
WR_INLINE const uint8_t*
wr_readback_into_buffer(WrWindowState* wrWindow, uint32_t width, uint32_t height,
wr_readback_into_buffer(uint32_t width, uint32_t height,
uint8_t* dst_buffer, size_t buffer_length)
WR_FUNC;