How to click pixels faster on iPhone?

I asked before about pixel click, and now I managed to get far enough so that noise appeared on the screen. Here's how I get started:

CGDataProviderRef provider;
bitmap = malloc(320*480*4);
provider = CGDataProviderCreateWithData(NULL, bitmap, 320*480*4, NULL);
CGColorSpaceRef colorSpaceRef;
colorSpaceRef = CGColorSpaceCreateDeviceRGB();
ir = CGImageCreate(
320,
480,
8,
32,
4 * 320,
colorSpaceRef,
kCGImageAlphaNoneSkipLast,
provider,
NULL,
NO,
kCGRenderingIntentDefault
);

This is how I draw each frame:

for (int i=0; i<320*480*4; i++) {
bitmap[i] = rand()%256;
}
CGRect rect = CGRectMake(0, 0, 320, 480);
CGContextDrawImage(context, rect, ir); 

The problem is that it is terribly slow, about 5 frames per second. I think my buffer publishing path should be wrong. Is it possible to do pixel-based full-screen graphics at all, which I could update at 30 frames per second without using a 3D chip?

+3
source share
4 answers

Slowness almost certainly occurs in noise generation. If you run this in Tools, you will probably see a lot of time spent in your loop.

- . , , .

CoreGraphics , , CGLayer , .

bytesPerRow . 32 IIRC. , , .

, OpenGL.

+2

, 614400 (320*480*4), , .

, ? , ? CGRect?

, , , .

+1

, OpenGL iPhone. 2D 3D. UIView , OpenGL. .

+1

CGContextDrawImage, CGImageRef -[CALayer setContents:], , .

[[view layer] setContents:(id)ir];

, , , Google

+1

Source: https://habr.com/ru/post/1698169/


All Articles