src/video/uikit/SDL_uikitopengles.m
author Alex Szpakowski <slime73@gmail.com>
Wed, 06 Aug 2014 13:50:50 -0300
branchiOS-improvements
changeset 9512 c9f61d1dac7b
parent 9510 e19faa3b5d88
parent 9045 c689ac0e8411
child 9513 34d9391e7d3e
permissions -rw-r--r--
Merged default into iOS-improvements
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5527
diff changeset
     2
  Simple DirectMedia Layer
8149
681eb46b8ac4 Fixed bug 2374 - Update copyright for 2014...
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
5262
b530ef003506 Happy 2011! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5246
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5527
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5527
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5527
diff changeset
     7
  arising from the use of this software.
5262
b530ef003506 Happy 2011! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5246
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5527
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5527
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5527
diff changeset
    11
  freely, subject to the following restrictions:
5262
b530ef003506 Happy 2011! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5246
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5527
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5527
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5527
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5527
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5527
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5527
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5527
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
5262
b530ef003506 Happy 2011! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5246
diff changeset
    20
*/
8093
b43765095a6f Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents: 7425
diff changeset
    21
#include "../../SDL_internal.h"
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6021
diff changeset
    22
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6021
diff changeset
    23
#if SDL_VIDEO_DRIVER_UIKIT
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
#include "SDL_uikitopengles.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
#include "SDL_uikitopenglview.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
#include "SDL_uikitappdelegate.h"
6518
42948831d16e Refactored the UIKit mode code into a separate file so it's cleaner and more consistent with other backends
Sam Lantinga <slouken@libsdl.org>
parents: 6451
diff changeset
    28
#include "SDL_uikitmodes.h"
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
#include "SDL_uikitwindow.h"
6321
71fa3d8976a3 Fixed includes for Objective C
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
    30
#include "../SDL_sysvideo.h"
4490
06c7423f8c60 Updated iPhone keyboard code (which builds and runs on the iPad and iPhone simulator now)
Sam Lantinga <slouken@libsdl.org>
parents: 4488
diff changeset
    31
#include "../../events/SDL_keyboard_c.h"
06c7423f8c60 Updated iPhone keyboard code (which builds and runs on the iPad and iPhone simulator now)
Sam Lantinga <slouken@libsdl.org>
parents: 4488
diff changeset
    32
#include "../../events/SDL_mouse_c.h"
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6021
diff changeset
    33
