Kaydet (Commit) bb0b2744 authored tarafından Tor Lillqvist's avatar Tor Lillqvist

Draw the frame virtual device bitmaps directly to the destination CGContext

Much faster. No need for the pixelBuffer inbetween.

Change-Id: I6493faca6da3a3e9a1285e00c887928b85dca56e
üst 378d3896
......@@ -11,11 +11,6 @@
#import "View.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
int nbytes;
char *pixelBuffer;
CGImageRef image;
}
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) View *view;
......
......@@ -44,17 +44,6 @@ static UIView *theView;
[self.window addGestureRecognizer: tapRecognizer];
nbytes = bounds.size.width * bounds.size.height * 4;
pixelBuffer = (char *) malloc(nbytes);
memset(pixelBuffer, 0xFF, nbytes);
CGDataProviderRef provider = CGDataProviderCreateWithData( NULL, pixelBuffer, nbytes, NULL);
image = CGImageCreate(bounds.size.width, bounds.size.height, 8, 32, bounds.size.width*4, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaNoneSkipLast, provider, NULL, false, kCGRenderingIntentDefault);
self.view.pixelBuffer = pixelBuffer;
self.view.image = image;
lo_set_view_size(bounds.size.width, bounds.size.height);
NSThread* thread = [[NSThread alloc] initWithTarget:self
......@@ -105,7 +94,9 @@ static UIView *theView;
void lo_damaged(CGRect rect)
{
(void) rect;
[theView performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone:NO];
dispatch_async(dispatch_get_main_queue(), ^{
[theView setNeedsDisplayInRect:rect];
});
// NSLog(@"lo_damaged: %dx%d@(%d,%d)", (int)rect.size.width, (int)rect.size.height, (int)rect.origin.x, (int)rect.origin.y);
}
......
......@@ -11,9 +11,6 @@
@interface View : UIView
@property char *pixelBuffer;
@property CGImageRef image;
- (void)drawRect:(CGRect)rect;
- (void)tapGesture:(UIGestureRecognizer *)gestureRecognizer;
......
......@@ -14,18 +14,18 @@
- (void)drawRect:(CGRect)rect
{
(void) rect;
// NSLog(@"drawRect: %fx%f@(%f,%f)", rect.size.width, rect.size.height, rect.origin.x, rect.origin.y);
NSDate *a = [NSDate date];
lo_render_windows([self pixelBuffer], [self bounds].size.width, [self bounds].size.height);
NSLog(@"drawRect: lo_render_windows took %f s", [[NSDate date] timeIntervalSinceDate: a]);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGContextTranslateCTM(context, 0, self.frame.size.height);
CGContextScaleCTM(context, 1, -1);
lo_render_windows(context, rect);
CGContextRestoreGState(context);
CGContextDrawImage(context, [self bounds], [self image]);
NSLog(@"drawRect: lo_render_windows took %f s", [[NSDate date] timeIntervalSinceDate: a]);
}
- (void) tapGesture:(UIGestureRecognizer *)gestureRecognizer
......
......@@ -12,7 +12,7 @@
#if defined(IOS)
#include <CoreGraphics/CGGeometry.h>
#include <CoreGraphics/CoreGraphics.h>
#ifdef __cplusplus
extern "C" {
......@@ -45,7 +45,7 @@ void lo_damaged(CGRect rect);
void lo_runMain();
void lo_set_view_size(int width, int height);
void lo_render_windows(char *pixelBuffer, int width, int height);
void lo_render_windows(CGContextRef context, CGRect rect);
void lo_tap(int x, int y);
#ifdef __cplusplus
......
......@@ -304,11 +304,37 @@ void lo_set_view_size(int width, int height)
}
extern "C"
void lo_render_windows(char *pixelBuffer, int width, int height)
void lo_render_windows( CGContextRef context, CGRect rect )
{
// Hack: assume so far that we are asked to redraw the whole pixel buffer
if (IosSalInstance::getInstance() != NULL)
IosSalInstance::getInstance()->RedrawWindows(pixelBuffer, width, height, 0, 0, width, height);
if( IosSalInstance::getInstance() != NULL ) {
int i = 0;
std::list< SalFrame* >::const_iterator it;
for( it = IosSalInstance::getInstance()->getFrames().begin(); it != IosSalInstance::getInstance()->getFrames().end(); i++, it++ ) {
SvpSalFrame *pFrame = static_cast<SvpSalFrame *>(*it);
SalFrameGeometry aGeom = pFrame->GetGeometry();
CGRect bbox = CGRectMake( aGeom.nX, aGeom.nY, aGeom.nWidth, aGeom.nHeight );
if ( pFrame->IsVisible() &&
CGRectIntersectsRect( rect, bbox ) ) {
const basebmp::BitmapDeviceSharedPtr aDevice = pFrame->getDevice();
CGDataProviderRef provider =
CGDataProviderCreateWithData( NULL,
aDevice->getBuffer().get(),
aDevice->getSize().getY() * aDevice->getScanlineStride(),
NULL );
CGImage *image =
CGImageCreate( aDevice->getSize().getX(), aDevice->getSize().getY(),
8, 32, aDevice->getScanlineStride(),
CGColorSpaceCreateDeviceRGB(),
kCGImageAlphaNoneSkipLast,
provider,
NULL,
false,
kCGRenderingIntentDefault );
CGContextDrawImage( context, bbox, image );
}
}
}
}
extern "C"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment