OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010, Google Inc. All rights reserved. | 2 * Copyright (c) 2010, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 21 matching lines...) Expand all Loading... |
32 | 32 |
33 #include "core/platform/graphics/gpu/DrawingBuffer.h" | 33 #include "core/platform/graphics/gpu/DrawingBuffer.h" |
34 | 34 |
35 #include <algorithm> | 35 #include <algorithm> |
36 #include "core/platform/chromium/TraceEvent.h" | 36 #include "core/platform/chromium/TraceEvent.h" |
37 #include "core/platform/graphics/Extensions3D.h" | 37 #include "core/platform/graphics/Extensions3D.h" |
38 #include "core/platform/graphics/GraphicsContext3D.h" | 38 #include "core/platform/graphics/GraphicsContext3D.h" |
39 #include "core/platform/graphics/GraphicsLayer.h" | 39 #include "core/platform/graphics/GraphicsLayer.h" |
40 #include "public/platform/Platform.h" | 40 #include "public/platform/Platform.h" |
41 #include "public/platform/WebCompositorSupport.h" | 41 #include "public/platform/WebCompositorSupport.h" |
| 42 #include "public/platform/WebExternalBitmap.h" |
42 #include "public/platform/WebExternalTextureLayer.h" | 43 #include "public/platform/WebExternalTextureLayer.h" |
43 #include "public/platform/WebGraphicsContext3D.h" | 44 #include "public/platform/WebGraphicsContext3D.h" |
44 | 45 |
45 using namespace std; | 46 using namespace std; |
46 | 47 |
47 namespace WebCore { | 48 namespace WebCore { |
48 | 49 |
49 // Global resource ceiling (expressed in terms of pixels) for DrawingBuffer crea
tion and resize. | 50 // Global resource ceiling (expressed in terms of pixels) for DrawingBuffer crea
tion and resize. |
50 // When this limit is set, DrawingBuffer::create() and DrawingBuffer::reset() ca
lls that would | 51 // When this limit is set, DrawingBuffer::create() and DrawingBuffer::reset() ca
lls that would |
51 // exceed the global cap will instead clear the buffer. | 52 // exceed the global cap will instead clear the buffer. |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 return textureId; | 170 return textureId; |
170 } | 171 } |
171 | 172 |
172 WebKit::WebGraphicsContext3D* DrawingBuffer::context() | 173 WebKit::WebGraphicsContext3D* DrawingBuffer::context() |
173 { | 174 { |
174 if (!m_context) | 175 if (!m_context) |
175 return 0; | 176 return 0; |
176 return m_context->webContext(); | 177 return m_context->webContext(); |
177 } | 178 } |
178 | 179 |
179 bool DrawingBuffer::prepareMailbox(WebKit::WebExternalTextureMailbox* outMailbox
) | 180 bool DrawingBuffer::prepareMailbox(WebKit::WebExternalTextureMailbox* outMailbox
, WebKit::WebExternalBitmap* bitmap) |
180 { | 181 { |
181 if (!m_context || !m_contentsChanged || !m_lastColorBuffer) | 182 if (!m_context || !m_contentsChanged || !m_lastColorBuffer) |
182 return false; | 183 return false; |
183 | 184 |
184 m_context->makeContextCurrent(); | 185 m_context->makeContextCurrent(); |
185 | 186 |
186 // Resolve the multisampled buffer into the texture referenced by m_lastColo
rBuffer mailbox. | 187 // Resolve the multisampled buffer into the texture referenced by m_lastColo
rBuffer mailbox. |
187 if (multisample()) | 188 if (multisample()) |
188 commit(); | 189 commit(); |
189 | 190 |
| 191 if (bitmap) { |
| 192 bitmap->setSize(size()); |
| 193 |
| 194 unsigned char* pixels = bitmap->pixels(); |
| 195 bool needPremultiply = m_attributes.alpha && !m_attributes.premultiplied
Alpha; |
| 196 GraphicsContext3D::AlphaOp op = needPremultiply ? GraphicsContext3D::Alp
haDoPremultiply : GraphicsContext3D::AlphaDoNothing; |
| 197 if (pixels) |
| 198 m_context->readBackFramebuffer(pixels, size().width(), size().height
(), GraphicsContext3D::ReadbackSkia, op); |
| 199 } |
| 200 |
190 // We must restore the texture binding since creating new textures, | 201 // We must restore the texture binding since creating new textures, |
191 // consuming and producing mailboxes changes it. | 202 // consuming and producing mailboxes changes it. |
192 ScopedTextureUnit0BindingRestorer restorer(m_context.get(), m_activeTextureU
nit, m_texture2DBinding); | 203 ScopedTextureUnit0BindingRestorer restorer(m_context.get(), m_activeTextureU
nit, m_texture2DBinding); |
193 | 204 |
194 // First try to recycle an old buffer. | 205 // First try to recycle an old buffer. |
195 RefPtr<MailboxInfo> nextFrontColorBuffer = getRecycledMailbox(); | 206 RefPtr<MailboxInfo> nextFrontColorBuffer = getRecycledMailbox(); |
196 | 207 |
197 // No buffer available to recycle, create a new one. | 208 // No buffer available to recycle, create a new one. |
198 if (!nextFrontColorBuffer) { | 209 if (!nextFrontColorBuffer) { |
199 unsigned newColorBuffer = createColorTexture(m_size); | 210 unsigned newColorBuffer = createColorTexture(m_size); |
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 | 825 |
815 void DrawingBuffer::bind() | 826 void DrawingBuffer::bind() |
816 { | 827 { |
817 if (!m_context) | 828 if (!m_context) |
818 return; | 829 return; |
819 | 830 |
820 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO
? m_multisampleFBO : m_fbo); | 831 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO
? m_multisampleFBO : m_fbo); |
821 } | 832 } |
822 | 833 |
823 } // namespace WebCore | 834 } // namespace WebCore |
OLD | NEW |