src/video/uikit/SDL_uikitopengles.m
author Alex Szpakowski <slime73@gmail.com>
Tue, 29 Jul 2014 00:36:12 -0300
branchiOS-improvements
changeset 9506 18e3f94bd860
parent 9502 933ed557b7c1
child 9510 e19faa3b5d88
permissions -rw-r--r--
Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
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 {
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
    56
        if (context) {
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
    57
            SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
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
    58
            [data->view setCurrentContext];
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
    59
        }
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
    60
        else {
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
    61
            [EAGLContext setCurrentContext: 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
    62
        }
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    63
    }
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
    64
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    65
    return 0;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    66
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    67
9488
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
    68
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
    69
{
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
    70
    SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
    71
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
    72
    @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
    73
        if (w) {
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
    74
            *w = data->view.backingWidth;
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
    75
        }
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
    76
        if (h) {
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
    77
            *h = data->view.backingHeight;
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
    78
        }
9488
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
    79
    }
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
    80
}
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
    81
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
    82
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    83
int
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    84
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
    85
{
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
    86
    /*
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
    87
        shouldn't be passing a path into this function
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    88
        why?  Because we've already loaded the library
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    89
        and because the SDK forbids loading an external SO
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    90
    */
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    91
    if (path != NULL) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
    92
        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
    93
    }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    94
    return 0;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    95
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    96
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    97
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
    98
{
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
    99
    @autoreleasepool {
6088
eedb8e10ac22 Fix iOS build when SDL_POWER_UIKIT isn't defined.
Ryan C. Gordon <icculus@icculus.org>
parents: 6044
diff changeset
   100
#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
   101
        /* 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
   102
        SDL_UIKit_UpdateBatteryMonitoring();
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   103
#endif
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
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
        SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
   106
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
   107
        if (nil == data->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
   108
            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
   109
        }
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
   110
        [data->view swapBuffers];
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
   111
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
   112
        /* 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
   113
           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
   114
           (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
   115
         */
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
   116
    }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   117
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   118
9488
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
   119
SDL_GLContext
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
   120
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
   121
{
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
   122
    @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
   123
        SDL_uikitopenglview *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
   124
        SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
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
        UIWindow *uiwindow = data->uiwindow;
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
        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
   127
        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
   128
        CGFloat scale = 1.0;
9488
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
   129
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
   130
        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
   131
            /* 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
   132
               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
   133
               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
   134
             */
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
   135
            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
   136
        }
7423
dfe7ad02f008 Implement SDL_GL_SHARE_WITH_CURRENT_CONTEXT for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 7285
diff changeset
   137
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
   138
        if (_this->gl_config.share_with_current_context) {
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
            SDL_uikitopenglview *view = (SDL_uikitopenglview *) SDL_GL_GetCurrentContext();
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
            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
   141
        }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   142
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
   143
        /* 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
   144
        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
   145
                                                    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
   146
                                            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
   147
                                                    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
   148
                                                    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
   149
                                                    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
   150
                                                    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
   151
                                                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
   152
                                              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
   153
                                                     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
   154
                                             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
   155
                                               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
   156
        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
   157
            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
   158
        }
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
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
        data->view = 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
   161
        view->viewcontroller = data->viewcontroller;
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
   162
        if (view->viewcontroller != 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
   163
            [view->viewcontroller setView: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
   164
            [view->viewcontroller retain];
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
   165
        }
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
   166
        [uiwindow addSubview: view];
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7190
diff changeset
   167
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
        /* 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
   169
        if (uiwindow.rootViewController == 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
   170
            uiwindow.rootViewController = view->viewcontroller;
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
        }
5520
09b500e0656d Added orientation rotation for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 5363
diff changeset
   172
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
   173
        if (UIKit_GL_MakeCurrent(_this, window, view) < 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
   174
            UIKit_GL_DeleteContext(_this, 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
   175
            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
   176
        }
4488
6dc6a2bdd55e Re-implemented single mouse touches on the iPhone/iPad
Sam Lantinga <slouken@libsdl.org>
parents: 4446
diff changeset
   177
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
   178
        /* 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
   179
        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
   180
            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
   181
            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
   182
        }
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
   183
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
        return view;
6267
ed2cf4669e55 * On iOS, fix support for the case where [UIScreen scale] is not 1.0 (retina)
Tim Angus <tim@blackcompanystudios.co.uk>
parents: 6179
diff changeset
   185
    }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   186
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   187
9488
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
   188
void
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
   189
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
   190
{
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
   191
    @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
   192
        /* the delegate has retained the view, this will release him */
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
   193
        SDL_uikitopenglview *view = (SDL_uikitopenglview *)context;
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
   194
        if (view->viewcontroller) {
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
   195
            UIWindow *uiwindow = (UIWindow *)view.superview;
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
   196
            if (uiwindow.rootViewController == view->viewcontroller) {
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
   197
                uiwindow.rootViewController = 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
   198
            }
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
   199
            [view->viewcontroller setView: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
   200
            [view->viewcontroller release];
6521
f36bbe0a10c9 Remove the viewcontroller from the window when he OpenGL context is destroyed
Sam Lantinga <slouken@libsdl.org>
parents: 6518
diff changeset
   201
        }
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
   202
        [view removeFromSuperview];
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
   203
        [view release];
5520
09b500e0656d Added orientation rotation for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 5363
diff changeset
   204
    }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   205
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   206
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6021
diff changeset
   207
#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
   208
5132
5f09cb749d75 Added vim spacing hints
Sam Lantinga <slouken@libsdl.org>
parents: 5131
diff changeset
   209
/* vi: set ts=4 sw=4 expandtab: */