Mir
buffer.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2012,2013 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by:
17  * Kevin DuBois <kevin.dubois@canonical.com>
18  */
19 
20 #ifndef MIR_GRAPHICS_ANDROID_BUFFER_H_
21 #define MIR_GRAPHICS_ANDROID_BUFFER_H_
22 
24 #include "buffer_usage.h"
25 
26 #include <hardware/gralloc.h>
27 
28 #include <mutex>
29 #include <condition_variable>
30 #include <map>
31 
32 #define GL_GLEXT_PROTOTYPES
33 #define EGL_EGLEXT_PROTOTYPES
34 #include <EGL/egl.h>
35 #include <EGL/eglext.h>
36 
37 namespace mir
38 {
39 namespace graphics
40 {
41 struct EGLExtensions;
42 namespace android
43 {
44 
45 class Buffer: public BufferBasic
46 {
47 public:
48  Buffer(gralloc_module_t const* hw_module,
49  std::shared_ptr<NativeBuffer> const& buffer_handle,
50  std::shared_ptr<EGLExtensions> const& extensions);
51  ~Buffer();
52 
53  geometry::Size size() const override;
54  geometry::Stride stride() const override;
55  MirPixelFormat pixel_format() const override;
56  void gl_bind_to_texture() override;
57  bool can_bypass() const override;
58 
59  //note, you will get the native representation of an android buffer, including
60  //the fences associated with the buffer. You must close these fences
61  std::shared_ptr<NativeBuffer> native_buffer_handle() const override;
62 
63  void write(unsigned char const* pixels, size_t size) override;
64 
65 private:
66  gralloc_module_t const* hw_module;
67 
68  typedef std::pair<EGLDisplay, EGLContext> DispContextPair;
69  std::map<DispContextPair,EGLImageKHR> egl_image_map;
70 
71  std::mutex mutable content_lock;
72  std::shared_ptr<NativeBuffer> native_buffer;
73  std::shared_ptr<EGLExtensions> egl_extensions;
74 };
75 
76 }
77 }
78 }
79 
80 #endif /* MIR_GRAPHICS_ANDROID_BUFFER_H_ */
Definition: size.h:30
All things Mir.
Definition: buffer_stream.h:37
MirPixelFormat pixel_format() const override
Definition: buffer.cpp:67
void gl_bind_to_texture() override
Definition: buffer.cpp:78
std::shared_ptr< NativeBuffer > native_buffer_handle() const override
Definition: buffer.cpp:126
~Buffer()
Definition: buffer.cpp:45
MirPixelFormat
The order of components in a format enum matches the order of the components as they would be written...
Definition: common.h:127
geometry::Stride stride() const override
Definition: buffer.cpp:60
Definition: buffer.h:45
Definition: buffer_basic.h:29
Definition: android_input_receiver.h:32
geometry::Size size() const override
Definition: buffer.cpp:54
Definition: dimensions.h:38
void write(unsigned char const *pixels, size_t size) override
Definition: buffer.cpp:142
bool can_bypass() const override
Definition: buffer.cpp:73

Copyright © 2012,2013 Canonical Ltd.
Generated on Tue Mar 24 16:15:19 UTC 2015