2013-09-04 16:14:52 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; 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 "CompositingRenderTargetOGL.h"
|
|
|
|
#include "GLContext.h"
|
2014-01-02 19:17:29 +04:00
|
|
|
#include "GLReadTexImageHelper.h"
|
2014-01-08 12:37:58 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2013-09-04 16:14:52 +04:00
|
|
|
|
2014-05-22 14:11:45 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2014-01-08 12:37:58 +04:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
using namespace mozilla::gl;
|
2013-09-04 16:14:52 +04:00
|
|
|
|
|
|
|
CompositingRenderTargetOGL::~CompositingRenderTargetOGL()
|
|
|
|
{
|
2014-11-04 01:27:32 +03:00
|
|
|
mGL->MakeCurrent();
|
2013-09-04 16:14:52 +04:00
|
|
|
mGL->fDeleteTextures(1, &mTextureHandle);
|
|
|
|
mGL->fDeleteFramebuffers(1, &mFBO);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CompositingRenderTargetOGL::BindTexture(GLenum aTextureUnit, GLenum aTextureTarget)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mInitParams.mStatus == InitParams::INITIALIZED);
|
|
|
|
MOZ_ASSERT(mTextureHandle != 0);
|
|
|
|
mGL->fActiveTexture(aTextureUnit);
|
|
|
|
mGL->fBindTexture(aTextureTarget, mTextureHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CompositingRenderTargetOGL::BindRenderTarget()
|
|
|
|
{
|
2015-05-19 20:51:26 +03:00
|
|
|
bool needsClear = false;
|
|
|
|
|
2013-09-04 16:14:52 +04:00
|
|
|
if (mInitParams.mStatus != InitParams::INITIALIZED) {
|
|
|
|
InitializeImpl();
|
2015-05-19 20:51:26 +03:00
|
|
|
if (mInitParams.mInit == INIT_MODE_CLEAR) {
|
|
|
|
needsClear = true;
|
|
|
|
mClearOnBind = false;
|
|
|
|
}
|
2013-09-04 16:14:52 +04:00
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(mInitParams.mStatus == InitParams::INITIALIZED);
|
2015-05-11 22:10:06 +03:00
|
|
|
GLuint fbo = mFBO == 0 ? mGL->GetDefaultFramebuffer() : mFBO;
|
|
|
|
mGL->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, fbo);
|
2013-09-04 16:14:52 +04:00
|
|
|
GLenum result = mGL->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER);
|
|
|
|
if (result != LOCAL_GL_FRAMEBUFFER_COMPLETE) {
|
2013-09-24 15:54:07 +04:00
|
|
|
// The main framebuffer (0) of non-offscreen contexts
|
|
|
|
// might be backed by a EGLSurface that needs to be renewed.
|
|
|
|
if (mFBO == 0 && !mGL->IsOffscreen()) {
|
|
|
|
mGL->RenewSurface();
|
|
|
|
result = mGL->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER);
|
|
|
|
}
|
|
|
|
if (result != LOCAL_GL_FRAMEBUFFER_COMPLETE) {
|
2013-09-24 16:21:55 +04:00
|
|
|
nsAutoCString msg;
|
|
|
|
msg.AppendPrintf("Framebuffer not complete -- CheckFramebufferStatus returned 0x%x, "
|
|
|
|
"GLContext=%p, IsOffscreen()=%d, mFBO=%d, aFBOTextureTarget=0x%x, "
|
|
|
|
"aRect.width=%d, aRect.height=%d",
|
|
|
|
result, mGL, mGL->IsOffscreen(), mFBO, mInitParams.mFBOTextureTarget,
|
|
|
|
mInitParams.mSize.width, mInitParams.mSize.height);
|
|
|
|
NS_WARNING(msg.get());
|
2013-09-24 15:54:07 +04:00
|
|
|
}
|
2013-09-04 16:14:52 +04:00
|
|
|
}
|
|
|
|
|
2015-05-19 20:51:26 +03:00
|
|
|
needsClear = mClearOnBind;
|
2013-09-04 16:14:52 +04:00
|
|
|
}
|
2014-11-04 01:27:32 +03:00
|
|
|
|
2015-05-19 20:51:26 +03:00
|
|
|
if (needsClear) {
|
2014-11-19 23:30:25 +03:00
|
|
|
mGL->fScissor(0, 0, mInitParams.mSize.width, mInitParams.mSize.height);
|
2014-11-04 01:27:32 +03:00
|
|
|
mGL->fClearColor(0.0, 0.0, 0.0, 0.0);
|
2015-05-19 20:51:26 +03:00
|
|
|
mGL->fClearDepth(0.0);
|
|
|
|
mGL->fClear(LOCAL_GL_COLOR_BUFFER_BIT | LOCAL_GL_DEPTH_BUFFER_BIT);
|
2014-11-04 01:27:32 +03:00
|
|
|
}
|
2013-09-04 16:14:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<DataSourceSurface>
|
2013-09-04 16:14:52 +04:00
|
|
|
CompositingRenderTargetOGL::Dump(Compositor* aCompositor)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mInitParams.mStatus == InitParams::INITIALIZED);
|
|
|
|
CompositorOGL* compositorOGL = static_cast<CompositorOGL*>(aCompositor);
|
2014-01-08 12:37:58 +04:00
|
|
|
return ReadBackSurface(mGL, mTextureHandle, true, compositorOGL->GetFBOFormat());
|
2013-09-04 16:14:52 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
|
|
|
CompositingRenderTargetOGL::InitializeImpl()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mInitParams.mStatus == InitParams::READY);
|
|
|
|
|
2015-05-11 22:10:06 +03:00
|
|
|
//TODO: call mGL->GetBackbufferFB(), use that
|
|
|
|
GLuint fbo = mFBO == 0 ? mGL->GetDefaultFramebuffer() : mFBO;
|
|
|
|
mGL->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, fbo);
|
2013-09-04 16:14:52 +04:00
|
|
|
mGL->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER,
|
|
|
|
LOCAL_GL_COLOR_ATTACHMENT0,
|
|
|
|
mInitParams.mFBOTextureTarget,
|
|
|
|
mTextureHandle,
|
|
|
|
0);
|
|
|
|
|
|
|
|
// Making this call to fCheckFramebufferStatus prevents a crash on
|
|
|
|
// PowerVR. See bug 695246.
|
|
|
|
GLenum result = mGL->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER);
|
|
|
|
if (result != LOCAL_GL_FRAMEBUFFER_COMPLETE) {
|
|
|
|
nsAutoCString msg;
|
|
|
|
msg.AppendPrintf("Framebuffer not complete -- error 0x%x, aFBOTextureTarget 0x%x, mFBO %d, mTextureHandle %d, aRect.width %d, aRect.height %d",
|
|
|
|
result, mInitParams.mFBOTextureTarget, mFBO, mTextureHandle, mInitParams.mSize.width, mInitParams.mSize.height);
|
|
|
|
NS_ERROR(msg.get());
|
|
|
|
}
|
|
|
|
|
2014-10-03 04:22:32 +04:00
|
|
|
mInitParams.mStatus = InitParams::INITIALIZED;
|
2013-09-04 16:14:52 +04:00
|
|
|
}
|
2014-05-22 14:11:45 +04:00
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|