xref: /aosp_15_r20/external/deqp/framework/platform/ios/tcuIOSViewController.m (revision 35238bce31c2a825756842865a792f8cf7f89930)
1/*-------------------------------------------------------------------------
2 * drawElements Quality Program Tester Core
3 * ----------------------------------------
4 *
5 * Copyright 2014 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 *      http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 *//*!
20 * \file
21 * \brief iOS View Controller.
22 *//*--------------------------------------------------------------------*/
23
24#import <QuartzCore/QuartzCore.h>
25
26#import "tcuEAGLView.h"
27#import "tcuIOSViewController.h"
28
29#include "qpDebugOut.h"
30
31@interface tcuIOSViewController ()
32@property(nonatomic, assign) CADisplayLink *displayLink;
33@end
34
35@implementation tcuIOSViewController
36
37@synthesize displayLink;
38
39- (void)loadView
40{
41    tcuEAGLView *view = [[tcuEAGLView alloc]
42        initWithFrame:[UIScreen mainScreen].applicationFrame];
43    self.view = view;
44    [view release];
45}
46
47- (void)viewDidLoad
48{
49    [super viewDidLoad];
50
51    isIterating = FALSE;
52    self.displayLink = nil;
53    app = tcuIOSApp_create(self.view);
54}
55
56- (void)dealloc
57{
58    [super dealloc];
59}
60
61- (void)didReceiveMemoryWarning
62{
63    [super didReceiveMemoryWarning];
64}
65
66- (void)viewWillAppear:(BOOL)animated
67{
68    [super viewWillAppear:animated];
69}
70
71- (void)viewWillDisappear:(BOOL)animated
72{
73    [super viewWillDisappear:animated];
74}
75
76- (void)viewDidUnload
77{
78    [super viewDidUnload];
79}
80
81- (void)startTestIteration
82{
83    if (!isIterating)
84    {
85        DE_ASSERT(self.displayLink == nil);
86
87        // Obtain display link.
88        self.displayLink =
89            [[UIScreen mainScreen] displayLinkWithTarget:self
90                                                selector:@selector(iterate)];
91        [self.displayLink setFrameInterval:1];
92        [self.displayLink addToRunLoop:[NSRunLoop currentRunLoop]
93                               forMode:NSDefaultRunLoopMode];
94
95        isIterating = TRUE;
96    }
97}
98
99- (void)stopTestIteration
100{
101    if (isIterating)
102    {
103        isIterating = FALSE;
104        [self.displayLink invalidate];
105        self.displayLink = nil;
106    }
107}
108
109- (void)iterate
110{
111    if (isIterating)
112    {
113        bool result = tcuIOSApp_iterate(app);
114
115        if (!result)
116        {
117            [self stopTestIteration];
118            qpDief("Fatal error occurred in test execution, killing process.");
119        }
120    }
121}
122
123@end
124