#include "../../power/uikit/SDL_syspower.h"
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
#include "SDL_loadso.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    35
#include <dlfcn.h>
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    36
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
static int UIKit_GL_Initialize(_THIS);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    38
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    39
void *
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
UIKit_GL_GetProcAddress(_THIS, const char *proc)
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
    41
{
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    42
    /* Look through all SO's for the proc symbol.  Here's why:
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    43
       -Looking for the path to the OpenGL Library seems not to work in the iPhone Simulator.
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    44
       -We don't know that the path won't change in the future.
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    45
    */
5363
96799a165806 Fixed testgles on iOS (bug 1136)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    46
    return dlsym(RTLD_DEFAULT, proc);
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    47
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    48
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    49
/*
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    50
    note that SDL_GL_Delete context makes it current without passing the window
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    51
*/
9488
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
    52
int
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
    53
UIKit_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    54
{
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
    55
    @autoreleasepool {
9512
c9f61d1dac7b Merged default into iOS-improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9510 9045
diff changeset
    56
        [EAGLContext setCurrentContext:(__bridge EAGLContext *)context];
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    57
    }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
    return 0;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    59
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    60
9488
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
    61
void UIKit_GL_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
    62
{
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
    63
    @autoreleasepool {
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
    64
        SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
9488
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
    65
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
    66
        if (w) {
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
    67
            *w = data.view.backingWidth;
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
    68
        }
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
    69
        if (h) {
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
    70
            *h = data.view.backingHeight;
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
    71
        }
9488
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
    72
    }
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
    73
}
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
    74
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
    75
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    76
int
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    77
UIKit_GL_LoadLibrary(_THIS, const char *path)
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    78
{
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
    79
    /*
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
    80
        shouldn't be passing a path into this function
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    81
        why?  Because we've already loaded the library
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    82
        and because the SDK forbids loading an external SO
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    83
    */
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    84
    if (path != NULL) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
    85
        return SDL_SetError("iPhone GL Load Library just here for compatibility");
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    86
    }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    87
    return 0;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    88
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    89
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    90
void UIKit_GL_SwapWindow(_THIS, SDL_Window * window)
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    91
{
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
    92
    @autoreleasepool {
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
    93
        SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
    94
6088
eedb8e10ac22 Fix iOS build when SDL_POWER_UIKIT isn't defined.
Ryan C. Gordon <icculus@icculus.org>
parents: 6044
diff changeset
    95
#if SDL_POWER_UIKIT
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
    96
        /* Check once a frame to see if we should turn off the battery monitor. */
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
    97
        SDL_UIKit_UpdateBatteryMonitoring();
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
    98
#endif
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    99
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   100
        if (data.view == nil) {
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   101
            return;
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   102
        }
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   103
        [data.view swapBuffers];
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
   104
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   105
        /* You need to pump events in order for the OS to make changes visible.
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   106
           We don't pump events here because we don't want iOS application events
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   107
           (low memory, terminate, etc.) to happen inside low level rendering.
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   108
         */
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
   109
    }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   110
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   111
9488
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
   112
SDL_GLContext
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
   113
UIKit_GL_CreateContext(_THIS, SDL_Window * window)
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   114
{
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   115
    @autoreleasepool {
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   116
        SDL_uikitopenglview *view;
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   117
        SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   118
        UIWindow *uiwindow = data.uiwindow;
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   119
        CGRect frame = UIKit_ComputeViewFrame(window, uiwindow.screen);
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   120
        EAGLSharegroup *share_group = nil;
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   121
        CGFloat scale = 1.0;
9488
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
   122
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   123
        if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   124
            /* Set the scale to the natural scale factor of the screen - the backing
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   125
               dimensions of the OpenGL view will match the pixel dimensions of the
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   126
               screen rather than the dimensions in points.
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   127
             */
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   128
            scale = uiwindow.screen.scale;
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   129
        }
7423
dfe7ad02f008 Implement SDL_GL_SHARE_WITH_CURRENT_CONTEXT for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 7285
diff changeset
   130
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   131
        if (_this->gl_config.share_with_current_context) {
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   132
            SDL_uikitopenglview *view = (__bridge SDL_uikitopenglview *) SDL_GL_GetCurrentContext();
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   133
            share_group = [view.context sharegroup];
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   134
        }
7423
dfe7ad02f008 Implement SDL_GL_SHARE_WITH_CURRENT_CONTEXT for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 7285
diff changeset
   135
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   136
        /* construct our view, passing in SDL's OpenGL configuration data */
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   137
        view = [[SDL_uikitopenglview alloc] initWithFrame: frame
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   138
                                                    scale: scale
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   139
                                            retainBacking: _this->gl_config.retained_backing
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   140
                                                    rBits: _this->gl_config.red_size
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   141
                                                    gBits: _this->gl_config.green_size
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   142
                                                    bBits: _this->gl_config.blue_size
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   143
                                                    aBits: _this->gl_config.alpha_size
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   144
                                                depthBits: _this->gl_config.depth_size
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   145
                                              stencilBits: _this->gl_config.stencil_size
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   146
                                                     sRGB: _this->gl_config.framebuffer_srgb_capable
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   147
                                             majorVersion: _this->gl_config.major_version
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   148
                                               shareGroup: share_group];
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   149
        if (!view) {
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   150
            return NULL;
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   151
        }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   152
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   153
        data.view = view;
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   154
        view.viewcontroller = data.viewcontroller;
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   155
        if (view.viewcontroller != nil) {
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   156
            view.viewcontroller.view = view;
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   157
        }
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   158
        [uiwindow addSubview: view];
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7190
diff changeset
   159
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   160
        /* The view controller needs to be the root in order to control rotation on iOS 6.0 */
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   161
        if (uiwindow.rootViewController == nil) {
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   162
            uiwindow.rootViewController = view.viewcontroller;
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   163
        }
5520
09b500e0656d Added orientation rotation for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 5363
diff changeset
   164
9512
c9f61d1dac7b Merged default into iOS-improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9510 9045
diff changeset
   165
        EAGLContext *context = view.context;
c9f61d1dac7b Merged default into iOS-improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9510 9045
diff changeset
   166
        if (UIKit_GL_MakeCurrent(_this, window, (__bridge SDL_GLContext) context) < 0) {
c9f61d1dac7b Merged default into iOS-improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9510 9045
diff changeset
   167
            UIKit_GL_DeleteContext(_this, (SDL_GLContext) CFBridgingRetain(context));
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   168
            return NULL;
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   169
        }
4488
6dc6a2bdd55e Re-implemented single mouse touches on the iPhone/iPad
Sam Lantinga <slouken@libsdl.org>
parents: 4446
diff changeset
   170
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   171
        /* Make this window the current mouse focus for touch input */
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   172
        if (uiwindow.screen == [UIScreen mainScreen]) {
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   173
            SDL_SetMouseFocus(window);
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   174
            SDL_SetKeyboardFocus(window);
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   175
        }
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   176
9512
c9f61d1dac7b Merged default into iOS-improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9510 9045
diff changeset
   177
        return (SDL_GLContext) CFBridgingRetain(context);
6439
fbbd640d7867 Fixed touch coordinates with the new UI bounds calculation
Sam Lantinga <slouken@libsdl.org>
parents: 6437
diff changeset
   178
    }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   179
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   180
9488
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
   181
void
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
   182
UIKit_GL_DeleteContext(_THIS, SDL_GLContext context)
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   183
{
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   184
    @autoreleasepool {
9512
c9f61d1dac7b Merged default into iOS-improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9510 9045
diff changeset
   185
        SDL_Window *window;
c9f61d1dac7b Merged default into iOS-improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9510 9045
diff changeset
   186
        EAGLContext *eaglcontext = (EAGLContext *) CFBridgingRelease(context);
9045
c689ac0e8411 The OpenGL context returned by the UIKit backend is now an actual OpenGL context instead of the OpenGL view we created.
Sam Lantinga <slouken@libsdl.org>
parents: 8583
diff changeset
   187
9512
c9f61d1dac7b Merged default into iOS-improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9510 9045
diff changeset
   188
        /* Find the view associated with this context */
c9f61d1dac7b Merged default into iOS-improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9510 9045
diff changeset
   189
        for (window = _this->windows; window; window = window->next) {
c9f61d1dac7b Merged default into iOS-improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9510 9045
diff changeset
   190
            SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
c9f61d1dac7b Merged default into iOS-improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9510 9045
diff changeset
   191
            SDL_uikitopenglview *view = data.view;
c9f61d1dac7b Merged default into iOS-improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9510 9045
diff changeset
   192
            if (view.context == eaglcontext) {
c9f61d1dac7b Merged default into iOS-improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9510 9045
diff changeset
   193
                /* the delegate has retained the view, this will release him */
c9f61d1dac7b Merged default into iOS-improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9510 9045
diff changeset
   194
                if (view.viewcontroller) {
c9f61d1dac7b Merged default into iOS-improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9510 9045
diff changeset
   195
                    UIWindow *uiwindow = (UIWindow *)view.superview;
c9f61d1dac7b Merged default into iOS-improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9510 9045
diff changeset
   196
                    if (uiwindow.rootViewController == view.viewcontroller) {
c9f61d1dac7b Merged default into iOS-improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9510 9045
diff changeset
   197
                        uiwindow.rootViewController = nil;
c9f61d1dac7b Merged default into iOS-improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9510 9045
diff changeset
   198
                    }
c9f61d1dac7b Merged default into iOS-improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9510 9045
diff changeset
   199
                    view.viewcontroller.view = nil;
c9f61d1dac7b Merged default into iOS-improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9510 9045
diff changeset
   200
                    view.viewcontroller = nil;
9045
c689ac0e8411 The OpenGL context returned by the UIKit backend is now an actual OpenGL context instead of the OpenGL view we created.
Sam Lantinga <slouken@libsdl.org>
parents: 8583
diff changeset
   201
                }
9512
c9f61d1dac7b Merged default into iOS-improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9510 9045
diff changeset
   202
                [view removeFromSuperview];
c9f61d1dac7b Merged default into iOS-improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9510 9045
diff changeset
   203
c9f61d1dac7b Merged default into iOS-improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9510 9045
diff changeset
   204
                data.view = nil;
c9f61d1dac7b Merged default into iOS-improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9510 9045
diff changeset
   205
                return;
9045
c689ac0e8411 The OpenGL context returned by the UIKit backend is now an actual OpenGL context instead of the OpenGL view we created.
Sam Lantinga <slouken@libsdl.org>
parents: 8583
diff changeset
   206
            }
6521
f36bbe0a10c9 Remove the viewcontroller from the window when he OpenGL context is destroyed
Sam Lantinga <slouken@libsdl.org>
parents: 6518
diff changeset
   207
        }
5520
09b500e0656d Added orientation rotation for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 5363
diff changeset
   208
    }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   209
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   210
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6021
diff changeset
   211
#endif /* SDL_VIDEO_DRIVER_UIKIT */
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6021
diff changeset
   212
5132
5f09cb749d75 Added vim spacing hints
Sam Lantinga <slouken@libsdl.org>
parents: 5131
diff changeset
   213
/* vi: set ts=4 sw=4 expandtab: */