fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / ios / shared / ios_sharedlo / objective_c / render / MLORenderBuffer.m
blobb4dadc7c4c82c64b75c84f6bbf8be7f380b0166e
1 // -*- Mode: ObjC; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 //
3 // This file is part of the LibreOffice project.
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 #import "MLORenderBuffer.h"
10 #import "MLORenderManager_Impl.h"
11 #import "mlo_utils.h"
12 #import <QuartzCore/QuartzCore.h>
13 #include <touch/touch.h>
15 @interface  MLORenderBuffer ()
16 @property MLORenderManager * manager;
17 @end
18 static const CGFloat
19     MIN_AVERAGE_RENDER_TIME_THRESHOLD=1.0f/100.0f,
20     MIN_FPS=10.0f;
22 static const NSTimeInterval SCALING_ANIMATION_DURATION = 0.02f;
24 static CGFloat averageFps,maxFps;
25 @implementation MLORenderBuffer
27 -(id)initWithArrayIndex:(NSInteger) index renderManager:(MLORenderManager *) manager{
28     self= [self init];
29     if(self){
30         self.index = index;
31         self.manager = manager;
32         self.backgroundColor = [UIColor whiteColor];
33         self.previous = nil;
34     }
35     return self;
38 -(void)hide{
39     self.alpha = 0;
40     [self resetTransform];
43 -(void)setNeedsDisplayInRect:(CGRect)rect{
44     [self resetTransform];
45     [super setNeedsDisplayInRect:rect];
48 -(void) resetTransform{
49     if(self.frame.origin.x ||self.frame.origin.y ){
50         self.frame = CGRectMake(0,0,_manager.bufferFrame.size.width,_manager.bufferFrame.size.height);
51     }
54 - (void)drawRect:(CGRect)rect
56     if(ENABLE_LO_DESKTOP){
57         CGContextRef context = UIGraphicsGetCurrentContext();
58        
59         //rect = self.frame;
60         LOG_RECT(rect, @"drawRect");
61         
62         CGContextSaveGState(context);
63         CGContextSetFillColorWithColor(context,[UIColor whiteColor].CGColor);
64         CGContextTranslateCTM(context, 0, _manager.bufferFrame.size.height);
65         CGContextScaleCTM(context, 1, -1);
66         CGContextScaleCTM(context, 1, 1);
67         NSDate *startDate = [NSDate date];
68         
69         [_manager loRenderWillBegin];
70         
71         touch_lo_render_windows(context, rect.origin.y, rect.origin.y, rect.size.width, rect.size.height);
73         CGContextRestoreGState(context);
74         
75         CGFloat duration =  [[NSDate date] timeIntervalSinceDate: startDate];
76         
77         maxFps = max(maxFps,1.0f/duration);
78         
79         static float totalTime = 0,counter = 0;
80         
81         totalTime +=duration;
82         counter++;
83         
84         CGFloat averageTime = totalTime / counter;
85         if(averageTime >MIN_AVERAGE_RENDER_TIME_THRESHOLD){
86             averageFps = 1.0f/ averageTime;
87         }
88         
89         if(LOG_DRAW_RECT){
90             NSLog(@"drawRect: lo_render_windows: time=%f sec, average=%f sec, fps=%f",
91                   duration, averageTime, averageFps);
92         }
93         if(_manager.currentGesture != PINCH){
94             [_manager swapPreviousBuffer:_previous withNextBuffer:self];
95         }
96     }
99 +(CGFloat) getAverageFps{
100     return max(averageFps, MIN_FPS);
103 +(CGFloat) getMaxFps{
104     return max(maxFps, MIN_FPS);
107 @end