Re: Hardware-accelerated scaling on iOS without OpenGL

2016-11-25 Thread David Duncan
The transform is a reasonable way to go. You can also change the contentMode to 
get scaling for free. Fundamentally this all ends up as a texture draw on the 
GPU so how you get the geometry for the draw there is nearly irrelevant.

The major performance gain from OpenGL (or Metal) in this case is that you can 
avoid an additional buffer copy and composite on the way to the display in many 
circumstances. This may not be significant in your case however.

--
David Duncan @ My iPhone

> On Nov 25, 2016, at 11:38 AM, Andreas Falkenhahn  
> wrote:
> 
>> On 25.11.2016 at 16:29 David Duncan wrote:
>> 
>> The fastest method without OpenGL is to work with CGImage directly
>> and assign the image as the contents of a CALayer.
> 
>> This will engage CoreAnimation to use the hardware to scale the
>> image, but is still not quite as fast as OpenGL for the same task.
> 
>> Roughly you'll want to look at CGImageCreate and
>> CGDataProviderCreate (there are a number of variants of the latter).
> 
> Thanks, I've just tried this and the performance seems reasonably well.
> I don't know how fast direct OpenGL would be but it looks like the
> CALayer approach is already sufficiently fast enough.
> 
> But just to make sure I implemented this in the right way: Assigning the
> image as the contents of my view's CALayer means that I shouldn't draw
> in drawRect() at all but just do the following whenever I need to draw
> a new frame:
> 
>myImage = CGImageCreate(...);
>view.layer.contents = (id) myImage;
>CGImageRelease(myImage);
> 
> Is that right? I have to create a new CGImageRef for every frame I draw
> because CGImages are immutable objects, right? 
> 
> And to scale the whole shebang from 320x240 to full screen I just set
> 
>view.transform = CGAffineTransformScale(CGAffineTransformIdentity, scalex, 
> scaley);
> 
> Or is there a better way to force a view into full screen by scaling?
> 
> -- 
> Best regards,
> Andreas Falkenhahnmailto:andr...@falkenhahn.com
> 

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Hardware-accelerated scaling on iOS without OpenGL

2016-11-25 Thread Alex Zavatone

On Nov 25, 2016, at 10:38 AM, Andreas Falkenhahn wrote:

> On 25.11.2016 at 16:29 David Duncan wrote:
> 
>> The fastest method without OpenGL is to work with CGImage directly
>> and assign the image as the contents of a CALayer.
> 
>> This will engage CoreAnimation to use the hardware to scale the
>> image, but is still not quite as fast as OpenGL for the same task.
> 
>> Roughly you'll want to look at CGImageCreate and
>> CGDataProviderCreate (there are a number of variants of the latter).
> 
> Thanks, I've just tried this and the performance seems reasonably well.
> I don't know how fast direct OpenGL would be but it looks like the
> CALayer approach is already sufficiently fast enough.
> 
> But just to make sure I implemented this in the right way: Assigning the
> image as the contents of my view's CALayer means that I shouldn't draw
> in drawRect() at all but just do the following whenever I need to draw
> a new frame:
> 
>myImage = CGImageCreate(...);
>view.layer.contents = (id) myImage;
>CGImageRelease(myImage);
> 
> Is that right? I have to create a new CGImageRef for every frame I draw
> because CGImages are immutable objects, right? 
> 
> And to scale the whole shebang from 320x240 to full screen I just set
> 
>view.transform = CGAffineTransformScale(CGAffineTransformIdentity, scalex, 
> scaley);
> 
> Or is there a better way to force a view into full screen by scaling?
> 
> -- 
> Best regards,
> Andreas Falkenhahnmailto:andr...@falkenhahn.com

The view transform seems to be the best approach to me.  To make sure that 
performance is good enough, log the time elapsed before and after the operation 
so you have a good idea how long the operation really takes.



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Hardware-accelerated scaling on iOS without OpenGL

2016-11-25 Thread Andreas Falkenhahn
On 25.11.2016 at 16:29 David Duncan wrote:

> The fastest method without OpenGL is to work with CGImage directly
> and assign the image as the contents of a CALayer.

> This will engage CoreAnimation to use the hardware to scale the
> image, but is still not quite as fast as OpenGL for the same task.

> Roughly you'll want to look at CGImageCreate and
> CGDataProviderCreate (there are a number of variants of the latter).

