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 #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, public NativeBufferBase,
47 {
48 public:
49  Buffer(gralloc_module_t const* hw_module,
50  std::shared_ptr<NativeBuffer> const& buffer_handle,
51  std::shared_ptr<EGLExtensions> const& extensions);
52  ~Buffer();
53 
54  geometry::Size size() const override;
55  geometry::Stride stride() const override;
56  MirPixelFormat pixel_format() const override;
57  void gl_bind_to_texture() override;
58  void bind() override;
59  void secure_for_render() override;
60 
61 
62  //note, you will get the native representation of an android buffer, including
63  //the fences associated with the buffer. You must close these fences
64  std::shared_ptr<NativeBuffer> native_buffer_handle() const override;
65 
66  void write(unsigned char const* pixels, size_t size) override;
67  void read(std::function<void(unsigned char const*)> const&) override;
68 
70 
71 private:
72  void bind(std::unique_lock<std::mutex> const&);
73  void secure_for_render(std::unique_lock<std::mutex> const&);
74  gralloc_module_t const* hw_module;
75 
76  typedef std::pair<EGLDisplay, EGLContext> DispContextPair;
77  std::map<DispContextPair,EGLImageKHR> egl_image_map;
78 
79  std::mutex mutable content_lock;
80  std::shared_ptr<NativeBuffer> native_buffer;
81  std::shared_ptr<EGLExtensions> egl_extensions;
82 };
83 
84 }
85 }
86 }
87 
88 #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:45
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 Wed Mar 30 00:29:56 UTC 2016