| 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 14 matching lines...) Expand all Loading... |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 | 32 |
| 33 #include "DrawingBuffer.h" | 33 #include "DrawingBuffer.h" |
| 34 | 34 |
| 35 #include "Extensions3DChromium.h" | |
| 36 #include "GraphicsContext3D.h" | 35 #include "GraphicsContext3D.h" |
| 37 | |
| 38 #if USE(SKIA) | 36 #if USE(SKIA) |
| 39 #include "GrContext.h" | 37 #include "GrContext.h" |
| 40 #endif | 38 #endif |
| 41 | 39 |
| 42 #if USE(ACCELERATED_COMPOSITING) | 40 #if USE(ACCELERATED_COMPOSITING) |
| 43 #include "Canvas2DLayerChromium.h" | 41 #include "Canvas2DLayerChromium.h" |
| 44 #endif | 42 #endif |
| 45 | 43 |
| 46 namespace WebCore { | 44 namespace WebCore { |
| 47 | 45 |
| 48 static unsigned generateColorTexture(GraphicsContext3D* context, const IntSize&
size) | 46 static unsigned generateColorTexture(GraphicsContext3D* context, const IntSize&
size) |
| 49 { | 47 { |
| 50 unsigned offscreenColorTexture = context->createTexture(); | 48 unsigned offscreenColorTexture = context->createTexture(); |
| 51 if (!offscreenColorTexture) | 49 if (!offscreenColorTexture) |
| 52 return 0; | 50 return 0; |
| 53 | 51 |
| 54 context->bindTexture(GraphicsContext3D::TEXTURE_2D, offscreenColorTexture); | 52 context->bindTexture(GraphicsContext3D::TEXTURE_2D, offscreenColorTexture); |
| 55 context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEX
TURE_MAG_FILTER, GraphicsContext3D::NEAREST); | 53 context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEX
TURE_MAG_FILTER, GraphicsContext3D::NEAREST); |
| 56 context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEX
TURE_MIN_FILTER, GraphicsContext3D::NEAREST); | 54 context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEX
TURE_MIN_FILTER, GraphicsContext3D::NEAREST); |
| 57 context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEX
TURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE); | 55 context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEX
TURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE); |
| 58 context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEX
TURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE); | 56 context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEX
TURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE); |
| 59 context->texImage2DResourceSafe(GraphicsContext3D::TEXTURE_2D, 0, GraphicsCo
ntext3D::RGBA, size.width(), size.height(), 0, GraphicsContext3D::RGBA, Graphics
Context3D::UNSIGNED_BYTE); | 57 context->texImage2DResourceSafe(GraphicsContext3D::TEXTURE_2D, 0, GraphicsCo
ntext3D::RGBA, size.width(), size.height(), 0, GraphicsContext3D::RGBA, Graphics
Context3D::UNSIGNED_BYTE); |
| 60 context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContex
t3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, offscreenColorTexture, 0)
; | 58 context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContex
t3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, offscreenColorTexture, 0)
; |
| 61 | 59 |
| 62 return offscreenColorTexture; | 60 return offscreenColorTexture; |
| 63 } | 61 } |
| 64 | 62 |
| 65 | |
| 66 DrawingBuffer::DrawingBuffer(GraphicsContext3D* context, | 63 DrawingBuffer::DrawingBuffer(GraphicsContext3D* context, |
| 67 const IntSize& size, | 64 const IntSize& size, |
| 68 bool multisampleExtensionSupported, | 65 bool multisampleExtensionSupported, |
| 69 bool packedDepthStencilExtensionSupported) | 66 bool packedDepthStencilExtensionSupported) |
| 70 : m_context(context) | 67 : m_context(context) |
| 71 , m_size(-1, -1) | 68 , m_size(-1, -1) |
| 72 , m_multisampleExtensionSupported(multisampleExtensionSupported) | 69 , m_multisampleExtensionSupported(multisampleExtensionSupported) |
| 73 , m_packedDepthStencilExtensionSupported(packedDepthStencilExtensionSupporte
d) | 70 , m_packedDepthStencilExtensionSupported(packedDepthStencilExtensionSupporte
d) |
| 74 , m_fbo(0) | 71 , m_fbo(0) |
| 75 , m_colorBuffer(0) | 72 , m_colorBuffer(0) |
| 76 , m_depthStencilBuffer(0) | 73 , m_depthStencilBuffer(0) |
| 77 , m_depthBuffer(0) | 74 , m_depthBuffer(0) |
| 78 , m_stencilBuffer(0) | 75 , m_stencilBuffer(0) |
| 79 , m_multisampleFBO(0) | 76 , m_multisampleFBO(0) |
| 80 , m_multisampleColorBuffer(0) | 77 , m_multisampleColorBuffer(0) |
| 81 #if USE(SKIA) | 78 #if USE(SKIA) |
| 82 , m_grContext(0) | 79 , m_grContext(0) |
| 83 #endif | 80 #endif |
| 84 { | 81 { |
| 85 if (!m_context->getExtensions()->supports("GL_CHROMIUM_copy_texture_to_paren
t_texture")) { | |
| 86 m_context.clear(); | |
| 87 return; | |
| 88 } | |
| 89 m_fbo = context->createFramebuffer(); | 82 m_fbo = context->createFramebuffer(); |
| 90 context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo); | 83 context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo); |
| 91 m_colorBuffer = generateColorTexture(context, size); | 84 m_colorBuffer = generateColorTexture(context, size); |
| 92 createSecondaryBuffers(); | 85 createSecondaryBuffers(); |
| 93 if (!reset(size)) { | 86 if (!reset(size)) { |
| 94 m_context.clear(); | 87 m_context.clear(); |
| 95 return; | 88 return; |
| 96 } | 89 } |
| 97 } | 90 } |
| 98 | 91 |
| 99 DrawingBuffer::~DrawingBuffer() | 92 DrawingBuffer::~DrawingBuffer() |
| 100 { | 93 { |
| 101 #if USE(ACCELERATED_COMPOSITING) | 94 #if USE(ACCELERATED_COMPOSITING) |
| 102 if (m_platformLayer) | 95 if (m_platformLayer) |
| 103 m_platformLayer->setDrawingBuffer(0); | 96 m_platformLayer->setDrawingBuffer(0); |
| 104 #endif | 97 #endif |
| 105 | 98 |
| 106 if (!m_context) | 99 if (!m_context) |
| 107 return; | 100 return; |
| 108 | 101 |
| 109 clear(); | 102 clear(); |
| 110 } | 103 } |
| 111 | 104 |
| 112 #if USE(ACCELERATED_COMPOSITING) | 105 #if USE(ACCELERATED_COMPOSITING) |
| 113 void DrawingBuffer::publishToPlatformLayer() | 106 void DrawingBuffer::publishToPlatformLayer() |
| 114 { | 107 { |
| 115 if (!m_context) | 108 if (!m_context) |
| 116 return; | 109 return; |
| 117 | 110 |
| 118 if (m_callback) | |
| 119 m_callback->willPublish(); | |
| 120 if (multisample()) | 111 if (multisample()) |
| 121 commit(); | 112 commit(); |
| 122 unsigned parentTexture = m_platformLayer->textureId(); | |
| 123 // We do the copy in the canvas' (child) context so that it executes in the
correct order relative to | |
| 124 // other commands in the child context. This ensures that the parent texture
always contains a complete | |
| 125 // frame and not some intermediate result. | |
| 126 m_context->makeContextCurrent(); | 113 m_context->makeContextCurrent(); |
| 127 #if USE(SKIA) | 114 #if USE(SKIA) |
| 128 if (m_grContext) | 115 if (m_grContext) |
| 129 m_grContext->flush(0); | 116 m_grContext->flush(0); |
| 130 #endif | 117 #endif |
| 131 static_cast<Extensions3DChromium*>(m_context->getExtensions())->copyTextureT
oParentTextureCHROMIUM(m_colorBuffer, parentTexture); | |
| 132 m_context->flush(); | 118 m_context->flush(); |
| 133 } | 119 } |
| 134 #endif | 120 #endif |
| 135 | 121 |
| 136 void DrawingBuffer::didReset() | |
| 137 { | |
| 138 #if USE(ACCELERATED_COMPOSITING) | |
| 139 if (m_platformLayer) | |
| 140 m_platformLayer->setTextureChanged(); | |
| 141 #endif | |
| 142 } | |
| 143 | |
| 144 #if USE(ACCELERATED_COMPOSITING) | 122 #if USE(ACCELERATED_COMPOSITING) |
| 145 PlatformLayer* DrawingBuffer::platformLayer() | 123 PlatformLayer* DrawingBuffer::platformLayer() |
| 146 { | 124 { |
| 147 if (!m_platformLayer) | 125 if (!m_platformLayer) |
| 148 m_platformLayer = Canvas2DLayerChromium::create(this, 0); | 126 m_platformLayer = Canvas2DLayerChromium::create(this, 0); |
| 149 return m_platformLayer.get(); | 127 return m_platformLayer.get(); |
| 150 } | 128 } |
| 151 #endif | 129 #endif |
| 152 | 130 |
| 153 Platform3DObject DrawingBuffer::platformColorBuffer() const | 131 Platform3DObject DrawingBuffer::platformColorBuffer() const |
| (...skipping 27 matching lines...) Expand all Loading... |
| 181 desc->fWidth = m_size.width(); | 159 desc->fWidth = m_size.width(); |
| 182 desc->fHeight = m_size.height(); | 160 desc->fHeight = m_size.height(); |
| 183 desc->fConfig = kRGBA_8888_GrPixelConfig; | 161 desc->fConfig = kRGBA_8888_GrPixelConfig; |
| 184 | 162 |
| 185 desc->fStencilBits = (m_depthStencilBuffer || m_stencilBuffer) ? 8 : 0; | 163 desc->fStencilBits = (m_depthStencilBuffer || m_stencilBuffer) ? 8 : 0; |
| 186 } | 164 } |
| 187 | 165 |
| 188 #endif | 166 #endif |
| 189 | 167 |
| 190 } | 168 } |
| OLD | NEW |