Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: Source/core/html/canvas/WebGLFramebuffer.cpp

Issue 365653002: Oilpan: move 2D Canvas and WebGL objects to the heap. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Smaller adjustments Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 23 matching lines...) Expand all
34 34
35 namespace { 35 namespace {
36 36
37 Platform3DObject objectOrZero(WebGLObject* object) 37 Platform3DObject objectOrZero(WebGLObject* object)
38 { 38 {
39 return object ? object->object() : 0; 39 return object ? object->object() : 0;
40 } 40 }
41 41
42 class WebGLRenderbufferAttachment FINAL : public WebGLFramebuffer::WebGLAtta chment { 42 class WebGLRenderbufferAttachment FINAL : public WebGLFramebuffer::WebGLAtta chment {
43 public: 43 public:
44 static PassRefPtr<WebGLFramebuffer::WebGLAttachment> create(WebGLRenderb uffer*); 44 static PassRefPtrWillBeRawPtr<WebGLFramebuffer::WebGLAttachment> create( WebGLRenderbuffer*);
45
46 virtual void trace(Visitor*) OVERRIDE;
45 47
46 private: 48 private:
47 WebGLRenderbufferAttachment(WebGLRenderbuffer*); 49 explicit WebGLRenderbufferAttachment(WebGLRenderbuffer*);
50 WebGLRenderbufferAttachment() { }
51
48 virtual GLsizei width() const OVERRIDE; 52 virtual GLsizei width() const OVERRIDE;
49 virtual GLsizei height() const OVERRIDE; 53 virtual GLsizei height() const OVERRIDE;
50 virtual GLenum format() const OVERRIDE; 54 virtual GLenum format() const OVERRIDE;
51 virtual GLenum type() const OVERRIDE; 55 virtual GLenum type() const OVERRIDE;
52 virtual WebGLSharedObject* object() const OVERRIDE; 56 virtual WebGLSharedObject* object() const OVERRIDE;
53 virtual bool isSharedObject(WebGLSharedObject*) const OVERRIDE; 57 virtual bool isSharedObject(WebGLSharedObject*) const OVERRIDE;
54 virtual bool valid() const OVERRIDE; 58 virtual bool valid() const OVERRIDE;
55 virtual void onDetached(blink::WebGraphicsContext3D*) OVERRIDE; 59 virtual void onDetached(blink::WebGraphicsContext3D*) OVERRIDE;
56 virtual void attach(blink::WebGraphicsContext3D*, GLenum attachment) OVE RRIDE; 60 virtual void attach(blink::WebGraphicsContext3D*, GLenum attachment) OVE RRIDE;
57 virtual void unattach(blink::WebGraphicsContext3D*, GLenum attachment) O VERRIDE; 61 virtual void unattach(blink::WebGraphicsContext3D*, GLenum attachment) O VERRIDE;
58 62
59 WebGLRenderbufferAttachment() { }; 63 RefPtrWillBeMember<WebGLRenderbuffer> m_renderbuffer;
60
61 RefPtr<WebGLRenderbuffer> m_renderbuffer;
62 }; 64 };
63 65
64 PassRefPtr<WebGLFramebuffer::WebGLAttachment> WebGLRenderbufferAttachment::c reate(WebGLRenderbuffer* renderbuffer) 66 PassRefPtrWillBeRawPtr<WebGLFramebuffer::WebGLAttachment> WebGLRenderbufferA ttachment::create(WebGLRenderbuffer* renderbuffer)
65 { 67 {
66 return adoptRef(new WebGLRenderbufferAttachment(renderbuffer)); 68 return adoptRefWillBeNoop(new WebGLRenderbufferAttachment(renderbuffer)) ;
69 }
70
71 void WebGLRenderbufferAttachment::trace(Visitor* visitor)
72 {
73 visitor->trace(m_renderbuffer);
74 WebGLFramebuffer::WebGLAttachment::trace(visitor);
67 } 75 }
68 76
69 WebGLRenderbufferAttachment::WebGLRenderbufferAttachment(WebGLRenderbuffer* renderbuffer) 77 WebGLRenderbufferAttachment::WebGLRenderbufferAttachment(WebGLRenderbuffer* renderbuffer)
70 : m_renderbuffer(renderbuffer) 78 : m_renderbuffer(renderbuffer)
71 { 79 {
72 } 80 }
73 81
74 GLsizei WebGLRenderbufferAttachment::width() const 82 GLsizei WebGLRenderbufferAttachment::width() const
75 { 83 {
76 return m_renderbuffer->width(); 84 return m_renderbuffer->width();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 } 142 }
135 143
136 GLenum WebGLRenderbufferAttachment::type() const 144 GLenum WebGLRenderbufferAttachment::type() const
137 { 145 {
138 notImplemented(); 146 notImplemented();
139 return 0; 147 return 0;
140 } 148 }
141 149
142 class WebGLTextureAttachment FINAL : public WebGLFramebuffer::WebGLAttachmen t { 150 class WebGLTextureAttachment FINAL : public WebGLFramebuffer::WebGLAttachmen t {
143 public: 151 public:
144 static PassRefPtr<WebGLFramebuffer::WebGLAttachment> create(WebGLTexture *, GLenum target, GLint level); 152 static PassRefPtrWillBeRawPtr<WebGLFramebuffer::WebGLAttachment> create( WebGLTexture*, GLenum target, GLint level);
153
154 virtual void trace(Visitor*) OVERRIDE;
145 155
146 private: 156 private:
147 WebGLTextureAttachment(WebGLTexture*, GLenum target, GLint level); 157 WebGLTextureAttachment(WebGLTexture*, GLenum target, GLint level);
158 WebGLTextureAttachment() { }
159
148 virtual GLsizei width() const OVERRIDE; 160 virtual GLsizei width() const OVERRIDE;
149 virtual GLsizei height() const OVERRIDE; 161 virtual GLsizei height() const OVERRIDE;
150 virtual GLenum format() const OVERRIDE; 162 virtual GLenum format() const OVERRIDE;
151 virtual GLenum type() const OVERRIDE; 163 virtual GLenum type() const OVERRIDE;
152 virtual WebGLSharedObject* object() const OVERRIDE; 164 virtual WebGLSharedObject* object() const OVERRIDE;
153 virtual bool isSharedObject(WebGLSharedObject*) const OVERRIDE; 165 virtual bool isSharedObject(WebGLSharedObject*) const OVERRIDE;
154 virtual bool valid() const OVERRIDE; 166 virtual bool valid() const OVERRIDE;
155 virtual void onDetached(blink::WebGraphicsContext3D*) OVERRIDE; 167 virtual void onDetached(blink::WebGraphicsContext3D*) OVERRIDE;
156 virtual void attach(blink::WebGraphicsContext3D*, GLenum attachment) OVE RRIDE; 168 virtual void attach(blink::WebGraphicsContext3D*, GLenum attachment) OVE RRIDE;
157 virtual void unattach(blink::WebGraphicsContext3D*, GLenum attachment) O VERRIDE; 169 virtual void unattach(blink::WebGraphicsContext3D*, GLenum attachment) O VERRIDE;
158 170
159 WebGLTextureAttachment() { }; 171 RefPtrWillBeMember<WebGLTexture> m_texture;
160
161 RefPtr<WebGLTexture> m_texture;
162 GLenum m_target; 172 GLenum m_target;
163 GLint m_level; 173 GLint m_level;
164 }; 174 };
165 175
166 PassRefPtr<WebGLFramebuffer::WebGLAttachment> WebGLTextureAttachment::create (WebGLTexture* texture, GLenum target, GLint level) 176 PassRefPtrWillBeRawPtr<WebGLFramebuffer::WebGLAttachment> WebGLTextureAttach ment::create(WebGLTexture* texture, GLenum target, GLint level)
167 { 177 {
168 return adoptRef(new WebGLTextureAttachment(texture, target, level)); 178 return adoptRefWillBeNoop(new WebGLTextureAttachment(texture, target, le vel));
179 }
180
181 void WebGLTextureAttachment::trace(Visitor* visitor)
182 {
183 visitor->trace(m_texture);
184 WebGLFramebuffer::WebGLAttachment::trace(visitor);
169 } 185 }
170 186
171 WebGLTextureAttachment::WebGLTextureAttachment(WebGLTexture* texture, GLenum target, GLint level) 187 WebGLTextureAttachment::WebGLTextureAttachment(WebGLTexture* texture, GLenum target, GLint level)
172 : m_texture(texture) 188 : m_texture(texture)
173 , m_target(target) 189 , m_target(target)
174 , m_level(level) 190 , m_level(level)
175 { 191 {
176 } 192 }
177 193
178 GLsizei WebGLTextureAttachment::width() const 194 GLsizei WebGLTextureAttachment::width() const
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 } // anonymous namespace 262 } // anonymous namespace
247 263
248 WebGLFramebuffer::WebGLAttachment::WebGLAttachment() 264 WebGLFramebuffer::WebGLAttachment::WebGLAttachment()
249 { 265 {
250 } 266 }
251 267
252 WebGLFramebuffer::WebGLAttachment::~WebGLAttachment() 268 WebGLFramebuffer::WebGLAttachment::~WebGLAttachment()
253 { 269 {
254 } 270 }
255 271
256 PassRefPtr<WebGLFramebuffer> WebGLFramebuffer::create(WebGLRenderingContextBase* ctx) 272 PassRefPtrWillBeRawPtr<WebGLFramebuffer> WebGLFramebuffer::create(WebGLRendering ContextBase* ctx)
257 { 273 {
258 return adoptRef(new WebGLFramebuffer(ctx)); 274 return adoptRefWillBeNoop(new WebGLFramebuffer(ctx));
259 } 275 }
260 276
261 WebGLFramebuffer::WebGLFramebuffer(WebGLRenderingContextBase* ctx) 277 WebGLFramebuffer::WebGLFramebuffer(WebGLRenderingContextBase* ctx)
262 : WebGLContextObject(ctx) 278 : WebGLContextObject(ctx)
263 , m_hasEverBeenBound(false) 279 , m_hasEverBeenBound(false)
264 { 280 {
265 ScriptWrappable::init(this); 281 ScriptWrappable::init(this);
266 setObject(ctx->webContext()->createFramebuffer()); 282 setObject(ctx->webContext()->createFramebuffer());
267 } 283 }
268 284
269 WebGLFramebuffer::~WebGLFramebuffer() 285 WebGLFramebuffer::~WebGLFramebuffer()
270 { 286 {
271 deleteObject(0); 287 // Delete the platform framebuffer resource. Explicit detachment
288 // is for the benefit of Oilpan, where the framebuffer object
289 // isn't detached when it and the WebGLRenderingContextBase object
290 // it is registered with are both finalized. Without Oilpan, the
291 // object will have been detached.
292 //
293 // To keep the code regular, the trivial detach()ment is always
294 // performed.
295 detachAndDeleteObject();
272 } 296 }
273 297
274 void WebGLFramebuffer::setAttachmentForBoundFramebuffer(GLenum attachment, GLenu m texTarget, WebGLTexture* texture, GLint level) 298 void WebGLFramebuffer::setAttachmentForBoundFramebuffer(GLenum attachment, GLenu m texTarget, WebGLTexture* texture, GLint level)
275 { 299 {
276 ASSERT(isBound()); 300 ASSERT(isBound());
277 removeAttachmentFromBoundFramebuffer(attachment); 301 removeAttachmentFromBoundFramebuffer(attachment);
278 if (!object()) 302 if (!object())
279 return; 303 return;
280 if (texture && texture->object()) { 304 if (texture && texture->object()) {
281 m_attachments.add(attachment, WebGLTextureAttachment::create(texture, te xTarget, level)); 305 m_attachments.add(attachment, WebGLTextureAttachment::create(texture, te xTarget, level));
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 bool WebGLFramebuffer::hasStencilBuffer() const 556 bool WebGLFramebuffer::hasStencilBuffer() const
533 { 557 {
534 WebGLAttachment* attachment = getAttachment(GL_STENCIL_ATTACHMENT); 558 WebGLAttachment* attachment = getAttachment(GL_STENCIL_ATTACHMENT);
535 if (!attachment) 559 if (!attachment)
536 attachment = getAttachment(GC3D_DEPTH_STENCIL_ATTACHMENT_WEBGL); 560 attachment = getAttachment(GC3D_DEPTH_STENCIL_ATTACHMENT_WEBGL);
537 return attachment && attachment->valid(); 561 return attachment && attachment->valid();
538 } 562 }
539 563
540 void WebGLFramebuffer::deleteObjectImpl(blink::WebGraphicsContext3D* context3d, Platform3DObject object) 564 void WebGLFramebuffer::deleteObjectImpl(blink::WebGraphicsContext3D* context3d, Platform3DObject object)
541 { 565 {
566 #if !ENABLE(OILPAN)
567 // With Oilpan, both the AttachmentMap and its WebGLAttachment objects are
568 // GCed objects and cannot be accessed, as they may have been finalized
569 // already during the same GC sweep.
570 //
571 // The WebGLAttachment-derived classes instead handle detachment
572 // on their own when finalizing, so the explicit notification is
573 // not needed.
542 for (AttachmentMap::iterator it = m_attachments.begin(); it != m_attachments .end(); ++it) 574 for (AttachmentMap::iterator it = m_attachments.begin(); it != m_attachments .end(); ++it)
543 it->value->onDetached(context3d); 575 it->value->onDetached(context3d);
576 #endif
544 577
545 context3d->deleteFramebuffer(object); 578 context3d->deleteFramebuffer(object);
546 } 579 }
547 580
548 bool WebGLFramebuffer::isBound() const 581 bool WebGLFramebuffer::isBound() const
549 { 582 {
550 return (context()->m_framebufferBinding.get() == this); 583 return (context()->m_framebufferBinding.get() == this);
551 } 584 }
552 585
553 void WebGLFramebuffer::drawBuffers(const Vector<GLenum>& bufs) 586 void WebGLFramebuffer::drawBuffers(const Vector<GLenum>& bufs)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 { 621 {
589 int index = static_cast<int>(drawBuffer - GL_DRAW_BUFFER0_EXT); 622 int index = static_cast<int>(drawBuffer - GL_DRAW_BUFFER0_EXT);
590 ASSERT(index >= 0); 623 ASSERT(index >= 0);
591 if (index < static_cast<int>(m_drawBuffers.size())) 624 if (index < static_cast<int>(m_drawBuffers.size()))
592 return m_drawBuffers[index]; 625 return m_drawBuffers[index];
593 if (drawBuffer == GL_DRAW_BUFFER0_EXT) 626 if (drawBuffer == GL_DRAW_BUFFER0_EXT)
594 return GL_COLOR_ATTACHMENT0; 627 return GL_COLOR_ATTACHMENT0;
595 return GL_NONE; 628 return GL_NONE;
596 } 629 }
597 630
631 void WebGLFramebuffer::trace(Visitor* visitor)
632 {
633 visitor->trace(m_attachments);
634 WebGLContextObject::trace(visitor);
598 } 635 }
636
637 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698