VLCVideoLayer.m 3.21 KB
Newer Older
1
/*****************************************************************************
2
 * VLCVideoLayer.m: VLCKit.framework VLCVideoLayer implementation
3 4
 *****************************************************************************
 * Copyright (C) 2007 Pierre d'Herbemont
5
 * Copyright (C) 2007 VLC authors and VideoLAN
Pierre's avatar
Pierre committed
6
 * $Id$
7 8 9
 *
 * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
 *
10 11 12
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
13 14 15 16
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
19
 *
20 21 22
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 24 25 26 27
 *****************************************************************************/

#import "VLCVideoLayer.h"
#import "VLCLibrary.h"
#import "VLCEventManager.h"
28
#import "VLCVideoCommon.h"
29 30

/* Libvlc */
31 32 33 34
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

35 36 37 38 39 40
#include <vlc/vlc.h>
#include <vlc/libvlc.h>

#import <QuartzCore/QuartzCore.h>

/******************************************************************************
41
 * VLCVideoLayer (Private)
42 43
 */

44 45 46 47
@interface VLCVideoLayer ()

@property (nonatomic, readwrite) BOOL hasVideo;

48 49
- (void)addVoutLayer:(CALayer *)aLayer;

50 51
@end

52
/******************************************************************************
53
 * Implementation VLCVideoLayer
54 55 56 57
 */

@implementation VLCVideoLayer

58 59
- (BOOL)fillScreen
{
60
    return [(VLCVideoLayoutManager *)self.layoutManager fillScreenEntirely];
61 62 63 64
}

- (void)setFillScreen:(BOOL)fillScreen
{
65
    [(VLCVideoLayoutManager*)self.layoutManager setFillScreenEntirely:fillScreen];
66 67 68
    [self setNeedsLayout];
}

69 70 71 72
/******************************************************************************
 * Implementation VLCVideoLayer  (Private)
 */

73
/* This is called by the libvlc module 'opengllayer' as soon as there is one
74 75
 * vout available
 */
76
- (void)addVoutLayer:(CALayer *)voutLayer
77 78
{
    [CATransaction begin];
79

80
    voutLayer.name = @"vlcopengllayer";
81

82 83 84
    VLCVideoLayoutManager * layoutManager = [VLCVideoLayoutManager layoutManager];
    layoutManager.originalVideoSize = voutLayer.bounds.size;
    self.layoutManager = layoutManager;
85

86
    [self insertSublayer:voutLayer atIndex:0];
87
    [self setNeedsDisplayOnBoundsChange:YES];
88

89
    [CATransaction commit];
90 91 92

    /* Trigger by hand, as it doesn't go through else. Assumed bug from Cocoa */
    [self willChangeValueForKey:@"hasVideo"];
93
    self.hasVideo = YES;
94
    [self didChangeValueForKey:@"hasVideo"];
95
}
96

97 98 99 100
- (void)removeVoutLayer:(CALayer*)voutLayer
{
    [CATransaction begin];
    [voutLayer removeFromSuperlayer];
101
    [CATransaction commit];
102

103 104
    /* Trigger by hand, as it doesn't go through else. Assumed bug from Cocoa */
    [self willChangeValueForKey:@"hasVideo"];
105
    _hasVideo = NO;
106
    [self didChangeValueForKey:@"hasVideo"];
107 108
}

109
@end