diff --git a/gfx/layers/RenderThread.cpp b/gfx/layers/RenderThread.cpp deleted file mode 100644 index c12596528dba..000000000000 --- a/gfx/layers/RenderThread.cpp +++ /dev/null @@ -1,197 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "RenderThread.h" -#include "nsThreadUtils.h" -#include "mozilla/layers/RendererOGL.h" - -namespace mozilla { -namespace layers { - -static StaticRefPtr sRenderThread; - -RenderThread::RenderThread(base::Thread* aThread) -: mThread(aThread) -{ - -} - -RenderThread::~RenderThread() -{ - delete mThread; -} - -// statuc -RenderThread* -RenderThread::Get() -{ - return sRenderThread; -} - -// static -void -RenderThread::Start() -{ - MOZ_ASSERT(NS_IsMainThread()); - MOZ_ASSERT(!sRenderThread); - - base::Thread* thread = new base::Thread("Compositor"); - - base::Thread::Options options; - // TODO(nical): The compositor thread has a bunch of specific options, see - // which ones make sense here. - if (!thread->StartWithOptions(options)) { - delete thread; - return; - } - - sRenderThread = new RenderThread(thread); -} - -// static -void -RenderThread::ShutDown() -{ - MOZ_ASSERT(NS_IsMainThread()); - MOZ_ASSERT(sRenderThread); - - // TODO(nical): sync with the render thread - - sRenderThread = nullptr; -} - -// static -MessageLoop* -RenderThread::Loop() -{ - return sRenderThread ? sRenderThread->mThread->message_loop() : nullptr; -} - -// static -bool -RenderThread::IsInRenderThread() -{ - return sRenderThread && sRenderThread->mThread->thread_id() == PlatformThread::CurrentId(); -} - -void -RenderThread::AddRenderer(wr::WindowId aWindowId, UniquePtr aRenderer) -{ - mRenderers[aWindowId] = Move(aRenderer); -} - -void -RenderThread::RemoveRenderer(wr::WindowId aWindowId) -{ - mRenderers.erase(aWindowId); -} - - -void -RenderThread::NewFrameReady(wr::WindowId aWindowId) -{ - if (!IsInRenderThread()) { - Loop()->PostTask(NewRunnableMethod( - this, &RenderThread::NewFrameReady, aWindowId - )); - return; - } - - UpdateAndRender(aWindowId); -} - -void -RenderThread::NewScrollFrameReady(wr::WindowId aWindowId, bool aCompositeNeeded) -{ - if (!IsInRenderThread()) { - Loop()->PostTask(NewRunnableMethod( - this, &RenderThread::NewScrollFrameReady, aWindowId, aCompositeNeeded - )); - return; - } - - UpdateAndRender(aWindowId); -} - -void -RenderThread::PipelineSizeChanged(wr::WindowId aWindowId, uint64_t aPipelineId, float aWidth, float aHeight) -{ - if (!IsInRenderThread()) { - Loop()->PostTask(NewRunnableMethod( - this, &RenderThread::PipelineSizeChanged, - aWindowId, aPipelineId, aWidth, aHeight - )); - return; - } - - UpdateAndRender(aWindowId); -} - -void -RenderThread::RunEvent(wr::WindowId aWindowId, UniquePtr aEvent) -{ - if (!IsInRenderThread()) { - Loop()->PostTask(NewRunnableMethod&&>( - this, &RenderThread::RunEvent, - aWindowId, Move(aEvent) - )); - } - - aEvent->Run(*this, aWindowId); - aEvent = nullptr; -} - - -void -RenderThread::UpdateAndRender(wr::WindowId aWindowId) -{ - auto it = mRenderers.find(aWindowId); - MOZ_ASSERT(it != mRenderers.end()); - if (it == mRenderers.end()) { - return; - } - - auto& renderer = it->second; - - auto transactionId = 0; // TODO! - - renderer->Update(); - renderer->Render(transactionId); -} - -} // namespace -} // namespace - -extern "C" { - -void wr_notifier_new_frame_ready(uint64_t aWindowId) -{ - mozilla::layers::RenderThread::Get()->NewFrameReady(mozilla::wr::WindowId(aWindowId)); -} - -void wr_notifier_new_scroll_frame_ready(uint64_t aWindowId, bool aCompositeNeeded) -{ - mozilla::layers::RenderThread::Get()->NewScrollFrameReady(mozilla::wr::WindowId(aWindowId), - aCompositeNeeded); -} - -void wr_notifier_pipeline_size_changed(uint64_t aWindowId, - uint64_t aPipelineId, - float aWidth, - float aHeight) -{ - mozilla::layers::RenderThread::Get()->PipelineSizeChanged(mozilla::wr::WindowId(aWindowId), - aPipelineId, aWidth, aHeight); -} - -void wr_notifier_external_event(uint64_t aWindowId, size_t aRawEvent) -{ - mozilla::UniquePtr evt( - reinterpret_cast(aRawEvent)); - mozilla::layers::RenderThread::Get()->RunEvent(mozilla::wr::WindowId(aWindowId), - mozilla::Move(evt)); -} - -} // extern C diff --git a/gfx/layers/RenderThread.h b/gfx/layers/RenderThread.h deleted file mode 100644 index 2a3d5912bad6..000000000000 --- a/gfx/layers/RenderThread.h +++ /dev/null @@ -1,110 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set sw=2 sts=2 ts=8 et tw=99 : */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef MOZILLA_LAYERS_RENDERTHREAD_H -#define MOZILLA_LAYERS_RENDERTHREAD_H - -#include "base/basictypes.h" // for DISALLOW_EVIL_CONSTRUCTORS -#include "base/platform_thread.h" // for PlatformThreadId -#include "base/thread.h" // for Thread -#include "base/message_loop.h" -#include "nsISupportsImpl.h" -#include "ThreadSafeRefcountingWithMainThreadDestruction.h" -#include "mozilla/gfx/webrender.h" -#include "mozilla/UniquePtr.h" - -namespace mozilla { -namespace layers { - -class RendererOGL; -class RenderThread; - -/// Base class for an event that can bes cheduled to run on the render thread. -/// -/// The event can be passed through the same channels as regular WebRender messages -/// to preserve ordering. -class RendererEvent -{ -public: - virtual ~RendererEvent() {} - virtual void Run(RenderThread& aRenderThread, wr::WindowId aWindow); -}; - -/// The render thread is where WebRender issues all of its GPU work, and as much -/// as possible this thread should only serve this purpose. -/// -/// The render thread owns the different RendererOGLs (one per window) and implements -/// the RenderNotifier api exposed by the WebRender bindings. -/// -/// We should generally avoid posting tasks to the render thhread's event loop directly -/// and instead use the RendererEvent mechanism which avoids races between the events -/// and WebRender's own messages. -/// -/// The GL context(s) should be created and used on this thread only. -/// XXX - I've tried to organize code so that we can potentially avoid making -/// this a singleton since this bad habbit has a tendency to bite us later, but -/// I haven't gotten all the way there either in order to focus on the more -/// important pieces first. So we are a bit in-between (this is totally a singleton -/// but in some places we pretend it's not). Hopefully we can evolve this in a way -/// that keeps the door open to removing the singleton bits. -class RenderThread final -{ - NS_INLINE_DECL_THREADSAFE_REFCOUNTING_WITH_MAIN_THREAD_DESTRUCTION(RenderThread) - -public: - /// Can be called from any thread. - static RenderThread* Get(); - - static void Start(); - - static void ShutDown(); - - /// Can be called from any thread. - /// In most cases it is best to use RendererEvents through WebRender's api instead - /// of scheduling directly to this message loop (so as to preserve the ordering - /// of the messages). - static MessageLoop* Loop(); - - /// Can be called from any thread. - static bool IsInRenderThread(); - - /// Can only be called from the render thread. - void AddRenderer(wr::WindowId aWindowId, UniquePtr aRenderer); - - /// Can only be called from the render thread. - void RemoveRenderer(wr::WindowId aWindowId); - - // RenderNotifier implementation - - /// Automatically forwarded to the render thread. - void NewFrameReady(wr::WindowId aWindowId); - - /// Automatically forwarded to the render thread. - void NewScrollFrameReady(wr::WindowId aWindowId, bool aCompositeNeeded); - - /// Automatically forwarded to the render thread. - void PipelineSizeChanged(wr::WindowId aWindowId, uint64_t aPipelineId, float aWidth, float aHeight); - - /// Automatically forwarded to the render thread. - void RunEvent(wr::WindowId aWindowId, UniquePtr aCallBack); - -private: - RenderThread(base::Thread* aThread); - - ~RenderThread(); - - /// Can only be called from the render thread. - void UpdateAndRender(wr::WindowId aWindowId); - - base::Thread* const mThread; - - std::map> mRenderers; -}; - -} // namespace -} // namespace - -#endif diff --git a/gfx/layers/moz.build b/gfx/layers/moz.build index 803fa7218aa8..ae2a20a065df 100644 --- a/gfx/layers/moz.build +++ b/gfx/layers/moz.build @@ -192,11 +192,9 @@ EXPORTS.mozilla.layers += [ 'opengl/CompositorOGL.h', 'opengl/MacIOSurfaceTextureClientOGL.h', 'opengl/MacIOSurfaceTextureHostOGL.h', - 'opengl/RendererOGL.h', 'opengl/TextureClientOGL.h', 'opengl/TextureHostOGL.h', 'PersistentBufferProvider.h', - 'RenderThread.h', 'RenderTrace.h', 'TextureWrapperImage.h', 'TransactionIdAllocator.h', @@ -367,13 +365,11 @@ UNIFIED_SOURCES += [ 'opengl/CompositorOGL.cpp', 'opengl/GLBlitTextureImageHelper.cpp', 'opengl/OGLShaderProgram.cpp', - 'opengl/RendererOGL.cpp', 'opengl/TextureClientOGL.cpp', 'opengl/TextureHostOGL.cpp', 'opengl/TexturePoolOGL.cpp', 'protobuf/LayerScopePacket.pb.cc', 'ReadbackProcessor.cpp', - 'RenderThread.cpp', 'RenderTrace.cpp', 'RotatedBuffer.cpp', 'ShareableCanvasLayer.cpp', diff --git a/gfx/layers/opengl/RendererOGL.cpp b/gfx/layers/opengl/RendererOGL.cpp deleted file mode 100644 index bb7d189dc210..000000000000 --- a/gfx/layers/opengl/RendererOGL.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "RendererOGL.h" -#include "GLContext.h" -#include "GLContextProvider.h" -#include "mozilla/gfx/Logging.h" -#include "mozilla/layers/WebRenderBridgeParent.h" -#include "mozilla/layers/CompositorThread.h" - -namespace mozilla { -namespace layers { - -// static -RendererOGL* -RendererOGL::Create(already_AddRefed aThread, - already_AddRefed aWidget, - WrRenderer* aWrRenderer, - wr::WindowId aWindowId, - WebRenderBridgeParent* aBridge) -{ - RefPtr widget = aWidget; - RefPtr thread = aThread; - - MOZ_ASSERT(widget); - MOZ_ASSERT(thread); - MOZ_ASSERT(aWrRenderer); - MOZ_ASSERT(RenderThread::IsInRenderThread()); - - if (!widget || !thread) { - return nullptr; - } - - RefPtr gl = gl::GLContextProvider::CreateForCompositorWidget(widget, true); - if (!gl) { - return nullptr; - } - - if (!gl->MakeCurrent()) { - return nullptr; - } - - return new RendererOGL(thread.forget(), - gl.forget(), - widget.forget(), - aWindowId, - aWrRenderer, - aBridge); -} - -RendererOGL::RendererOGL(already_AddRefed aThread, - already_AddRefed aGL, - already_AddRefed aWidget, - wr::WindowId aWindowId, - WrRenderer* aWrRenderer, - WebRenderBridgeParent* aBridge) -: mThread(aThread) -, mGL(aGL) -, mWidget(aWidget) -, mWrRenderer(aWrRenderer) -, mBridge(aBridge) -, mWindowId(aWindowId) -{ -} - -RendererOGL::~RendererOGL() -{ - -} - -void -RendererOGL::Update() -{ - wr_renderer_update(mWrRenderer); -} - -bool -RendererOGL::Render(uint64_t aTransactionId) -{ - // TODO: WebRender has the notion of epoch and gecko has transaction ids. - // They mostly mean the same thing but I'm not sure they are produced the same - // way. We need to merge the two or have a way to associate transaction ids with - // epochs to wire everything up properly. - - TimeStamp start = TimeStamp::Now(); - - if (!mGL->MakeCurrent()) { - gfxCriticalNote << "Failed to make render context current, can't draw."; - return false; - } - - mozilla::widget::WidgetRenderingContext widgetContext; - -#if defined(XP_MACOSX) - widgetContext.mGL = mGL; -// TODO: we don't have a notion of compositor here. -//#elif defined(MOZ_WIDGET_ANDROID) -// widgetContext.mCompositor = mCompositor; -#endif - - if (!mWidget->PreRender(&widgetContext)) { - return false; - } - // XXX set clear color if MOZ_WIDGET_ANDROID is defined. - // XXX pass the actual render bounds instead of an empty rect. - mWidget->DrawWindowUnderlay(&widgetContext, LayoutDeviceIntRect()); - - auto size = mWidget->GetClientSize(); - wr_renderer_render(mWrRenderer, size.width, size.height); - - mGL->SwapBuffers(); - mWidget->DrawWindowOverlay(&widgetContext, LayoutDeviceIntRect()); - mWidget->PostRender(&widgetContext); - - // TODO: Flush pending actions such as texture deletions/unlocks. - - TimeStamp end = TimeStamp::Now(); - - CompositorThreadHolder::Loop()->PostTask(NewRunnableMethod( - mBridge, - &WebRenderBridgeParent::DidComposite, - aTransactionId, start, end - )); - - return true; -} - -} -} diff --git a/gfx/layers/opengl/RendererOGL.h b/gfx/layers/opengl/RendererOGL.h deleted file mode 100644 index fbda1fdc43a8..000000000000 --- a/gfx/layers/opengl/RendererOGL.h +++ /dev/null @@ -1,79 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set sw=2 sts=2 ts=8 et tw=99 : */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef MOZILLA_LAYERS_RENDEREROGL_H -#define MOZILLA_LAYERS_RENDEREROGL_H - -#include "mozilla/layers/RenderThread.h" -#include "mozilla/gfx/webrender.h" - -namespace mozilla { - -namespace gfx { -class DrawTarget; -} - -namespace gl { -class GLContext; -} - -namespace widget { -class CompositorWidget; -} - -namespace layers { - -class WebRenderBridgeParent; - -/// Owns the WebRender renderer and GL context. -/// -/// There is one renderer per window, all owned by the render thread. -/// This class is a similar abstraction to CompositorOGL except that it is used -/// on the render thread instead of the compositor thread. -class RendererOGL -{ -public: - - /// Render thread only. - static RendererOGL* Create(already_AddRefed aThread, - already_AddRefed aWidget, - WrRenderer* aWrRenderer, - wr::WindowId aWindowId, - WebRenderBridgeParent* aBridge); - - /// Render thread only. - void Update(); - - /// Render thread only. - bool Render(uint64_t aTransactionId); - - /// Render thread only. - bool RenderToTarget(gfx::DrawTarget& aTarget); - - /// Render thread only. - ~RendererOGL(); - -protected: - RendererOGL(already_AddRefed aThread, - already_AddRefed aGL, - already_AddRefed, - wr::WindowId aWindowId, - WrRenderer* aWrRenderer, - WebRenderBridgeParent* aBridge); - - RefPtr mThread; - RefPtr mGL; - RefPtr mWidget; - WrRenderer* mWrRenderer; - WebRenderBridgeParent* mBridge; - wr::WindowId mWindowId; -}; - -} -} - - -#endif diff --git a/gfx/layers/wr/WebRenderBridgeParent.cpp b/gfx/layers/wr/WebRenderBridgeParent.cpp index ee457014e23b..8fb1e04a1821 100644 --- a/gfx/layers/wr/WebRenderBridgeParent.cpp +++ b/gfx/layers/wr/WebRenderBridgeParent.cpp @@ -15,7 +15,6 @@ #include "mozilla/layers/CompositorVsyncScheduler.h" #include "mozilla/layers/ImageBridgeParent.h" #include "mozilla/layers/ImageDataSerializer.h" -#include "mozilla/layers/RenderThread.h" #include "mozilla/layers/TextureHost.h" #include "mozilla/layers/WebRenderCompositorOGL.h" #include "mozilla/widget/CompositorWidget.h" @@ -25,11 +24,6 @@ bool is_in_compositor_thread() return mozilla::layers::CompositorThreadHolder::IsInCompositorThread(); } -bool is_in_render_thread() -{ - return mozilla::layers::RenderThread::IsInRenderThread(); -} - void* get_proc_address_from_glcontext(void* glcontext_ptr, const char* procname) { MOZ_ASSERT(glcontext_ptr); @@ -517,12 +511,6 @@ WebRenderBridgeParent::CompositeToTarget(gfx::DrawTarget* aTarget, const gfx::In mCompositor->FlushPendingNotifyNotUsed(); } -void -WebRenderBridgeParent::DidComposite(uint64_t aTransactionId, TimeStamp aStart, TimeStamp aEnd) -{ - mCompositorBridge->NotifyDidComposite(aTransactionId, aStart, aEnd); -} - WebRenderBridgeParent::~WebRenderBridgeParent() { } diff --git a/gfx/layers/wr/WebRenderBridgeParent.h b/gfx/layers/wr/WebRenderBridgeParent.h index 305f6965a06d..8c9e57ca3a49 100644 --- a/gfx/layers/wr/WebRenderBridgeParent.h +++ b/gfx/layers/wr/WebRenderBridgeParent.h @@ -106,8 +106,6 @@ public: void SendPendingAsyncMessages() override; void SetAboutToSendAsyncMessages() override; - void DidComposite(uint64_t aTransactionId, TimeStamp aStart, TimeStamp aEnd); - private: virtual ~WebRenderBridgeParent(); diff --git a/gfx/thebes/gfxPlatform.cpp b/gfx/thebes/gfxPlatform.cpp index 42715c8232d8..a700d166a8d4 100644 --- a/gfx/thebes/gfxPlatform.cpp +++ b/gfx/thebes/gfxPlatform.cpp @@ -7,7 +7,6 @@ #include "mozilla/layers/CompositorThread.h" #include "mozilla/layers/ImageBridgeChild.h" #include "mozilla/layers/ISurfaceAllocator.h" // for GfxMemoryImageReporter -#include "mozilla/layers/RenderThread.h" #include "mozilla/gfx/gfxVars.h" #include "mozilla/gfx/GPUProcessManager.h" #include "mozilla/gfx/GraphicsMessages.h" @@ -940,9 +939,6 @@ gfxPlatform::InitLayersIPC() if (XRE_IsParentProcess()) { - if (gfxPrefs::WebRenderEnabled()) { - layers::RenderThread::Start(); - } layers::CompositorThreadHolder::Start(); } } @@ -969,7 +965,6 @@ gfxPlatform::ShutdownLayersIPC() // This has to happen after shutting down the child protocols. layers::CompositorThreadHolder::Shutdown(); - layers::RenderThread::ShutDown(); } else { // TODO: There are other kind of processes and we should make sure gfx // stuff is either not created there or shut down properly. diff --git a/gfx/webrender_bindings/src/bindings.rs b/gfx/webrender_bindings/src/bindings.rs index e86689bee54e..f064d8fd375c 100644 --- a/gfx/webrender_bindings/src/bindings.rs +++ b/gfx/webrender_bindings/src/bindings.rs @@ -17,9 +17,6 @@ use webrender::renderer::{ExternalImage, ExternalImageHandler, ExternalImageSour use std::sync::{Arc, Mutex, Condvar}; extern crate webrender_traits; -fn pipeline_id_to_u64(id: PipelineId) -> u64 { (id.0 as u64) << 32 + id.1 as u64 } -fn u64_to_pipeline_id(id: u64) -> PipelineId { PipelineId((id >> 32) as u32, id as u32) } - fn get_proc_address(glcontext_ptr: *mut c_void, name: &str) -> *const c_void{ extern { @@ -42,169 +39,8 @@ fn get_proc_address(glcontext_ptr: *mut c_void, name: &str) -> *const c_void{ extern { fn is_in_compositor_thread() -> bool; - fn is_in_render_thread() -> bool; } -#[no_mangle] -pub extern fn wr_renderer_update(renderer: &mut Renderer) { - renderer.update(); -} - -#[no_mangle] -pub extern fn wr_renderer_render(renderer: &mut Renderer, width: u32, height: u32) { - renderer.render(DeviceUintSize::new(width, height)); -} - -#[no_mangle] -pub extern fn wr_renderer_set_profiler_enabled(renderer: &mut Renderer, enabled: bool) { - renderer.set_profiler_enabled(enabled); -} - -#[no_mangle] -pub extern fn wr_renderer_current_epoch(renderer: &mut Renderer, - pipeline_id: PipelineId, - out_epoch: &mut Epoch) -> bool { - if let Some(epoch) = renderer.current_epoch(pipeline_id) { - *out_epoch = epoch; - return true; - } - return false; -} - -#[no_mangle] -pub unsafe extern fn wr_renderer_delete(renderer: *mut Renderer) { - Box::from_raw(renderer); -} - -#[no_mangle] -pub unsafe extern fn wr_api_delete(api: *mut webrender_traits::RenderApi) { - Box::from_raw(api); -} - -#[no_mangle] -pub extern fn wr_window_new(window_id: u64, - enable_profiler: bool, - out_api: &mut *mut webrender_traits::RenderApi, - out_renderer: &mut *mut Renderer) { - assert!(unsafe { is_in_compositor_thread() }); - - let opts = RendererOptions { - device_pixel_ratio: 1.0, - resource_override_path: None, - enable_aa: false, - enable_subpixel_aa: false, - enable_msaa: false, - enable_profiler: enable_profiler, - enable_recording: false, - enable_scrollbars: false, - precache_shaders: false, - renderer_kind: RendererKind::Native, - debug: false, - clear_framebuffer: true, - clear_empty_tiles: false, - clear_color: ColorF::new(1.0, 1.0, 1.0, 1.0), - }; - - let (renderer, sender) = Renderer::new(opts); - renderer.set_render_notifier(Box::new(CppNotifier { window_id: window_id })); - - *out_api = Box::into_raw(Box::new(sender.create_api())); - *out_renderer = Box::into_raw(Box::new(renderer)); -} - -// Call MakeCurrent before this. -#[no_mangle] -pub extern fn wr_gl_init(gl_context: *mut c_void) { - assert!(unsafe { is_in_render_thread() }); - - gl::load_with(|symbol| get_proc_address(gl_context, symbol)); - gl::clear_color(0.3, 0.0, 0.0, 1.0); - - let version = unsafe { - let data = CStr::from_ptr(gl::GetString(gl::VERSION) as *const _).to_bytes().to_vec(); - String::from_utf8(data).unwrap() - }; - - println!("WebRender - OpenGL version new {}", version); -} - -#[no_mangle] -pub extern fn wr_state_new(width: u32, height: u32, pipeline: u64) -> *mut WrState { - assert!(unsafe { is_in_compositor_thread() }); - let pipeline_id = u64_to_pipeline_id(pipeline); - - let state = Box::new(WrState { - size: (width, height), - pipeline_id: pipeline_id, - z_index: 0, - frame_builder: WebRenderFrameBuilder::new(pipeline_id), - }); - - Box::into_raw(state) -} - -#[no_mangle] -pub extern fn wr_state_delete(state:*mut WrState) { - assert!(unsafe { is_in_compositor_thread() }); - - unsafe { - Box::from_raw(state); - } -} - -struct CppNotifier { - window_id: u64, -} - -unsafe impl Send for CppNotifier {} - -extern { - fn wr_notifier_new_frame_ready(window_id: u64); - fn wr_notifier_new_scroll_frame_ready(window_id: u64, composite_needed: bool); - fn wr_notifier_pipeline_size_changed(window_id: u64, pipeline: u64, new_width: f32, new_height: f32); - // TODO: Waiting for PR #688 - fn wr_notifier_external_event(window_id: u64, raw_event: usize); -} - -impl webrender_traits::RenderNotifier for CppNotifier { - fn new_frame_ready(&mut self) { - unsafe { - wr_notifier_new_frame_ready(self.window_id); - } - } - - fn new_scroll_frame_ready(&mut self, composite_needed: bool) { - unsafe { - wr_notifier_new_scroll_frame_ready(self.window_id, composite_needed); - } - } - - fn pipeline_size_changed(&mut self, - pipeline_id: PipelineId, - new_size: Option) { - let (w, h) = if let Some(size) = new_size { - (size.width, size.height) - } else { - (0.0, 0.0) - }; - unsafe { - let id = pipeline_id_to_u64(pipeline_id); - wr_notifier_pipeline_size_changed(self.window_id, id, w, h); - } - } -} - -// RenderThread WIP notes: -// In order to separate the compositor thread (or ipc receiver) and the render -// thread, some of the logic below needs to be rewritten. In particular -// the WrWindowState and Notifier implementations aren't designed to work with -// a separate render thread. -// As part of that I am moving the bindings closer to WebRender's API boundary, -// and moving more of the logic in C++ land. -// This work is tracked by bug 1328602. -// -// See RenderThread.h for some notes about how the pieces fit together. - pub struct WebRenderFrameBuilder { pub root_pipeline_id: PipelineId, pub dl_builder: webrender_traits::DisplayListBuilder, @@ -219,7 +55,6 @@ impl WebRenderFrameBuilder { } } -// XXX (bug 1328602) - This will be removed soon-ish. struct Notifier { render_notifier: Arc<(Mutex, Condvar)>, } @@ -241,7 +76,6 @@ impl webrender_traits::RenderNotifier for Notifier { } } -// XXX (bug 1328602) - This will be removed soon-ish. pub struct WrWindowState { renderer: Renderer, api: webrender_traits::RenderApi, @@ -368,7 +202,7 @@ pub extern fn wr_init_window(root_pipeline_id: u64, })); } - let pipeline_id = u64_to_pipeline_id(root_pipeline_id); + let pipeline_id = PipelineId((root_pipeline_id >> 32) as u32, root_pipeline_id as u32); api.set_root_pipeline(pipeline_id); let state = Box::new(WrWindowState { @@ -386,7 +220,7 @@ pub extern fn wr_init_window(root_pipeline_id: u64, #[no_mangle] pub extern fn wr_create(window: &mut WrWindowState, width: u32, height: u32, layers_id: u64) -> *mut WrState { assert!( unsafe { is_in_compositor_thread() }); - let pipeline_id = u64_to_pipeline_id(layers_id); + let pipeline_id = PipelineId((layers_id >> 32) as u32, layers_id as u32); let builder = WebRenderFrameBuilder::new(pipeline_id); @@ -499,7 +333,7 @@ fn wait_for_epoch(window: &mut WrWindowState) { #[no_mangle] pub fn wr_composite_window(window: &mut WrWindowState) { - assert!(unsafe { is_in_render_thread() }); + assert!( unsafe { is_in_compositor_thread() }); gl::clear(gl::COLOR_BUFFER_BIT); diff --git a/gfx/webrender_bindings/src/webrender.h b/gfx/webrender_bindings/src/webrender.h index 229a3a62e066..31ade926bbd3 100644 --- a/gfx/webrender_bindings/src/webrender.h +++ b/gfx/webrender_bindings/src/webrender.h @@ -8,15 +8,8 @@ #define WR_h extern "C" { bool is_in_compositor_thread(); -bool is_in_render_thread(); void* get_proc_address_from_glcontext(void* glcontext_ptr, const char* procname); -struct WrRenderer; -void wr_renderer_update(WrRenderer* renderer); -void wr_renderer_render(WrRenderer* renderer, uint32_t width, uint32_t height); -void wr_renderer_set_profiler_enabled(WrRenderer* renderer, bool enabled); -bool wr_renderer_current_epoch(WrRenderer* renderer, uint64_t pipeline_id, uint32_t* out_epoch); - enum WRImageFormat { Invalid, A8, @@ -247,18 +240,4 @@ WR_FUNC; #undef WR_FUNC } - -namespace mozilla { -namespace wr { - -struct WindowId { - explicit WindowId(uint64_t aHandle) : mHandle(aHandle) {} - bool operator<(const WindowId& aOther) const { return mHandle < aOther.mHandle; } - - uint64_t mHandle; -}; - -} // namespace -} // namespace - #endif