OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/desktop_capture/mac/scoped_pixel_buffer_object.h" | 11 #include "webrtc/modules/desktop_capture/mac/scoped_pixel_buffer_object.h" |
12 | 12 |
13 #include <stddef.h> | 13 #include <stddef.h> |
14 | 14 |
15 namespace webrtc { | 15 namespace webrtc { |
16 | 16 |
17 ScopedPixelBufferObject::ScopedPixelBufferObject() | 17 ScopedPixelBufferObject::ScopedPixelBufferObject() |
18 : cgl_context_(NULL), | 18 : cgl_context_(nullptr), pixel_buffer_object_(0) {} |
19 pixel_buffer_object_(0) { | |
20 } | |
21 | 19 |
22 ScopedPixelBufferObject::~ScopedPixelBufferObject() { | 20 ScopedPixelBufferObject::~ScopedPixelBufferObject() { |
23 Release(); | 21 Release(); |
24 } | 22 } |
25 | 23 |
26 bool ScopedPixelBufferObject::Init(CGLContextObj cgl_context, | 24 bool ScopedPixelBufferObject::Init(CGLContextObj cgl_context, |
27 int size_in_bytes) { | 25 int size_in_bytes) { |
28 cgl_context_ = cgl_context; | 26 cgl_context_ = cgl_context; |
29 CGLContextObj CGL_MACRO_CONTEXT = cgl_context_; | 27 CGLContextObj CGL_MACRO_CONTEXT = cgl_context_; |
30 glGenBuffersARB(1, &pixel_buffer_object_); | 28 glGenBuffersARB(1, &pixel_buffer_object_); |
31 if (glGetError() == GL_NO_ERROR) { | 29 if (glGetError() == GL_NO_ERROR) { |
32 glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pixel_buffer_object_); | 30 glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pixel_buffer_object_); |
33 glBufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, size_in_bytes, NULL, | 31 glBufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, size_in_bytes, nullptr, |
34 GL_STREAM_READ_ARB); | 32 GL_STREAM_READ_ARB); |
35 glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0); | 33 glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0); |
36 if (glGetError() != GL_NO_ERROR) { | 34 if (glGetError() != GL_NO_ERROR) { |
37 Release(); | 35 Release(); |
38 } | 36 } |
39 } else { | 37 } else { |
40 cgl_context_ = NULL; | 38 cgl_context_ = nullptr; |
41 pixel_buffer_object_ = 0; | 39 pixel_buffer_object_ = 0; |
42 } | 40 } |
43 return pixel_buffer_object_ != 0; | 41 return pixel_buffer_object_ != 0; |
44 } | 42 } |
45 | 43 |
46 void ScopedPixelBufferObject::Release() { | 44 void ScopedPixelBufferObject::Release() { |
47 if (pixel_buffer_object_) { | 45 if (pixel_buffer_object_) { |
48 CGLContextObj CGL_MACRO_CONTEXT = cgl_context_; | 46 CGLContextObj CGL_MACRO_CONTEXT = cgl_context_; |
49 glDeleteBuffersARB(1, &pixel_buffer_object_); | 47 glDeleteBuffersARB(1, &pixel_buffer_object_); |
50 cgl_context_ = NULL; | 48 cgl_context_ = nullptr; |
51 pixel_buffer_object_ = 0; | 49 pixel_buffer_object_ = 0; |
52 } | 50 } |
53 } | 51 } |
54 | 52 |
55 } // namespace webrtc | 53 } // namespace webrtc |
OLD | NEW |