0009-ios_vout2-fix-crash-when-trying-to-draw-OpenGL-chang.patch 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. From 759c080826b69637c06d51b38b3c53dd6e97608e Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Felix=20Paul=20K=C3=BChne?= <fkuehne@videolan.org>
  3. Date: Thu, 28 Mar 2013 12:34:46 +0100
  4. Subject: [PATCH 09/10] ios_vout2: fix crash when trying to draw OpenGL
  5. changes while the app is in the background
  6. ---
  7. modules/video_output/ios2.m | 25 +++++++++++++++++++++----
  8. 1 file changed, 21 insertions(+), 4 deletions(-)
  9. diff --git a/modules/video_output/ios2.m b/modules/video_output/ios2.m
  10. index a18f8f2..0774550 100644
  11. --- a/modules/video_output/ios2.m
  12. +++ b/modules/video_output/ios2.m
  13. @@ -89,9 +89,11 @@ vlc_module_end ()
  14. GLuint _frameBuffer;
  15. BOOL _bufferNeedReset;
  16. + BOOL _appActive;
  17. }
  18. @property (readwrite) vout_display_t* voutDisplay;
  19. @property (readonly) EAGLContext* eaglContext;
  20. +@property (readonly) BOOL isAppActive;
  21. - (void)createBuffers;
  22. - (void)destroyBuffers;
  23. @@ -189,6 +191,8 @@ static int Open(vlc_object_t *this)
  24. vd->control = Control;
  25. /* */
  26. + [[NSNotificationCenter defaultCenter] addObserver:sys->glESView selector:@selector(applicationStateChanged:) name:UIApplicationWillResignActiveNotification object:nil];
  27. + [[NSNotificationCenter defaultCenter] addObserver:sys->glESView selector:@selector(applicationStateChanged:) name:UIApplicationDidBecomeActiveNotification object:nil];
  28. [sys->glESView performSelectorOnMainThread:@selector(reshape) withObject:nil waitUntilDone:YES];
  29. [autoreleasePool release];
  30. @@ -311,7 +315,8 @@ static void PictureDisplay(vout_display_t *vd, picture_t *pic, subpicture_t *sub
  31. {
  32. vout_display_sys_t *sys = vd->sys;
  33. sys->has_first_frame = true;
  34. - vout_display_opengl_Display(sys->vgl, &vd->source);
  35. + if ([sys->glESView isAppActive])
  36. + vout_display_opengl_Display(sys->vgl, &vd->source);
  37. picture_Release(pic);
  38. @@ -324,7 +329,8 @@ static void PictureRender(vout_display_t *vd, picture_t *pic, subpicture_t *subp
  39. vout_display_sys_t *sys = vd->sys;
  40. - vout_display_opengl_Prepare(sys->vgl, pic, subpicture);
  41. + if ([sys->glESView isAppActive])
  42. + vout_display_opengl_Prepare(sys->vgl, pic, subpicture);
  43. }
  44. static picture_pool_t *PicturePool(vout_display_t *vd, unsigned requested_count)
  45. @@ -350,14 +356,15 @@ static int OpenglESClean(vlc_gl_t *gl)
  46. static void OpenglESSwap(vlc_gl_t *gl)
  47. {
  48. vout_display_sys_t *sys = (vout_display_sys_t *)gl->sys;
  49. - [[sys->glESView eaglContext] presentRenderbuffer:GL_RENDERBUFFER];
  50. + if ([sys->glESView isAppActive])
  51. + [[sys->glESView eaglContext] presentRenderbuffer:GL_RENDERBUFFER];
  52. }
  53. /*****************************************************************************
  54. * Our UIView object
  55. *****************************************************************************/
  56. @implementation VLCOpenGLES2VideoView
  57. -@synthesize voutDisplay = _voutDisplay, eaglContext = _eaglContext;
  58. +@synthesize voutDisplay = _voutDisplay, eaglContext = _eaglContext, isAppActive = _appActive;
  59. + (Class)layerClass
  60. {
  61. @@ -384,6 +391,8 @@ static void OpenglESSwap(vlc_gl_t *gl)
  62. [self performSelectorOnMainThread:@selector(reshape) withObject:nil waitUntilDone:NO];
  63. [self setAutoresizingMask: UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
  64. + _appActive = ([UIApplication sharedApplication].applicationState == UIApplicationStateActive);
  65. +
  66. return self;
  67. }
  68. @@ -484,6 +493,14 @@ static void OpenglESSwap(vlc_gl_t *gl)
  69. glViewport(place.x, place.y, place.width, place.height);
  70. }
  71. +- (void)applicationStateChanged:(NSNotification *)notification
  72. +{
  73. + if ([[notification name] isEqualToString: UIApplicationWillResignActiveNotification])
  74. + _appActive = NO;
  75. + else
  76. + _appActive = YES;
  77. +}
  78. +
  79. - (void)updateConstraints
  80. {
  81. [self reshape];
  82. --
  83. 1.7.12.4 (Apple Git-37)