Thanks, I've just tried this and the performance seems reasonably well.
I don't know how fast direct OpenGL would be but it looks like the
CALayer approach is already sufficiently fast enough.

But just to make sure I implemented this in the right way: Assigning the
image as the contents of my view's CALayer means that I shouldn't draw
in drawRect() at all but just do the following whenever I need to draw
a new frame:

myImage = CGImageCreate(...);
view.layer.contents = (id) myImage;
CGImageRelease(myImage);

Is that right? I have to create a new CGImageRef for every frame I draw
because CGImages are immutable objects, right? 

And to scale the whole shebang from 320x240 to full screen I just set

view.transform = CGAffineTransformScale(CGAffineTransformIdentity, scalex, 
scaley);

Or is there a better way to force a view into full screen by scaling?

-- 
Best regards,
 Andreas Falkenhahnmailto:andr...@falkenhahn.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Hardware-accelerated scaling on iOS without OpenGL

2016-11-25 Thread David Duncan
The fastest method without OpenGL is to work with CGImage directly and assign 
the image as the contents of a CALayer.

This will engage CoreAnimation to use the hardware to scale the image, but is 
still not quite as fast as OpenGL for the same task.

Roughly you'll want to look at CGImageCreate and CGDataProviderCreate (there 
are a number of variants of the latter). Much sample code will try using 
CGBitmapContextCreateImage because it looks easier, but this will take a kernel 
hit for each frame and mark the memory copy-on-write which will cause you to 
take another hit when the memory gets written to. 

--
David Duncan @ My iPhone

> On Nov 25, 2016, at 10:22 AM, Andreas Falkenhahn  
> wrote:
> 
> I'm currently writing an iOS backend for a cross-platform program whose
> platform-independent engine writes all of its graphics into 32-bit pixel
> buffers, in RGBA order. The alpha byte isn't used. The graphics are always
> opaque so I don't need alpha blending.
> 
> What is the most efficient option to draw and scale these pixel buffers to
> my CGContextRef inside my drawRect method? The pixel buffers are usually
> only 320x240 pixels and need to be scaled to completely fill my view's
> dimensions, e.g. 1024x768 on non-Retina iPads and 2048x1536 on Retina iPads.
> This is a whole lot of work so it's best done using the GPU. But how can I
> force iOS to draw and scale using the GPU without using OpenGL?
> 
> I've tried using CGContextDrawImage() but this is really slow, probably 
> because
> everything is done using the CPU.
> 
> I've also had a look at the CIImage APIs because these are apparently GPU
> optimized but the problem is that CIImage objects are immutable so I'd have to
> constantly create new CIImage objects for each frame I need to draw which will
> probably kill the performance as well.
> 
> I could go with OpenGL of course but I'd like to get some feedback on whether
> there is an easier solution to get what I want here.
> 
> Thanks for any ideas!
> 
> -- 
> Best regards,
> Andreas Falkenhahn  mailto:andr...@falkenhahn.com
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Hardware-accelerated scaling on iOS without OpenGL

2016-11-25 Thread Andreas Falkenhahn
I'm currently writing an iOS backend for a cross-platform program whose
platform-independent engine writes all of its graphics into 32-bit pixel
buffers, in RGBA order. The alpha byte isn't used. The graphics are always
opaque so I don't need alpha blending.

What is the most efficient option to draw and scale these pixel buffers to
my CGContextRef inside my drawRect method? The pixel buffers are usually
only 320x240 pixels and need to be scaled to completely fill my view's
dimensions, e.g. 1024x768 on non-Retina iPads and 2048x1536 on Retina iPads.
This is a whole lot of work so it's best done using the GPU. But how can I
force iOS to draw and scale using the GPU without using OpenGL?

I've tried using CGContextDrawImage() but this is really slow, probably because
everything is done using the CPU.

I've also had a look at the CIImage APIs because these are apparently GPU
optimized but the problem is that CIImage objects are immutable so I'd have to
constantly create new CIImage objects for each frame I need to draw which will
probably kill the performance as well.

I could go with OpenGL of course but I'd like to get some feedback on whether
there is an easier solution to get what I want here.

Thanks for any ideas!

-- 
Best regards,
 Andreas Falkenhahn  mailto:andr...@falkenhahn.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com