Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "CompositingRenderTargetOGL.h" |
michael@0 | 7 | #include "GLContext.h" |
michael@0 | 8 | #include "GLReadTexImageHelper.h" |
michael@0 | 9 | #include "mozilla/gfx/2D.h" |
michael@0 | 10 | |
michael@0 | 11 | using namespace mozilla; |
michael@0 | 12 | using namespace mozilla::gfx; |
michael@0 | 13 | using namespace mozilla::gl; |
michael@0 | 14 | using namespace mozilla::layers; |
michael@0 | 15 | |
michael@0 | 16 | CompositingRenderTargetOGL::~CompositingRenderTargetOGL() |
michael@0 | 17 | { |
michael@0 | 18 | mGL->fDeleteTextures(1, &mTextureHandle); |
michael@0 | 19 | mGL->fDeleteFramebuffers(1, &mFBO); |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | void |
michael@0 | 23 | CompositingRenderTargetOGL::BindTexture(GLenum aTextureUnit, GLenum aTextureTarget) |
michael@0 | 24 | { |
michael@0 | 25 | MOZ_ASSERT(mInitParams.mStatus == InitParams::INITIALIZED); |
michael@0 | 26 | MOZ_ASSERT(mTextureHandle != 0); |
michael@0 | 27 | mGL->fActiveTexture(aTextureUnit); |
michael@0 | 28 | mGL->fBindTexture(aTextureTarget, mTextureHandle); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | void |
michael@0 | 32 | CompositingRenderTargetOGL::BindRenderTarget() |
michael@0 | 33 | { |
michael@0 | 34 | if (mInitParams.mStatus != InitParams::INITIALIZED) { |
michael@0 | 35 | InitializeImpl(); |
michael@0 | 36 | } else { |
michael@0 | 37 | MOZ_ASSERT(mInitParams.mStatus == InitParams::INITIALIZED); |
michael@0 | 38 | mGL->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, mFBO); |
michael@0 | 39 | GLenum result = mGL->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER); |
michael@0 | 40 | if (result != LOCAL_GL_FRAMEBUFFER_COMPLETE) { |
michael@0 | 41 | // The main framebuffer (0) of non-offscreen contexts |
michael@0 | 42 | // might be backed by a EGLSurface that needs to be renewed. |
michael@0 | 43 | if (mFBO == 0 && !mGL->IsOffscreen()) { |
michael@0 | 44 | mGL->RenewSurface(); |
michael@0 | 45 | result = mGL->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER); |
michael@0 | 46 | } |
michael@0 | 47 | if (result != LOCAL_GL_FRAMEBUFFER_COMPLETE) { |
michael@0 | 48 | nsAutoCString msg; |
michael@0 | 49 | msg.AppendPrintf("Framebuffer not complete -- CheckFramebufferStatus returned 0x%x, " |
michael@0 | 50 | "GLContext=%p, IsOffscreen()=%d, mFBO=%d, aFBOTextureTarget=0x%x, " |
michael@0 | 51 | "aRect.width=%d, aRect.height=%d", |
michael@0 | 52 | result, mGL, mGL->IsOffscreen(), mFBO, mInitParams.mFBOTextureTarget, |
michael@0 | 53 | mInitParams.mSize.width, mInitParams.mSize.height); |
michael@0 | 54 | NS_WARNING(msg.get()); |
michael@0 | 55 | } |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | mCompositor->PrepareViewport(mInitParams.mSize, mTransform); |
michael@0 | 59 | } |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | #ifdef MOZ_DUMP_PAINTING |
michael@0 | 63 | TemporaryRef<DataSourceSurface> |
michael@0 | 64 | CompositingRenderTargetOGL::Dump(Compositor* aCompositor) |
michael@0 | 65 | { |
michael@0 | 66 | MOZ_ASSERT(mInitParams.mStatus == InitParams::INITIALIZED); |
michael@0 | 67 | CompositorOGL* compositorOGL = static_cast<CompositorOGL*>(aCompositor); |
michael@0 | 68 | return ReadBackSurface(mGL, mTextureHandle, true, compositorOGL->GetFBOFormat()); |
michael@0 | 69 | } |
michael@0 | 70 | #endif |
michael@0 | 71 | |
michael@0 | 72 | void |
michael@0 | 73 | CompositingRenderTargetOGL::InitializeImpl() |
michael@0 | 74 | { |
michael@0 | 75 | MOZ_ASSERT(mInitParams.mStatus == InitParams::READY); |
michael@0 | 76 | |
michael@0 | 77 | mGL->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, mFBO); |
michael@0 | 78 | mGL->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER, |
michael@0 | 79 | LOCAL_GL_COLOR_ATTACHMENT0, |
michael@0 | 80 | mInitParams.mFBOTextureTarget, |
michael@0 | 81 | mTextureHandle, |
michael@0 | 82 | 0); |
michael@0 | 83 | |
michael@0 | 84 | // Making this call to fCheckFramebufferStatus prevents a crash on |
michael@0 | 85 | // PowerVR. See bug 695246. |
michael@0 | 86 | GLenum result = mGL->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER); |
michael@0 | 87 | if (result != LOCAL_GL_FRAMEBUFFER_COMPLETE) { |
michael@0 | 88 | nsAutoCString msg; |
michael@0 | 89 | msg.AppendPrintf("Framebuffer not complete -- error 0x%x, aFBOTextureTarget 0x%x, mFBO %d, mTextureHandle %d, aRect.width %d, aRect.height %d", |
michael@0 | 90 | result, mInitParams.mFBOTextureTarget, mFBO, mTextureHandle, mInitParams.mSize.width, mInitParams.mSize.height); |
michael@0 | 91 | NS_ERROR(msg.get()); |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | mCompositor->PrepareViewport(mInitParams.mSize, mTransform); |
michael@0 | 95 | mGL->fScissor(0, 0, mInitParams.mSize.width, mInitParams.mSize.height); |
michael@0 | 96 | if (mInitParams.mInit == INIT_MODE_CLEAR) { |
michael@0 | 97 | mGL->fClearColor(0.0, 0.0, 0.0, 0.0); |
michael@0 | 98 | mGL->fClear(LOCAL_GL_COLOR_BUFFER_BIT); |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | mInitParams.mStatus = InitParams::INITIALIZED; |
michael@0 | 102 | } |