Chromium Code Reviews| 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 PassRefPtrWillBeRawPtr<WebGLFramebuffer::WebGLAttachment> create(WebG LRenderbuffer*); | 41 static WebGLFramebuffer::WebGLAttachment* create(WebGLRenderbuffer*); |
| 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 RefPtrWillBeMember<WebGLRenderbuffer> m_renderbuffer; | 60 Member<WebGLRenderbuffer> m_renderbuffer; |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 PassRefPtrWillBeRawPtr<WebGLFramebuffer::WebGLAttachment> WebGLRenderbufferAttac hment::create(WebGLRenderbuffer* renderbuffer) | 63 WebGLFramebuffer::WebGLAttachment* WebGLRenderbufferAttachment::create(WebGLRend erbuffer* renderbuffer) |
| 64 { | 64 { |
| 65 return adoptRefWillBeNoop(new WebGLRenderbufferAttachment(renderbuffer)); | 65 return 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(); | |
| 143 return 0; | 144 return 0; |
| 144 } | 145 } |
| 145 | 146 |
| 146 class WebGLTextureAttachment final : public WebGLFramebuffer::WebGLAttachment { | 147 class WebGLTextureAttachment final : public WebGLFramebuffer::WebGLAttachment { |
| 147 public: | 148 public: |
| 148 static PassRefPtrWillBeRawPtr<WebGLFramebuffer::WebGLAttachment> create(WebG LTexture*, GLenum target, GLint level); | 149 static WebGLFramebuffer::WebGLAttachment* create(WebGLTexture*, GLenum targe t, GLint level); |
| 149 | 150 |
| 150 DECLARE_VIRTUAL_TRACE(); | 151 DECLARE_VIRTUAL_TRACE(); |
| 151 | 152 |
| 152 private: | 153 private: |
| 153 WebGLTextureAttachment(WebGLTexture*, GLenum target, GLint level); | 154 WebGLTextureAttachment(WebGLTexture*, GLenum target, GLint level); |
| 154 WebGLTextureAttachment() { } | 155 WebGLTextureAttachment() { } |
| 155 | 156 |
| 156 GLsizei width() const override; | 157 GLsizei width() const override; |
| 157 GLsizei height() const override; | 158 GLsizei height() const override; |
| 158 GLenum format() const override; | 159 GLenum format() const override; |
| 159 GLenum type() const override; | 160 GLenum type() const override; |
| 160 WebGLSharedObject* object() const override; | 161 WebGLSharedObject* object() const override; |
| 161 bool isSharedObject(WebGLSharedObject*) const override; | 162 bool isSharedObject(WebGLSharedObject*) const override; |
| 162 bool valid() const override; | 163 bool valid() const override; |
| 163 void onDetached(WebGraphicsContext3D*) override; | 164 void onDetached(WebGraphicsContext3D*) override; |
| 164 void attach(WebGraphicsContext3D*, GLenum target, GLenum attachment) overrid e; | 165 void attach(WebGraphicsContext3D*, GLenum target, GLenum attachment) overrid e; |
| 165 void unattach(WebGraphicsContext3D*, GLenum target, GLenum attachment) overr ide; | 166 void unattach(WebGraphicsContext3D*, GLenum target, GLenum attachment) overr ide; |
| 166 | 167 |
| 167 RefPtrWillBeMember<WebGLTexture> m_texture; | 168 Member<WebGLTexture> m_texture; |
| 168 GLenum m_target; | 169 GLenum m_target; |
| 169 GLint m_level; | 170 GLint m_level; |
| 170 }; | 171 }; |
| 171 | 172 |
| 172 PassRefPtrWillBeRawPtr<WebGLFramebuffer::WebGLAttachment> WebGLTextureAttachment ::create(WebGLTexture* texture, GLenum target, GLint level) | 173 WebGLFramebuffer::WebGLAttachment* WebGLTextureAttachment::create(WebGLTexture* texture, GLenum target, GLint level) |
| 173 { | 174 { |
| 174 return adoptRefWillBeNoop(new WebGLTextureAttachment(texture, target, level) ); | 175 return new WebGLTextureAttachment(texture, target, level); |
| 175 } | 176 } |
| 176 | 177 |
| 177 DEFINE_TRACE(WebGLTextureAttachment) | 178 DEFINE_TRACE(WebGLTextureAttachment) |
| 178 { | 179 { |
| 179 visitor->trace(m_texture); | 180 visitor->trace(m_texture); |
| 180 WebGLFramebuffer::WebGLAttachment::trace(visitor); | 181 WebGLFramebuffer::WebGLAttachment::trace(visitor); |
| 181 } | 182 } |
| 182 | 183 |
| 183 WebGLTextureAttachment::WebGLTextureAttachment(WebGLTexture* texture, GLenum tar get, GLint level) | 184 WebGLTextureAttachment::WebGLTextureAttachment(WebGLTexture* texture, GLenum tar get, GLint level) |
| 184 : m_texture(texture) | 185 : m_texture(texture) |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 } // anonymous namespace | 318 } // anonymous namespace |
| 318 | 319 |
| 319 WebGLFramebuffer::WebGLAttachment::WebGLAttachment() | 320 WebGLFramebuffer::WebGLAttachment::WebGLAttachment() |
| 320 { | 321 { |
| 321 } | 322 } |
| 322 | 323 |
| 323 WebGLFramebuffer::WebGLAttachment::~WebGLAttachment() | 324 WebGLFramebuffer::WebGLAttachment::~WebGLAttachment() |
| 324 { | 325 { |
| 325 } | 326 } |
| 326 | 327 |
| 327 PassRefPtrWillBeRawPtr<WebGLFramebuffer> WebGLFramebuffer::create(WebGLRendering ContextBase* ctx) | 328 WebGLFramebuffer* WebGLFramebuffer::create(WebGLRenderingContextBase* ctx) |
| 328 { | 329 { |
| 329 return adoptRefWillBeNoop(new WebGLFramebuffer(ctx)); | 330 return new WebGLFramebuffer(ctx); |
| 330 } | 331 } |
| 331 | 332 |
| 332 WebGLFramebuffer::WebGLFramebuffer(WebGLRenderingContextBase* ctx) | 333 WebGLFramebuffer::WebGLFramebuffer(WebGLRenderingContextBase* ctx) |
| 333 : WebGLContextObject(ctx) | 334 : WebGLContextObject(ctx) |
| 334 , m_object(ctx->webContext()->createFramebuffer()) | 335 , m_object(ctx->webContext()->createFramebuffer()) |
| 335 , m_hasEverBeenBound(false) | 336 , m_hasEverBeenBound(false) |
| 336 , m_readBuffer(GL_COLOR_ATTACHMENT0) | 337 , m_readBuffer(GL_COLOR_ATTACHMENT0) |
| 337 { | 338 { |
| 338 } | 339 } |
| 339 | 340 |
| 340 WebGLFramebuffer::~WebGLFramebuffer() | 341 WebGLFramebuffer::~WebGLFramebuffer() |
| 341 { | 342 { |
| 342 // Delete the platform framebuffer resource. Explicit detachment | 343 m_attachments.clear(); |
|
sof
2015/08/06 06:46:30
Could you add a comment next to this explaining pu
peria
2015/08/06 07:38:46
Done.
| |
| 343 // is for the benefit of Oilpan, where the framebuffer object | 344 |
| 344 // isn't detached when it and the WebGLRenderingContextBase object | 345 // See the comment in WebGLObject::detachAndDeleteObject(). |
| 345 // it is registered with are both finalized. Without Oilpan, the | |
| 346 // object will have been detached. | |
| 347 // | |
| 348 // To keep the code regular, the trivial detach()ment is always | |
| 349 // performed. | |
| 350 detachAndDeleteObject(); | 346 detachAndDeleteObject(); |
| 351 } | 347 } |
| 352 | 348 |
| 353 void WebGLFramebuffer::setAttachmentForBoundFramebuffer(GLenum target, GLenum at tachment, GLenum texTarget, WebGLTexture* texture, GLint level) | 349 void WebGLFramebuffer::setAttachmentForBoundFramebuffer(GLenum target, GLenum at tachment, GLenum texTarget, WebGLTexture* texture, GLint level) |
| 354 { | 350 { |
| 355 ASSERT(isBound(target)); | 351 ASSERT(isBound(target)); |
| 356 removeAttachmentFromBoundFramebuffer(target, attachment); | 352 removeAttachmentFromBoundFramebuffer(target, attachment); |
| 357 if (!m_object) | 353 if (!m_object) |
| 358 return; | 354 return; |
| 359 if (texture && texture->object()) { | 355 if (texture && texture->object()) { |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 574 bool WebGLFramebuffer::hasStencilBuffer() const | 570 bool WebGLFramebuffer::hasStencilBuffer() const |
| 575 { | 571 { |
| 576 WebGLAttachment* attachment = getAttachment(GL_STENCIL_ATTACHMENT); | 572 WebGLAttachment* attachment = getAttachment(GL_STENCIL_ATTACHMENT); |
| 577 if (!attachment) | 573 if (!attachment) |
| 578 attachment = getAttachment(GL_DEPTH_STENCIL_ATTACHMENT); | 574 attachment = getAttachment(GL_DEPTH_STENCIL_ATTACHMENT); |
| 579 return attachment && attachment->valid(); | 575 return attachment && attachment->valid(); |
| 580 } | 576 } |
| 581 | 577 |
| 582 void WebGLFramebuffer::deleteObjectImpl(WebGraphicsContext3D* context3d) | 578 void WebGLFramebuffer::deleteObjectImpl(WebGraphicsContext3D* context3d) |
| 583 { | 579 { |
| 584 #if !ENABLE(OILPAN) | 580 // Both the AttachmentMap and its WebGLAttachment objects are GCed |
| 585 // With Oilpan, both the AttachmentMap and its WebGLAttachment objects are | 581 // objects and cannot be accessed, as they may have been finalized |
| 586 // GCed objects and cannot be accessed, as they may have been finalized | |
| 587 // already during the same GC sweep. | 582 // already during the same GC sweep. |
| 588 // | 583 // |
| 589 // The WebGLAttachment-derived classes instead handle detachment | 584 // The WebGLAttachment-derived classes instead handle detachment |
| 590 // on their own when finalizing, so the explicit notification is | 585 // on their own when finalizing, so the explicit notification is |
| 591 // not needed. | 586 // not needed. |
| 592 for (const auto& attachment : m_attachments) | 587 if (!m_attachments.isEmpty()) { |
| 593 attachment.value->onDetached(context3d); | 588 for (const auto& attachment : m_attachments) |
| 594 #endif | 589 attachment.value->onDetached(context3d); |
| 590 } | |
| 595 | 591 |
| 596 context3d->deleteFramebuffer(m_object); | 592 context3d->deleteFramebuffer(m_object); |
| 597 m_object = 0; | 593 m_object = 0; |
| 598 } | 594 } |
| 599 | 595 |
| 600 bool WebGLFramebuffer::isBound(GLenum target) const | 596 bool WebGLFramebuffer::isBound(GLenum target) const |
| 601 { | 597 { |
| 602 return (context()->getFramebufferBinding(target) == this); | 598 return (context()->getFramebufferBinding(target) == this); |
| 603 } | 599 } |
| 604 | 600 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 656 return false; | 652 return false; |
| 657 if (format) | 653 if (format) |
| 658 *format = image->format(); | 654 *format = image->format(); |
| 659 if (type) | 655 if (type) |
| 660 *type = image->type(); | 656 *type = image->type(); |
| 661 return true; | 657 return true; |
| 662 } | 658 } |
| 663 | 659 |
| 664 DEFINE_TRACE(WebGLFramebuffer) | 660 DEFINE_TRACE(WebGLFramebuffer) |
| 665 { | 661 { |
| 666 #if ENABLE(OILPAN) | |
| 667 visitor->trace(m_attachments); | 662 visitor->trace(m_attachments); |
| 668 #endif | |
| 669 WebGLContextObject::trace(visitor); | 663 WebGLContextObject::trace(visitor); |
| 670 } | 664 } |
| 671 | 665 |
| 672 } | 666 } |
| OLD | NEW |