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