| 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 20 matching lines...) Expand all Loading... |
| 31 #include "modules/webgl/WebGLRenderingContextBase.h" | 31 #include "modules/webgl/WebGLRenderingContextBase.h" |
| 32 #include "modules/webgl/WebGLTexture.h" | 32 #include "modules/webgl/WebGLTexture.h" |
| 33 #include "platform/NotImplemented.h" | 33 #include "platform/NotImplemented.h" |
| 34 | 34 |
| 35 namespace blink { | 35 namespace blink { |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 class WebGLRenderbufferAttachment final : public WebGLFramebuffer::WebGLAttachme
nt { | 39 class WebGLRenderbufferAttachment final : public WebGLFramebuffer::WebGLAttachme
nt { |
| 40 public: | 40 public: |
| 41 static WebGLFramebuffer::WebGLAttachment* create(WebGLRenderbuffer*); | 41 static PassRefPtrWillBeRawPtr<WebGLFramebuffer::WebGLAttachment> create(WebG
LRenderbuffer*); |
| 42 | 42 |
| 43 DECLARE_VIRTUAL_TRACE(); | 43 DECLARE_VIRTUAL_TRACE(); |
| 44 | 44 |
| 45 private: | 45 private: |
| 46 explicit WebGLRenderbufferAttachment(WebGLRenderbuffer*); | 46 explicit WebGLRenderbufferAttachment(WebGLRenderbuffer*); |
| 47 WebGLRenderbufferAttachment() { } | 47 WebGLRenderbufferAttachment() { } |
| 48 | 48 |
| 49 GLsizei width() const override; | 49 GLsizei width() const override; |
| 50 GLsizei height() const override; | 50 GLsizei height() const override; |
| 51 GLenum format() const override; | 51 GLenum format() const override; |
| 52 GLenum type() const override; | 52 GLenum type() const override; |
| 53 WebGLSharedObject* object() const override; | 53 WebGLSharedObject* object() const override; |
| 54 bool isSharedObject(WebGLSharedObject*) const override; | 54 bool isSharedObject(WebGLSharedObject*) const override; |
| 55 bool valid() const override; | 55 bool valid() const override; |
| 56 void onDetached(WebGraphicsContext3D*) override; | 56 void onDetached(WebGraphicsContext3D*) override; |
| 57 void attach(WebGraphicsContext3D*, GLenum target, GLenum attachment) overrid
e; | 57 void attach(WebGraphicsContext3D*, GLenum target, GLenum attachment) overrid
e; |
| 58 void unattach(WebGraphicsContext3D*, GLenum target, GLenum attachment) overr
ide; | 58 void unattach(WebGraphicsContext3D*, GLenum target, GLenum attachment) overr
ide; |
| 59 | 59 |
| 60 Member<WebGLRenderbuffer> m_renderbuffer; | 60 RefPtrWillBeMember<WebGLRenderbuffer> m_renderbuffer; |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 WebGLFramebuffer::WebGLAttachment* WebGLRenderbufferAttachment::create(WebGLRend
erbuffer* renderbuffer) | 63 PassRefPtrWillBeRawPtr<WebGLFramebuffer::WebGLAttachment> WebGLRenderbufferAttac
hment::create(WebGLRenderbuffer* renderbuffer) |
| 64 { | 64 { |
| 65 return new WebGLRenderbufferAttachment(renderbuffer); | 65 return adoptRefWillBeNoop(new WebGLRenderbufferAttachment(renderbuffer)); |
| 66 } | 66 } |
| 67 | 67 |
| 68 DEFINE_TRACE(WebGLRenderbufferAttachment) | 68 DEFINE_TRACE(WebGLRenderbufferAttachment) |
| 69 { | 69 { |
| 70 visitor->trace(m_renderbuffer); | 70 visitor->trace(m_renderbuffer); |
| 71 WebGLFramebuffer::WebGLAttachment::trace(visitor); | 71 WebGLFramebuffer::WebGLAttachment::trace(visitor); |
| 72 } | 72 } |
| 73 | 73 |
| 74 WebGLRenderbufferAttachment::WebGLRenderbufferAttachment(WebGLRenderbuffer* rend
erbuffer) | 74 WebGLRenderbufferAttachment::WebGLRenderbufferAttachment(WebGLRenderbuffer* rend
erbuffer) |
| 75 : m_renderbuffer(renderbuffer) | 75 : m_renderbuffer(renderbuffer) |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) { | 133 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) { |
| 134 context->framebufferRenderbuffer(target, GL_DEPTH_ATTACHMENT, GL_RENDERB
UFFER, 0); | 134 context->framebufferRenderbuffer(target, GL_DEPTH_ATTACHMENT, GL_RENDERB
UFFER, 0); |
| 135 context->framebufferRenderbuffer(target, GL_STENCIL_ATTACHMENT, GL_RENDE
RBUFFER, 0); | 135 context->framebufferRenderbuffer(target, GL_STENCIL_ATTACHMENT, GL_RENDE
RBUFFER, 0); |
| 136 } else { | 136 } else { |
| 137 context->framebufferRenderbuffer(target, attachment, GL_RENDERBUFFER, 0)
; | 137 context->framebufferRenderbuffer(target, attachment, GL_RENDERBUFFER, 0)
; |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 | 140 |
| 141 GLenum WebGLRenderbufferAttachment::type() const | 141 GLenum WebGLRenderbufferAttachment::type() const |
| 142 { | 142 { |
| 143 notImplemented(); | |
| 144 return 0; | 143 return 0; |
| 145 } | 144 } |
| 146 | 145 |
| 147 class WebGLTextureAttachment final : public WebGLFramebuffer::WebGLAttachment { | 146 class WebGLTextureAttachment final : public WebGLFramebuffer::WebGLAttachment { |
| 148 public: | 147 public: |
| 149 static WebGLFramebuffer::WebGLAttachment* create(WebGLTexture*, GLenum targe
t, GLint level); | 148 static PassRefPtrWillBeRawPtr<WebGLFramebuffer::WebGLAttachment> create(WebG
LTexture*, GLenum target, GLint level); |
| 150 | 149 |
| 151 DECLARE_VIRTUAL_TRACE(); | 150 DECLARE_VIRTUAL_TRACE(); |
| 152 | 151 |
| 153 private: | 152 private: |
| 154 WebGLTextureAttachment(WebGLTexture*, GLenum target, GLint level); | 153 WebGLTextureAttachment(WebGLTexture*, GLenum target, GLint level); |
| 155 WebGLTextureAttachment() { } | 154 WebGLTextureAttachment() { } |
| 156 | 155 |
| 157 GLsizei width() const override; | 156 GLsizei width() const override; |
| 158 GLsizei height() const override; | 157 GLsizei height() const override; |
| 159 GLenum format() const override; | 158 GLenum format() const override; |
| 160 GLenum type() const override; | 159 GLenum type() const override; |
| 161 WebGLSharedObject* object() const override; | 160 WebGLSharedObject* object() const override; |
| 162 bool isSharedObject(WebGLSharedObject*) const override; | 161 bool isSharedObject(WebGLSharedObject*) const override; |
| 163 bool valid() const override; | 162 bool valid() const override; |
| 164 void onDetached(WebGraphicsContext3D*) override; | 163 void onDetached(WebGraphicsContext3D*) override; |
| 165 void attach(WebGraphicsContext3D*, GLenum target, GLenum attachment) overrid
e; | 164 void attach(WebGraphicsContext3D*, GLenum target, GLenum attachment) overrid
e; |
| 166 void unattach(WebGraphicsContext3D*, GLenum target, GLenum attachment) overr
ide; | 165 void unattach(WebGraphicsContext3D*, GLenum target, GLenum attachment) overr
ide; |
| 167 | 166 |
| 168 Member<WebGLTexture> m_texture; | 167 RefPtrWillBeMember<WebGLTexture> m_texture; |
| 169 GLenum m_target; | 168 GLenum m_target; |
| 170 GLint m_level; | 169 GLint m_level; |
| 171 }; | 170 }; |
| 172 | 171 |
| 173 WebGLFramebuffer::WebGLAttachment* WebGLTextureAttachment::create(WebGLTexture*
texture, GLenum target, GLint level) | 172 PassRefPtrWillBeRawPtr<WebGLFramebuffer::WebGLAttachment> WebGLTextureAttachment
::create(WebGLTexture* texture, GLenum target, GLint level) |
| 174 { | 173 { |
| 175 return new WebGLTextureAttachment(texture, target, level); | 174 return adoptRefWillBeNoop(new WebGLTextureAttachment(texture, target, level)
); |
| 176 } | 175 } |
| 177 | 176 |
| 178 DEFINE_TRACE(WebGLTextureAttachment) | 177 DEFINE_TRACE(WebGLTextureAttachment) |
| 179 { | 178 { |
| 180 visitor->trace(m_texture); | 179 visitor->trace(m_texture); |
| 181 WebGLFramebuffer::WebGLAttachment::trace(visitor); | 180 WebGLFramebuffer::WebGLAttachment::trace(visitor); |
| 182 } | 181 } |
| 183 | 182 |
| 184 WebGLTextureAttachment::WebGLTextureAttachment(WebGLTexture* texture, GLenum tar
get, GLint level) | 183 WebGLTextureAttachment::WebGLTextureAttachment(WebGLTexture* texture, GLenum tar
get, GLint level) |
| 185 : m_texture(texture) | 184 : m_texture(texture) |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 } // anonymous namespace | 317 } // anonymous namespace |
| 319 | 318 |
| 320 WebGLFramebuffer::WebGLAttachment::WebGLAttachment() | 319 WebGLFramebuffer::WebGLAttachment::WebGLAttachment() |
| 321 { | 320 { |
| 322 } | 321 } |
| 323 | 322 |
| 324 WebGLFramebuffer::WebGLAttachment::~WebGLAttachment() | 323 WebGLFramebuffer::WebGLAttachment::~WebGLAttachment() |
| 325 { | 324 { |
| 326 } | 325 } |
| 327 | 326 |
| 328 WebGLFramebuffer* WebGLFramebuffer::create(WebGLRenderingContextBase* ctx) | 327 PassRefPtrWillBeRawPtr<WebGLFramebuffer> WebGLFramebuffer::create(WebGLRendering
ContextBase* ctx) |
| 329 { | 328 { |
| 330 return new WebGLFramebuffer(ctx); | 329 return adoptRefWillBeNoop(new WebGLFramebuffer(ctx)); |
| 331 } | 330 } |
| 332 | 331 |
| 333 WebGLFramebuffer::WebGLFramebuffer(WebGLRenderingContextBase* ctx) | 332 WebGLFramebuffer::WebGLFramebuffer(WebGLRenderingContextBase* ctx) |
| 334 : WebGLContextObject(ctx) | 333 : WebGLContextObject(ctx) |
| 335 , m_object(ctx->webContext()->createFramebuffer()) | 334 , m_object(ctx->webContext()->createFramebuffer()) |
| 336 , m_hasEverBeenBound(false) | 335 , m_hasEverBeenBound(false) |
| 337 , m_readBuffer(GL_COLOR_ATTACHMENT0) | 336 , m_readBuffer(GL_COLOR_ATTACHMENT0) |
| 338 { | 337 { |
| 339 } | 338 } |
| 340 | 339 |
| 341 WebGLFramebuffer::~WebGLFramebuffer() | 340 WebGLFramebuffer::~WebGLFramebuffer() |
| 342 { | 341 { |
| 343 // Attachments in |m_attachments| will be deleted from other places, so we | 342 // Delete the platform framebuffer resource. Explicit detachment |
| 344 // clear it to avoid deleting those attachments in detachAndDeleteObject(). | 343 // is for the benefit of Oilpan, where the framebuffer object |
| 345 m_attachments.clear(); | 344 // isn't detached when it and the WebGLRenderingContextBase object |
| 346 | 345 // it is registered with are both finalized. Without Oilpan, the |
| 347 // See the comment in WebGLObject::detachAndDeleteObject(). | 346 // object will have been detached. |
| 347 // |
| 348 // To keep the code regular, the trivial detach()ment is always |
| 349 // performed. |
| 348 detachAndDeleteObject(); | 350 detachAndDeleteObject(); |
| 349 } | 351 } |
| 350 | 352 |
| 351 void WebGLFramebuffer::setAttachmentForBoundFramebuffer(GLenum target, GLenum at
tachment, GLenum texTarget, WebGLTexture* texture, GLint level) | 353 void WebGLFramebuffer::setAttachmentForBoundFramebuffer(GLenum target, GLenum at
tachment, GLenum texTarget, WebGLTexture* texture, GLint level) |
| 352 { | 354 { |
| 353 ASSERT(isBound(target)); | 355 ASSERT(isBound(target)); |
| 354 removeAttachmentFromBoundFramebuffer(target, attachment); | 356 removeAttachmentFromBoundFramebuffer(target, attachment); |
| 355 if (!m_object) | 357 if (!m_object) |
| 356 return; | 358 return; |
| 357 if (texture && texture->object()) { | 359 if (texture && texture->object()) { |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 bool WebGLFramebuffer::hasStencilBuffer() const | 574 bool WebGLFramebuffer::hasStencilBuffer() const |
| 573 { | 575 { |
| 574 WebGLAttachment* attachment = getAttachment(GL_STENCIL_ATTACHMENT); | 576 WebGLAttachment* attachment = getAttachment(GL_STENCIL_ATTACHMENT); |
| 575 if (!attachment) | 577 if (!attachment) |
| 576 attachment = getAttachment(GL_DEPTH_STENCIL_ATTACHMENT); | 578 attachment = getAttachment(GL_DEPTH_STENCIL_ATTACHMENT); |
| 577 return attachment && attachment->valid(); | 579 return attachment && attachment->valid(); |
| 578 } | 580 } |
| 579 | 581 |
| 580 void WebGLFramebuffer::deleteObjectImpl(WebGraphicsContext3D* context3d) | 582 void WebGLFramebuffer::deleteObjectImpl(WebGraphicsContext3D* context3d) |
| 581 { | 583 { |
| 582 // Both the AttachmentMap and its WebGLAttachment objects are GCed | 584 #if !ENABLE(OILPAN) |
| 583 // objects and cannot be accessed, as they may have been finalized | 585 // With Oilpan, both the AttachmentMap and its WebGLAttachment objects are |
| 586 // GCed objects and cannot be accessed, as they may have been finalized |
| 584 // already during the same GC sweep. | 587 // already during the same GC sweep. |
| 588 // |
| 589 // The WebGLAttachment-derived classes instead handle detachment |
| 590 // on their own when finalizing, so the explicit notification is |
| 591 // not needed. |
| 585 for (const auto& attachment : m_attachments) | 592 for (const auto& attachment : m_attachments) |
| 586 attachment.value->onDetached(context3d); | 593 attachment.value->onDetached(context3d); |
| 594 #endif |
| 587 | 595 |
| 588 context3d->deleteFramebuffer(m_object); | 596 context3d->deleteFramebuffer(m_object); |
| 589 m_object = 0; | 597 m_object = 0; |
| 590 } | 598 } |
| 591 | 599 |
| 592 bool WebGLFramebuffer::isBound(GLenum target) const | 600 bool WebGLFramebuffer::isBound(GLenum target) const |
| 593 { | 601 { |
| 594 return (context()->getFramebufferBinding(target) == this); | 602 return (context()->getFramebufferBinding(target) == this); |
| 595 } | 603 } |
| 596 | 604 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 return false; | 656 return false; |
| 649 if (format) | 657 if (format) |
| 650 *format = image->format(); | 658 *format = image->format(); |
| 651 if (type) | 659 if (type) |
| 652 *type = image->type(); | 660 *type = image->type(); |
| 653 return true; | 661 return true; |
| 654 } | 662 } |
| 655 | 663 |
| 656 DEFINE_TRACE(WebGLFramebuffer) | 664 DEFINE_TRACE(WebGLFramebuffer) |
| 657 { | 665 { |
| 666 #if ENABLE(OILPAN) |
| 658 visitor->trace(m_attachments); | 667 visitor->trace(m_attachments); |
| 668 #endif |
| 659 WebGLContextObject::trace(visitor); | 669 WebGLContextObject::trace(visitor); |
| 660 } | 670 } |
| 661 | 671 |
| 662 } | 672 } |
| OLD | NEW |