2017-01-06 21:10:15 +03:00
|
|
|
/* -*- 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"
|
2017-01-11 15:49:02 +03:00
|
|
|
#include "mozilla/layers/CompositorBridgeParent.h"
|
2017-01-06 21:10:15 +03:00
|
|
|
#include "mozilla/layers/CompositorThread.h"
|
|
|
|
#include "mozilla/widget/CompositorWidget.h"
|
2017-01-11 15:49:02 +03:00
|
|
|
#include "base/task.h"
|
2017-01-06 21:10:15 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
2017-01-17 03:22:09 +03:00
|
|
|
namespace wr {
|
2017-01-06 21:10:15 +03:00
|
|
|
|
2017-01-11 15:51:27 +03:00
|
|
|
RendererOGL::RendererOGL(RefPtr<RenderThread>&& aThread,
|
|
|
|
RefPtr<gl::GLContext>&& aGL,
|
|
|
|
RefPtr<widget::CompositorWidget>&& aWidget,
|
2017-01-17 03:22:09 +03:00
|
|
|
wr::WindowId aWindowId,
|
2017-01-06 21:10:15 +03:00
|
|
|
WrRenderer* aWrRenderer,
|
2017-01-17 03:22:09 +03:00
|
|
|
layers::CompositorBridgeParentBase* aBridge)
|
2017-01-06 21:10:15 +03:00
|
|
|
: mThread(aThread)
|
|
|
|
, mGL(aGL)
|
|
|
|
, mWidget(aWidget)
|
|
|
|
, mWrRenderer(aWrRenderer)
|
|
|
|
, mBridge(aBridge)
|
2017-01-06 21:10:20 +03:00
|
|
|
, mWindowId(aWindowId)
|
2017-01-06 21:10:15 +03:00
|
|
|
{
|
2017-01-10 12:17:30 +03:00
|
|
|
MOZ_ASSERT(mThread);
|
|
|
|
MOZ_ASSERT(mGL);
|
|
|
|
MOZ_ASSERT(mWidget);
|
|
|
|
MOZ_ASSERT(mWrRenderer);
|
|
|
|
MOZ_ASSERT(mBridge);
|
|
|
|
MOZ_COUNT_CTOR(RendererOGL);
|
2017-01-06 21:10:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
RendererOGL::~RendererOGL()
|
|
|
|
{
|
2017-01-10 12:17:30 +03:00
|
|
|
MOZ_COUNT_DTOR(RendererOGL);
|
|
|
|
wr_renderer_delete(mWrRenderer);
|
2017-01-06 21:10:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RendererOGL::Update()
|
|
|
|
{
|
|
|
|
wr_renderer_update(mWrRenderer);
|
|
|
|
}
|
|
|
|
|
2017-01-11 15:49:02 +03:00
|
|
|
static void
|
2017-01-17 03:22:09 +03:00
|
|
|
NotifyDidRender(layers::CompositorBridgeParentBase* aBridge, uint64_t aTransactionId, TimeStamp aStart, TimeStamp aEnd)
|
2017-01-11 15:49:02 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-01-06 21:10:15 +03:00
|
|
|
bool
|
|
|
|
RendererOGL::Render(uint64_t aTransactionId)
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
|
2017-01-17 03:22:09 +03:00
|
|
|
layers::CompositorThreadHolder::Loop()->PostTask(NewRunnableFunction(
|
2017-01-11 15:49:02 +03:00
|
|
|
&NotifyDidRender,
|
|
|
|
mBridge, aTransactionId, start, end
|
2017-01-06 21:10:15 +03:00
|
|
|
));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-16 17:22:47 +03:00
|
|
|
void
|
|
|
|
RendererOGL::SetProfilerEnabled(bool aEnabled)
|
|
|
|
{
|
|
|
|
wr_renderer_set_profiler_enabled(mWrRenderer, aEnabled);
|
|
|
|
}
|
|
|
|
|
2017-01-06 21:10:15 +03:00
|
|
|
}
|
|
|
|
}
|