| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 DECLARE_VIRTUAL_TRACE(); | 42 DECLARE_VIRTUAL_TRACE(); |
| 43 | 43 |
| 44 private: | 44 private: |
| 45 explicit WebGLRenderbufferAttachment(WebGLRenderbuffer*); | 45 explicit WebGLRenderbufferAttachment(WebGLRenderbuffer*); |
| 46 WebGLRenderbufferAttachment() { } | 46 WebGLRenderbufferAttachment() { } |
| 47 | 47 |
| 48 WebGLSharedObject* object() const override; | 48 WebGLSharedObject* object() const override; |
| 49 bool isSharedObject(WebGLSharedObject*) const override; | 49 bool isSharedObject(WebGLSharedObject*) const override; |
| 50 bool valid() const override; | 50 bool valid() const override; |
| 51 void onDetached(WebGraphicsContext3D*, gpu::gles2::GLES2Interface*) override
; | 51 void onDetached(gpu::gles2::GLES2Interface*) override; |
| 52 void attach(gpu::gles2::GLES2Interface*, GLenum target, GLenum attachment) o
verride; | 52 void attach(gpu::gles2::GLES2Interface*, GLenum target, GLenum attachment) o
verride; |
| 53 void unattach(gpu::gles2::GLES2Interface*, GLenum target, GLenum attachment)
override; | 53 void unattach(gpu::gles2::GLES2Interface*, GLenum target, GLenum attachment)
override; |
| 54 | 54 |
| 55 Member<WebGLRenderbuffer> m_renderbuffer; | 55 Member<WebGLRenderbuffer> m_renderbuffer; |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 WebGLFramebuffer::WebGLAttachment* WebGLRenderbufferAttachment::create(WebGLRend
erbuffer* renderbuffer) | 58 WebGLFramebuffer::WebGLAttachment* WebGLRenderbufferAttachment::create(WebGLRend
erbuffer* renderbuffer) |
| 59 { | 59 { |
| 60 return new WebGLRenderbufferAttachment(renderbuffer); | 60 return new WebGLRenderbufferAttachment(renderbuffer); |
| 61 } | 61 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 79 bool WebGLRenderbufferAttachment::isSharedObject(WebGLSharedObject* object) cons
t | 79 bool WebGLRenderbufferAttachment::isSharedObject(WebGLSharedObject* object) cons
t |
| 80 { | 80 { |
| 81 return object == m_renderbuffer; | 81 return object == m_renderbuffer; |
| 82 } | 82 } |
| 83 | 83 |
| 84 bool WebGLRenderbufferAttachment::valid() const | 84 bool WebGLRenderbufferAttachment::valid() const |
| 85 { | 85 { |
| 86 return m_renderbuffer->object(); | 86 return m_renderbuffer->object(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 void WebGLRenderbufferAttachment::onDetached(WebGraphicsContext3D* context, gpu:
:gles2::GLES2Interface* gl) | 89 void WebGLRenderbufferAttachment::onDetached(gpu::gles2::GLES2Interface* gl) |
| 90 { | 90 { |
| 91 m_renderbuffer->onDetached(context, gl); | 91 m_renderbuffer->onDetached(gl); |
| 92 } | 92 } |
| 93 | 93 |
| 94 void WebGLRenderbufferAttachment::attach(gpu::gles2::GLES2Interface* gl, GLenum
target, GLenum attachment) | 94 void WebGLRenderbufferAttachment::attach(gpu::gles2::GLES2Interface* gl, GLenum
target, GLenum attachment) |
| 95 { | 95 { |
| 96 Platform3DObject object = objectOrZero(m_renderbuffer.get()); | 96 Platform3DObject object = objectOrZero(m_renderbuffer.get()); |
| 97 gl->FramebufferRenderbuffer(target, attachment, GL_RENDERBUFFER, object); | 97 gl->FramebufferRenderbuffer(target, attachment, GL_RENDERBUFFER, object); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void WebGLRenderbufferAttachment::unattach(gpu::gles2::GLES2Interface* gl, GLenu
m target, GLenum attachment) | 100 void WebGLRenderbufferAttachment::unattach(gpu::gles2::GLES2Interface* gl, GLenu
m target, GLenum attachment) |
| 101 { | 101 { |
| 102 gl->FramebufferRenderbuffer(target, attachment, GL_RENDERBUFFER, 0); | 102 gl->FramebufferRenderbuffer(target, attachment, GL_RENDERBUFFER, 0); |
| 103 } | 103 } |
| 104 | 104 |
| 105 class WebGLTextureAttachment final : public WebGLFramebuffer::WebGLAttachment { | 105 class WebGLTextureAttachment final : public WebGLFramebuffer::WebGLAttachment { |
| 106 public: | 106 public: |
| 107 static WebGLFramebuffer::WebGLAttachment* create(WebGLTexture*, GLenum targe
t, GLint level, GLint layer); | 107 static WebGLFramebuffer::WebGLAttachment* create(WebGLTexture*, GLenum targe
t, GLint level, GLint layer); |
| 108 | 108 |
| 109 DECLARE_VIRTUAL_TRACE(); | 109 DECLARE_VIRTUAL_TRACE(); |
| 110 | 110 |
| 111 private: | 111 private: |
| 112 WebGLTextureAttachment(WebGLTexture*, GLenum target, GLint level, GLint laye
r); | 112 WebGLTextureAttachment(WebGLTexture*, GLenum target, GLint level, GLint laye
r); |
| 113 WebGLTextureAttachment() { } | 113 WebGLTextureAttachment() { } |
| 114 | 114 |
| 115 WebGLSharedObject* object() const override; | 115 WebGLSharedObject* object() const override; |
| 116 bool isSharedObject(WebGLSharedObject*) const override; | 116 bool isSharedObject(WebGLSharedObject*) const override; |
| 117 bool valid() const override; | 117 bool valid() const override; |
| 118 void onDetached(WebGraphicsContext3D*, gpu::gles2::GLES2Interface*) override
; | 118 void onDetached(gpu::gles2::GLES2Interface*) override; |
| 119 void attach(gpu::gles2::GLES2Interface*, GLenum target, GLenum attachment) o
verride; | 119 void attach(gpu::gles2::GLES2Interface*, GLenum target, GLenum attachment) o
verride; |
| 120 void unattach(gpu::gles2::GLES2Interface*, GLenum target, GLenum attachment)
override; | 120 void unattach(gpu::gles2::GLES2Interface*, GLenum target, GLenum attachment)
override; |
| 121 | 121 |
| 122 Member<WebGLTexture> m_texture; | 122 Member<WebGLTexture> m_texture; |
| 123 GLenum m_target; | 123 GLenum m_target; |
| 124 GLint m_level; | 124 GLint m_level; |
| 125 GLint m_layer; | 125 GLint m_layer; |
| 126 }; | 126 }; |
| 127 | 127 |
| 128 WebGLFramebuffer::WebGLAttachment* WebGLTextureAttachment::create(WebGLTexture*
texture, GLenum target, GLint level, GLint layer) | 128 WebGLFramebuffer::WebGLAttachment* WebGLTextureAttachment::create(WebGLTexture*
texture, GLenum target, GLint level, GLint layer) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 152 bool WebGLTextureAttachment::isSharedObject(WebGLSharedObject* object) const | 152 bool WebGLTextureAttachment::isSharedObject(WebGLSharedObject* object) const |
| 153 { | 153 { |
| 154 return object == m_texture; | 154 return object == m_texture; |
| 155 } | 155 } |
| 156 | 156 |
| 157 bool WebGLTextureAttachment::valid() const | 157 bool WebGLTextureAttachment::valid() const |
| 158 { | 158 { |
| 159 return m_texture->object(); | 159 return m_texture->object(); |
| 160 } | 160 } |
| 161 | 161 |
| 162 void WebGLTextureAttachment::onDetached(WebGraphicsContext3D* context, gpu::gles
2::GLES2Interface* gl) | 162 void WebGLTextureAttachment::onDetached(gpu::gles2::GLES2Interface* gl) |
| 163 { | 163 { |
| 164 m_texture->onDetached(context, gl); | 164 m_texture->onDetached(gl); |
| 165 } | 165 } |
| 166 | 166 |
| 167 void WebGLTextureAttachment::attach(gpu::gles2::GLES2Interface* gl, GLenum targe
t, GLenum attachment) | 167 void WebGLTextureAttachment::attach(gpu::gles2::GLES2Interface* gl, GLenum targe
t, GLenum attachment) |
| 168 { | 168 { |
| 169 Platform3DObject object = objectOrZero(m_texture.get()); | 169 Platform3DObject object = objectOrZero(m_texture.get()); |
| 170 if (m_target == GL_TEXTURE_3D || m_target == GL_TEXTURE_2D_ARRAY) { | 170 if (m_target == GL_TEXTURE_3D || m_target == GL_TEXTURE_2D_ARRAY) { |
| 171 gl->FramebufferTextureLayer(target, attachment, object, m_level, m_layer
); | 171 gl->FramebufferTextureLayer(target, attachment, object, m_level, m_layer
); |
| 172 } else { | 172 } else { |
| 173 gl->FramebufferTexture2D(target, attachment, m_target, object, m_level); | 173 gl->FramebufferTexture2D(target, attachment, m_target, object, m_level); |
| 174 } | 174 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 } | 269 } |
| 270 | 270 |
| 271 void WebGLFramebuffer::removeAttachmentFromBoundFramebuffer(GLenum target, GLenu
m attachment) | 271 void WebGLFramebuffer::removeAttachmentFromBoundFramebuffer(GLenum target, GLenu
m attachment) |
| 272 { | 272 { |
| 273 ASSERT(isBound(target)); | 273 ASSERT(isBound(target)); |
| 274 if (!m_object) | 274 if (!m_object) |
| 275 return; | 275 return; |
| 276 | 276 |
| 277 WebGLAttachment* attachmentObject = getAttachment(attachment); | 277 WebGLAttachment* attachmentObject = getAttachment(attachment); |
| 278 if (attachmentObject) { | 278 if (attachmentObject) { |
| 279 attachmentObject->onDetached(context()->webContext(), context()->context
GL()); | 279 attachmentObject->onDetached(context()->contextGL()); |
| 280 m_attachments.remove(attachment); | 280 m_attachments.remove(attachment); |
| 281 drawBuffersIfNecessary(false); | 281 drawBuffersIfNecessary(false); |
| 282 switch (attachment) { | 282 switch (attachment) { |
| 283 case GL_DEPTH_STENCIL_ATTACHMENT: | 283 case GL_DEPTH_STENCIL_ATTACHMENT: |
| 284 attach(target, GL_DEPTH_ATTACHMENT, GL_DEPTH_ATTACHMENT); | 284 attach(target, GL_DEPTH_ATTACHMENT, GL_DEPTH_ATTACHMENT); |
| 285 attach(target, GL_STENCIL_ATTACHMENT, GL_STENCIL_ATTACHMENT); | 285 attach(target, GL_STENCIL_ATTACHMENT, GL_STENCIL_ATTACHMENT); |
| 286 break; | 286 break; |
| 287 case GL_DEPTH_ATTACHMENT: | 287 case GL_DEPTH_ATTACHMENT: |
| 288 case GL_STENCIL_ATTACHMENT: | 288 case GL_STENCIL_ATTACHMENT: |
| 289 attach(target, GL_DEPTH_STENCIL_ATTACHMENT, GL_DEPTH_STENCIL_ATTACHM
ENT); | 289 attach(target, GL_DEPTH_STENCIL_ATTACHMENT, GL_DEPTH_STENCIL_ATTACHM
ENT); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 } | 349 } |
| 350 | 350 |
| 351 bool WebGLFramebuffer::hasStencilBuffer() const | 351 bool WebGLFramebuffer::hasStencilBuffer() const |
| 352 { | 352 { |
| 353 WebGLAttachment* attachment = getAttachment(GL_STENCIL_ATTACHMENT); | 353 WebGLAttachment* attachment = getAttachment(GL_STENCIL_ATTACHMENT); |
| 354 if (!attachment) | 354 if (!attachment) |
| 355 attachment = getAttachment(GL_DEPTH_STENCIL_ATTACHMENT); | 355 attachment = getAttachment(GL_DEPTH_STENCIL_ATTACHMENT); |
| 356 return attachment && attachment->valid(); | 356 return attachment && attachment->valid(); |
| 357 } | 357 } |
| 358 | 358 |
| 359 void WebGLFramebuffer::deleteObjectImpl(WebGraphicsContext3D* context3d, gpu::gl
es2::GLES2Interface* gl) | 359 void WebGLFramebuffer::deleteObjectImpl(gpu::gles2::GLES2Interface* gl) |
| 360 { | 360 { |
| 361 // Both the AttachmentMap and its WebGLAttachment objects are GCed | 361 // Both the AttachmentMap and its WebGLAttachment objects are GCed |
| 362 // objects and cannot be accessed after the destructor has been | 362 // objects and cannot be accessed after the destructor has been |
| 363 // entered, as they may have been finalized already during the | 363 // entered, as they may have been finalized already during the |
| 364 // same GC sweep. These attachments' OpenGL objects will be fully | 364 // same GC sweep. These attachments' OpenGL objects will be fully |
| 365 // destroyed once their JavaScript wrappers are collected. | 365 // destroyed once their JavaScript wrappers are collected. |
| 366 if (!m_destructionInProgress) { | 366 if (!m_destructionInProgress) { |
| 367 for (const auto& attachment : m_attachments) | 367 for (const auto& attachment : m_attachments) |
| 368 attachment.value->onDetached(context3d, gl); | 368 attachment.value->onDetached(gl); |
| 369 } | 369 } |
| 370 | 370 |
| 371 gl->DeleteFramebuffers(1, &m_object); | 371 gl->DeleteFramebuffers(1, &m_object); |
| 372 m_object = 0; | 372 m_object = 0; |
| 373 } | 373 } |
| 374 | 374 |
| 375 bool WebGLFramebuffer::isBound(GLenum target) const | 375 bool WebGLFramebuffer::isBound(GLenum target) const |
| 376 { | 376 { |
| 377 return (context()->getFramebufferBinding(target) == this); | 377 return (context()->getFramebufferBinding(target) == this); |
| 378 } | 378 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 return GL_NONE; | 423 return GL_NONE; |
| 424 } | 424 } |
| 425 | 425 |
| 426 DEFINE_TRACE(WebGLFramebuffer) | 426 DEFINE_TRACE(WebGLFramebuffer) |
| 427 { | 427 { |
| 428 visitor->trace(m_attachments); | 428 visitor->trace(m_attachments); |
| 429 WebGLContextObject::trace(visitor); | 429 WebGLContextObject::trace(visitor); |
| 430 } | 430 } |
| 431 | 431 |
| 432 } // namespace blink | 432 } // namespace blink |
| OLD | NEW |