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 
25 
26 #include <hardware/gralloc.h>
27 
28 #include <mutex>
29 #include <condition_variable>
30 #include <map>
31 
32 #ifndef GL_GLEXT_PROTOTYPES
33 #define GL_GLEXT_PROTOTYPES
34 #endif
35 #define EGL_EGLEXT_PROTOTYPES
36 #include <EGL/egl.h>
37 #include <EGL/eglext.h>
38 
39 namespace mir
40 {
41 namespace graphics
42 {
43 struct EGLExtensions;
44 namespace android
45 {
46 
47 class Buffer: public BufferBasic, public NativeBufferBase,
49 {
50 public:
51  Buffer(gralloc_module_t const* hw_module,
52  std::shared_ptr<NativeBuffer> const& buffer_handle,
53  std::shared_ptr<EGLExtensions> const& extensions);
54  ~Buffer();
55 
56  geometry::Size size() const override;
57  geometry::Stride stride() const override;
58  MirPixelFormat pixel_format() const override;
59  void gl_bind_to_texture() override;
60  void bind() override;
61  void secure_for_render() override;
62 
63 
64  //note, you will get the native representation of an android buffer, including
65  //the fences associated with the buffer. You must close these fences
66  std::shared_ptr<NativeBuffer> native_buffer_handle() const override;
67 
68  void write(unsigned char const* pixels, size_t size) override;
69  void read(std::function<void(unsigned char const*)> const&) override;
70 
72 
73 private:
74  void bind(std::unique_lock<std::mutex> const&);
75  void secure_for_render(std::unique_lock<std::mutex> const&);
76  gralloc_module_t const* hw_module;
77 
78  typedef std::pair<EGLDisplay, EGLContext> DispContextPair;
79  std::map<DispContextPair,EGLImageKHR> egl_image_map;
80 
81  std::mutex mutable content_lock;
82  std::shared_ptr<NativeBuffer> native_buffer;
83  std::shared_ptr<EGLExtensions> egl_extensions;
84 };
85 
86 }
87 }
88 }
89 
90 #endif /* MIR_GRAPHICS_ANDROID_BUFFER_H_ */
Definition: size.h:30
All things Mir.
Definition: atomic_callback.h:25
Definition: texture_source.h:31
void read(std::function< void(unsigned char const *)> const &) override
Definition: buffer.cpp:179
MirPixelFormat pixel_format() const override
Definition: buffer.cpp:68
~Buffer()
Definition: buffer.cpp:46
NativeBufferBase * native_buffer_base() override
Definition: buffer.cpp:203
Definition: buffer.h:35
geometry::Size size() const override
Definition: buffer.cpp:55
std::shared_ptr< NativeBuffer > native_buffer_handle() const override
Definition: buffer.cpp:130
geometry::Stride stride() const override
Definition: buffer.cpp:61
void secure_for_render() override
Definition: buffer.cpp:208
void write(unsigned char const *pixels, size_t size) override
Definition: buffer.cpp:146
MirPixelFormat
32-bit pixel formats (8888): The order of components in the enum matches the order of the components ...
Definition: common.h:134
void gl_bind_to_texture() override
Definition: buffer.cpp:74
Definition: buffer.h:47
Definition: buffer_basic.h:29
Definition: android_input_receiver.h:36
Definition: dimensions.h:36
void bind() override
Definition: buffer.cpp:81

Copyright © 2012-2015 Canonical Ltd.
Generated on Thu Sep 8 14:50:19 UTC 2016