|
1 /* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
2 * |
|
3 * Permission is hereby granted, free of charge, to any person obtaining a |
|
4 * copy of this software and /or associated documentation files |
|
5 * (the "Materials "), to deal in the Materials without restriction, |
|
6 * including without limitation the rights to use, copy, modify, merge, |
|
7 * publish, distribute, sublicense, and/or sell copies of the Materials, |
|
8 * and to permit persons to whom the Materials are furnished to do so, |
|
9 * subject to the following conditions: |
|
10 * |
|
11 * The above copyright notice and this permission notice shall be included |
|
12 * in all copies or substantial portions of the Materials. |
|
13 * |
|
14 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|
16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
|
17 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
|
18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
|
19 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR |
|
20 * THE USE OR OTHER DEALINGS IN THE MATERIALS. |
|
21 * |
|
22 * Initial Contributors: |
|
23 * Nokia Corporation - initial contribution. |
|
24 * |
|
25 * Contributors: |
|
26 * |
|
27 * Description: |
|
28 * |
|
29 */ |
|
30 |
|
31 #include "EGLWindowSurface.h" |
|
32 #include "EGLConfig.h" |
|
33 #include "ColorDescriptor.h" |
|
34 #include "EGLOs.h" |
|
35 |
|
36 // \todo Use new[]/free[] instead? |
|
37 #include <stdlib.h> |
|
38 |
|
39 CEGLWindowSurface::CEGLWindowSurface() : |
|
40 CEGLSurface( CEGLSurface::WINDOW_SURFACE, |
|
41 0, |
|
42 0, |
|
43 0, |
|
44 NULL ), |
|
45 m_buffer0( NULL ), |
|
46 m_buffer1( NULL ), |
|
47 m_currentBuffer( NULL ), |
|
48 m_swapInterval( 1 ), |
|
49 m_osContext( NULL ) |
|
50 { |
|
51 } |
|
52 |
|
53 CEGLWindowSurface::CEGLWindowSurface( CEGLConfig* config, EGLint colorSpace, EGLint alphaFormat, EGLint renderBuffer, EGLIOsWindowContext* osContext) : |
|
54 CEGLSurface( CEGLSurface::WINDOW_SURFACE, |
|
55 colorSpace, |
|
56 alphaFormat, |
|
57 renderBuffer, |
|
58 config ), |
|
59 m_buffer0( NULL ), |
|
60 m_buffer1( NULL ), |
|
61 m_currentBuffer( NULL ), |
|
62 m_swapInterval( 1 ), |
|
63 m_osContext( osContext ) |
|
64 { |
|
65 EGLI_ASSERT( m_osContext != NULL ); |
|
66 } |
|
67 |
|
68 CEGLWindowSurface::~CEGLWindowSurface(void) |
|
69 { |
|
70 #if !defined(EGLI_USE_PLATSIM_EXTENSIONS) |
|
71 if( m_currentBuffer ) free( m_currentBuffer ); |
|
72 #endif |
|
73 if( m_osContext ) |
|
74 CEGLOs::DestroyOSWindowContext( m_osContext ); |
|
75 } |
|
76 |
|
77 void* CEGLWindowSurface::CurrentBuffer() |
|
78 { |
|
79 #if defined(EGLI_USE_PLATSIM_EXTENSIONS) |
|
80 m_currentBuffer = (m_currentBuffer && m_currentBuffer == m_buffer0) ? m_buffer1 : m_buffer0; |
|
81 EGLI_ASSERT( m_currentBuffer != NULL ); |
|
82 return m_currentBuffer; |
|
83 #else |
|
84 if( !m_currentBuffer || m_osContext->width != Width() || m_osContext->height != Height() ) |
|
85 { |
|
86 if( m_currentBuffer ) free( m_currentBuffer ); |
|
87 m_currentBuffer = malloc(m_height*m_stride); |
|
88 } |
|
89 return m_currentBuffer;//NULL; |
|
90 #endif |
|
91 } |
|
92 |
|
93 void CEGLWindowSurface::SetSwapInterval( EGLint interval ) |
|
94 { |
|
95 // \todo MIN, MAX |
|
96 m_swapInterval = interval; |
|
97 } |
|
98 |
|
99 void CEGLWindowSurface::SetOsContext( EGLIOsWindowContext* osContext ) |
|
100 { |
|
101 if( m_osContext ) |
|
102 CEGLOs::DestroyOSWindowContext( m_osContext ); |
|
103 m_osContext = osContext; |
|
104 } |