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

Side by Side Diff: ui/gl/gl_image_io_surface.cc

Issue 301793003: During image destroy, delete textures only if we have a GL context. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: build issues addressed. 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 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gl/gl_image_io_surface.h" 5 #include "ui/gl/gl_image_io_surface.h"
6 6
7 #include "ui/gl/gl_bindings.h" 7 #include "ui/gl/gl_bindings.h"
8 #include "ui/gl/gl_context.h" 8 #include "ui/gl/gl_context.h"
9 9
10 // Note that this must be included after gl_bindings.h to avoid conflicts. 10 // Note that this must be included after gl_bindings.h to avoid conflicts.
11 #include <OpenGL/CGLIOSurface.h> 11 #include <OpenGL/CGLIOSurface.h>
12 12
13 namespace gfx { 13 namespace gfx {
14 14
15 GLImageIOSurface::GLImageIOSurface(const gfx::Size& size) : size_(size) { 15 GLImageIOSurface::GLImageIOSurface(const gfx::Size& size) : size_(size) {
16 } 16 }
17 17
18 GLImageIOSurface::~GLImageIOSurface() { Destroy(); } 18 GLImageIOSurface::~GLImageIOSurface() {
19 DCHECK(!io_surface_);
20 }
19 21
20 bool GLImageIOSurface::Initialize(const gfx::GpuMemoryBufferHandle& handle) { 22 bool GLImageIOSurface::Initialize(const gfx::GpuMemoryBufferHandle& handle) {
21 io_surface_.reset(IOSurfaceLookup(handle.io_surface_id)); 23 io_surface_.reset(IOSurfaceLookup(handle.io_surface_id));
22 if (!io_surface_) { 24 if (!io_surface_) {
23 LOG(ERROR) << "IOSurface lookup failed"; 25 LOG(ERROR) << "IOSurface lookup failed";
24 return false; 26 return false;
25 } 27 }
26 28
27 return true; 29 return true;
28 } 30 }
29 31
32 void GLImageIOSurface::Destroy(bool have_context) {
33 io_surface_.reset();
34 }
35
30 gfx::Size GLImageIOSurface::GetSize() { return size_; } 36 gfx::Size GLImageIOSurface::GetSize() { return size_; }
31 37
32 bool GLImageIOSurface::BindTexImage(unsigned target) { 38 bool GLImageIOSurface::BindTexImage(unsigned target) {
39 if (!io_surface_) {
40 LOG(ERROR) << "Uninitialized image cannot be bound to texture";
41 return false;
42 }
reveman 2014/07/25 19:00:23 Let's keep this as before. Sorry.
sohanjg 2014/07/26 10:42:23 Done.
43
33 if (target != GL_TEXTURE_RECTANGLE_ARB) { 44 if (target != GL_TEXTURE_RECTANGLE_ARB) {
34 // This might be supported in the future. For now, perform strict 45 // This might be supported in the future. For now, perform strict
35 // validation so we know what's going on. 46 // validation so we know what's going on.
36 LOG(ERROR) << "IOSurface requires TEXTURE_RECTANGLE_ARB target"; 47 LOG(ERROR) << "IOSurface requires TEXTURE_RECTANGLE_ARB target";
37 return false; 48 return false;
38 } 49 }
39 50
40 CGLContextObj cgl_context = 51 CGLContextObj cgl_context =
41 static_cast<CGLContextObj>(GLContext::GetCurrent()->GetHandle()); 52 static_cast<CGLContextObj>(GLContext::GetCurrent()->GetHandle());
42 53
43 DCHECK(io_surface_);
44 CGLError cgl_error = CGLTexImageIOSurface2D(cgl_context, 54 CGLError cgl_error = CGLTexImageIOSurface2D(cgl_context,
45 target, 55 target,
46 GL_RGBA, 56 GL_RGBA,
47 size_.width(), 57 size_.width(),
48 size_.height(), 58 size_.height(),
49 GL_BGRA, 59 GL_BGRA,
50 GL_UNSIGNED_INT_8_8_8_8_REV, 60 GL_UNSIGNED_INT_8_8_8_8_REV,
51 io_surface_.get(), 61 io_surface_.get(),
52 0); 62 0);
53 if (cgl_error != kCGLNoError) { 63 if (cgl_error != kCGLNoError) {
54 LOG(ERROR) << "Error in CGLTexImageIOSurface2D"; 64 LOG(ERROR) << "Error in CGLTexImageIOSurface2D";
55 return false; 65 return false;
56 } 66 }
57 67
58 return true; 68 return true;
59 } 69 }
60 70
61 } // namespace gfx 71 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698