1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/layers/opengl/CompositingRenderTargetOGL.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,102 @@ 1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "CompositingRenderTargetOGL.h" 1.10 +#include "GLContext.h" 1.11 +#include "GLReadTexImageHelper.h" 1.12 +#include "mozilla/gfx/2D.h" 1.13 + 1.14 +using namespace mozilla; 1.15 +using namespace mozilla::gfx; 1.16 +using namespace mozilla::gl; 1.17 +using namespace mozilla::layers; 1.18 + 1.19 +CompositingRenderTargetOGL::~CompositingRenderTargetOGL() 1.20 +{ 1.21 + mGL->fDeleteTextures(1, &mTextureHandle); 1.22 + mGL->fDeleteFramebuffers(1, &mFBO); 1.23 +} 1.24 + 1.25 +void 1.26 +CompositingRenderTargetOGL::BindTexture(GLenum aTextureUnit, GLenum aTextureTarget) 1.27 +{ 1.28 + MOZ_ASSERT(mInitParams.mStatus == InitParams::INITIALIZED); 1.29 + MOZ_ASSERT(mTextureHandle != 0); 1.30 + mGL->fActiveTexture(aTextureUnit); 1.31 + mGL->fBindTexture(aTextureTarget, mTextureHandle); 1.32 +} 1.33 + 1.34 +void 1.35 +CompositingRenderTargetOGL::BindRenderTarget() 1.36 +{ 1.37 + if (mInitParams.mStatus != InitParams::INITIALIZED) { 1.38 + InitializeImpl(); 1.39 + } else { 1.40 + MOZ_ASSERT(mInitParams.mStatus == InitParams::INITIALIZED); 1.41 + mGL->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, mFBO); 1.42 + GLenum result = mGL->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER); 1.43 + if (result != LOCAL_GL_FRAMEBUFFER_COMPLETE) { 1.44 + // The main framebuffer (0) of non-offscreen contexts 1.45 + // might be backed by a EGLSurface that needs to be renewed. 1.46 + if (mFBO == 0 && !mGL->IsOffscreen()) { 1.47 + mGL->RenewSurface(); 1.48 + result = mGL->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER); 1.49 + } 1.50 + if (result != LOCAL_GL_FRAMEBUFFER_COMPLETE) { 1.51 + nsAutoCString msg; 1.52 + msg.AppendPrintf("Framebuffer not complete -- CheckFramebufferStatus returned 0x%x, " 1.53 + "GLContext=%p, IsOffscreen()=%d, mFBO=%d, aFBOTextureTarget=0x%x, " 1.54 + "aRect.width=%d, aRect.height=%d", 1.55 + result, mGL, mGL->IsOffscreen(), mFBO, mInitParams.mFBOTextureTarget, 1.56 + mInitParams.mSize.width, mInitParams.mSize.height); 1.57 + NS_WARNING(msg.get()); 1.58 + } 1.59 + } 1.60 + 1.61 + mCompositor->PrepareViewport(mInitParams.mSize, mTransform); 1.62 + } 1.63 +} 1.64 + 1.65 +#ifdef MOZ_DUMP_PAINTING 1.66 +TemporaryRef<DataSourceSurface> 1.67 +CompositingRenderTargetOGL::Dump(Compositor* aCompositor) 1.68 +{ 1.69 + MOZ_ASSERT(mInitParams.mStatus == InitParams::INITIALIZED); 1.70 + CompositorOGL* compositorOGL = static_cast<CompositorOGL*>(aCompositor); 1.71 + return ReadBackSurface(mGL, mTextureHandle, true, compositorOGL->GetFBOFormat()); 1.72 +} 1.73 +#endif 1.74 + 1.75 +void 1.76 +CompositingRenderTargetOGL::InitializeImpl() 1.77 +{ 1.78 + MOZ_ASSERT(mInitParams.mStatus == InitParams::READY); 1.79 + 1.80 + mGL->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, mFBO); 1.81 + mGL->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER, 1.82 + LOCAL_GL_COLOR_ATTACHMENT0, 1.83 + mInitParams.mFBOTextureTarget, 1.84 + mTextureHandle, 1.85 + 0); 1.86 + 1.87 + // Making this call to fCheckFramebufferStatus prevents a crash on 1.88 + // PowerVR. See bug 695246. 1.89 + GLenum result = mGL->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER); 1.90 + if (result != LOCAL_GL_FRAMEBUFFER_COMPLETE) { 1.91 + nsAutoCString msg; 1.92 + msg.AppendPrintf("Framebuffer not complete -- error 0x%x, aFBOTextureTarget 0x%x, mFBO %d, mTextureHandle %d, aRect.width %d, aRect.height %d", 1.93 + result, mInitParams.mFBOTextureTarget, mFBO, mTextureHandle, mInitParams.mSize.width, mInitParams.mSize.height); 1.94 + NS_ERROR(msg.get()); 1.95 + } 1.96 + 1.97 + mCompositor->PrepareViewport(mInitParams.mSize, mTransform); 1.98 + mGL->fScissor(0, 0, mInitParams.mSize.width, mInitParams.mSize.height); 1.99 + if (mInitParams.mInit == INIT_MODE_CLEAR) { 1.100 + mGL->fClearColor(0.0, 0.0, 0.0, 0.0); 1.101 + mGL->fClear(LOCAL_GL_COLOR_BUFFER_BIT); 1.102 + } 1.103 + 1.104 + mInitParams.mStatus = InitParams::INITIALIZED; 1.105 +}