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