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 #include "buffer_usage.h"
26 
27 #include <hardware/gralloc.h>
28 
29 #include <mutex>
30 #include <condition_variable>
31 #include <map>
32 
33 #define GL_GLEXT_PROTOTYPES
34 #define EGL_EGLEXT_PROTOTYPES
35 #include <EGL/egl.h>
36 #include <EGL/eglext.h>
37 
38 namespace mir
39 {
40 namespace graphics
41 {
42 struct EGLExtensions;
43 namespace android
44 {
45 
46 class Buffer: public BufferBasic, public NativeBufferBase,
48 {
49 public:
50  Buffer(gralloc_module_t const* hw_module,
51  std::shared_ptr<NativeBuffer> const& buffer_handle,
52  std::shared_ptr<EGLExtensions> const& extensions);
53  ~Buffer();
54 
55  geometry::Size size() const override;
56  geometry::Stride stride() const override;
57  MirPixelFormat pixel_format() const override;
58  void gl_bind_to_texture() override;
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  void read(std::function<void(unsigned char const*)> const&) override;
65 
67 
68 private:
69  gralloc_module_t const* hw_module;
70 
71  typedef std::pair<EGLDisplay, EGLContext> DispContextPair;
72  std::map<DispContextPair,EGLImageKHR> egl_image_map;
73 
74  std::mutex mutable content_lock;
75  std::shared_ptr<NativeBuffer> native_buffer;
76  std::shared_ptr<EGLExtensions> egl_extensions;
77 };
78 
79 }
80 }
81 }
82 
83 #endif /* MIR_GRAPHICS_ANDROID_BUFFER_H_ */
Definition: size.h:30
All things Mir.
Definition: atomic_callback.h:25
Definition: texture_source.h:29
NativeBufferBase * native_buffer_base() override
Definition: buffer.cpp:195
MirPixelFormat pixel_format() const override
Definition: buffer.cpp:68
void gl_bind_to_texture() override
Definition: buffer.cpp:74
Definition: buffer.h:35
std::shared_ptr< NativeBuffer > native_buffer_handle() const override
Definition: buffer.cpp:122
~Buffer()
Definition: buffer.cpp:46
MirPixelFormat
32-bit pixel formats (8888): The order of components in the enum matches the order of the components ...
Definition: common.h:134
void read(std::function< void(unsigned char const *)> const &) override
Definition: buffer.cpp:171
geometry::Stride stride() const override
Definition: buffer.cpp:61
Definition: buffer.h:46
Definition: buffer_basic.h:29
Definition: android_input_receiver.h:36
geometry::Size size() const override
Definition: buffer.cpp:55
Definition: dimensions.h:36
void write(unsigned char const *pixels, size_t size) override
Definition: buffer.cpp:138

Copyright © 2012-2015 Canonical Ltd.
Generated on Thu Oct 8 16:20:16 UTC 2015