VLCVideoView.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*****************************************************************************
  2. * VLCVideoView.m: VLCKit.framework VLCVideoView implementation
  3. *****************************************************************************
  4. * Copyright (C) 2007 Pierre d'Herbemont
  5. * Copyright (C) 2007 VLC authors and VideoLAN
  6. * $Id$
  7. *
  8. * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU Lesser General Public License as published by
  12. * the Free Software Foundation; either version 2.1 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public License
  21. * along with this program; if not, write to the Free Software Foundation,
  22. * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  23. *****************************************************************************/
  24. #import "VLCVideoView.h"
  25. #import "VLCLibrary.h"
  26. #import "VLCEventManager.h"
  27. #import "VLCVideoCommon.h"
  28. /* Libvlc */
  29. #ifdef HAVE_CONFIG_H
  30. # include "config.h"
  31. #endif
  32. #include <vlc/vlc.h>
  33. #include <vlc/libvlc.h>
  34. #import <QuartzCore/QuartzCore.h>
  35. /******************************************************************************
  36. * Soon deprecated stuff
  37. */
  38. /* This is a forward reference to VLCOpenGLVoutView specified in minimal_macosx
  39. library. We could get rid of this, but it prevents warnings from the
  40. compiler. (Scheduled to deletion) */
  41. @interface VLCOpenGLVoutView : NSView
  42. - (void)detachFromVout;
  43. @end
  44. /******************************************************************************
  45. * VLCVideoView (Private)
  46. */
  47. @interface VLCVideoView ()
  48. @property (nonatomic, readwrite) BOOL hasVideo;
  49. @property (nonatomic, retain) VLCVideoLayoutManager *layoutManager;
  50. - (void)addVoutLayer:(CALayer *)aLayer;
  51. @end
  52. /******************************************************************************
  53. * Implementation VLCVideoView
  54. */
  55. @implementation VLCVideoView
  56. /* Initializers */
  57. - (instancetype)initWithFrame:(NSRect)rect
  58. {
  59. if (self = [super initWithFrame:rect])
  60. {
  61. self.backColor = [NSColor blackColor];
  62. self.autoresizesSubviews = YES;
  63. self.layoutManager = [VLCVideoLayoutManager layoutManager];
  64. }
  65. return self;
  66. }
  67. /* NSView Overrides */
  68. - (void)drawRect:(NSRect)aRect
  69. {
  70. [self lockFocus];
  71. [self.backColor set];
  72. NSRectFill(aRect);
  73. [self unlockFocus];
  74. }
  75. - (BOOL)isOpaque
  76. {
  77. return YES;
  78. }
  79. - (BOOL)fillScreen
  80. {
  81. return [self.layoutManager fillScreenEntirely];
  82. }
  83. - (void)setFillScreen:(BOOL)fillScreen
  84. {
  85. [self.layoutManager setFillScreenEntirely:fillScreen];
  86. [self.layer setNeedsLayout];
  87. }
  88. /******************************************************************************
  89. * Implementation VLCVideoView (Private)
  90. */
  91. /* This is called by the libvlc module 'opengllayer' as soon as there is one
  92. * vout available
  93. */
  94. - (void)addVoutLayer:(CALayer *)aLayer
  95. {
  96. aLayer.name = @"vlcopengllayer";
  97. [CATransaction begin];
  98. self.wantsLayer = YES;
  99. CALayer * rootLayer = self.layer;
  100. [self.layoutManager setOriginalVideoSize:aLayer.bounds.size];
  101. [rootLayer setLayoutManager:self.layoutManager];
  102. [rootLayer insertSublayer:aLayer atIndex:0];
  103. [aLayer setNeedsDisplayOnBoundsChange:YES];
  104. [CATransaction commit];
  105. self.hasVideo = YES;
  106. }
  107. - (void)removeVoutLayer:(CALayer *)voutLayer
  108. {
  109. [CATransaction begin];
  110. [voutLayer removeFromSuperlayer];
  111. [CATransaction commit];
  112. self.hasVideo = NO;
  113. }
  114. @end