[cosmetics] update date in GPL header
[vuplus_xbmc] / xbmc / android / activity / GraphicBuffer.h
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://www.xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
21  * ***** BEGIN LICENSE BLOCK *****
22  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
23  *
24  * The contents of this file are subject to the Mozilla Public License Version
25  * 1.1 (the "License"); you may not use this file except in compliance with
26  * the License. You may obtain a copy of the License at
27  * http://www.mozilla.org/MPL/
28  *
29  * Software distributed under the License is distributed on an "AS IS" basis,
30  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
31  * for the specific language governing rights and limitations under the
32  * License.
33  *
34  * The Original Code is Mozilla Corporation code.
35  *
36  * The Initial Developer of the Original Code is Mozilla Foundation.
37  * Portions created by the Initial Developer are Copyright (C) 2009
38  * the Initial Developer. All Rights Reserved.
39  *
40  * Contributor(s):
41  *   James Willcox <jwillcox@mozilla.com>
42  *
43  * Alternatively, the contents of this file may be used under the terms of
44  * either the GNU General Public License Version 2 or later (the "GPL"), or
45  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
46  * in which case the provisions of the GPL or the LGPL are applicable instead
47  * of those above. If you wish to allow use of your version of this file only
48  * under the terms of either the GPL or the LGPL, and not to allow others to
49  * use your version of this file under the terms of the MPL, indicate your
50  * decision by deleting the provisions above and replace them with the notice
51  * and other provisions required by the GPL or the LGPL. If you do not delete
52  * the provisions above, a recipient may use your version of this file under
53  * the terms of any one of the MPL, the GPL or the LGPL.
54  *
55  * ***** END LICENSE BLOCK ***** */
56
57 #pragma once
58 #include <stdint.h>
59 #include "guilib/XBTF.h"
60
61 class DllGraphicBuffer;
62
63 /* Copied from Android's gralloc.h */
64 enum gfxImageUsage {
65     /* buffer is never read in software */
66     GRALLOC_USAGE_SW_READ_NEVER   = 0x00000000,
67     /* buffer is rarely read in software */
68     GRALLOC_USAGE_SW_READ_RARELY  = 0x00000002,
69     /* buffer is often read in software */
70     GRALLOC_USAGE_SW_READ_OFTEN   = 0x00000003,
71     /* mask for the software read values */
72     GRALLOC_USAGE_SW_READ_MASK    = 0x0000000F,
73
74     /* buffer is never written in software */
75     GRALLOC_USAGE_SW_WRITE_NEVER  = 0x00000000,
76     /* buffer is never written in software */
77     GRALLOC_USAGE_SW_WRITE_RARELY = 0x00000020,
78     /* buffer is never written in software */
79     GRALLOC_USAGE_SW_WRITE_OFTEN  = 0x00000030,
80     /* mask for the software write values */
81     GRALLOC_USAGE_SW_WRITE_MASK   = 0x000000F0,
82
83     /* buffer will be used as an OpenGL ES texture */
84     GRALLOC_USAGE_HW_TEXTURE      = 0x00000100,
85     /* buffer will be used as an OpenGL ES render target */
86     GRALLOC_USAGE_HW_RENDER       = 0x00000200,
87     /* buffer will be used by the 2D hardware blitter */
88     GRALLOC_USAGE_HW_2D           = 0x00000400,
89     /* buffer will be used with the framebuffer device */
90     GRALLOC_USAGE_HW_FB           = 0x00001000,
91     /* mask for the software usage bit-mask */
92     GRALLOC_USAGE_HW_MASK         = 0x00001F00,
93
94     /* implementation-specific private usage flags */
95     GRALLOC_USAGE_PRIVATE_0       = 0x10000000,
96     GRALLOC_USAGE_PRIVATE_1       = 0x20000000,
97     GRALLOC_USAGE_PRIVATE_2       = 0x40000000,
98     GRALLOC_USAGE_PRIVATE_3       = 0x80000000,
99     GRALLOC_USAGE_PRIVATE_MASK    = 0xF0000000,
100 };
101
102 class CGraphicBuffer
103 {
104 public:
105   CGraphicBuffer(uint32_t width, uint32_t height, uint32_t format, gfxImageUsage usage);
106   virtual       ~CGraphicBuffer();
107
108   bool          Lock(gfxImageUsage usage, void **addr);
109   bool          Unlock();
110   uint32_t      GetNativeBuffer();
111
112 private:
113   uint32_t      m_width;
114   uint32_t      m_height;
115   gfxImageUsage m_usage;
116   uint32_t      m_format;
117
118   uint32_t      GetAndroidFormat(uint32_t format);
119
120   void          *m_handle;
121   static        DllGraphicBuffer *m_dll;
122 };