tags:

views:

7600

answers:

8

Is it possible to mirror the Screen over the VGA Connector? Can't find anything about this.

+1  A: 

Each UIWindow object (basically the top level view) is assigned a screen (UIScreen) and you can of course set the screen you want. Therefore moving the main content to a second screen is easy, but mirroring is hard. (If you don't want a lecture on why it's ugly skip until the next paragraph) I believe this is apple's intention, both because drawing the same thing twice, one with a MUCH higher resolution, and because the experience of watching the interface before entering whatever presentation mode is rather subpar in comparison to seeing nothing until the video is playing, keynote presentation has started, etc. This is something you obviously want to consider on a case by case basis, but nonetheless mirroring is a Bad Idea.

UIWindow inherits from UIView, so although I don't have much personal experience with this exact thing, you should still be able to get it to draw to a bitmap context of some kind, and then use two different UIWindows each with only an image view on a them pushing the actual pixels to their respective screens. This is considerably easier if you only want to mirror one specific custom view (and not including it's subviews) because you can have that view on the device screen, (to capture any input) and then design it in a way that you have a method to call to draw it in whatever context it's in (some drawRects might work fine as is) and the call that from a super special awesome custom subview on the other screen, which would implement drawRect to just call the method on the actual view.

Hope this helps, sorry I ranted a bit :(

Jared P
Why do you say "one with a MUCH higher resolution"? I just hooked to a projector yesterday and it defaults to 1024x768 which is the same as the iPad. I wish by default it mirrored unless your app decided to display something else on the external. It would be really sweet for showing off application concepts.
jamone
While I agree that it would be cool for showing off the apps, keep in mind that apple doesn't think thats what people are going to be using this for primarily :P However, if you don't mind not seeing the screen on the iPad when its hooked up to an external display, its really easy to move the main UIWindow to the other UIScreen -- http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIScreen_Class/Reference/UIScreen.html
Jared P
+22  A: 

I was looking for the same thing you are. Last weekend I wrote a small UIApplication category to add mirroring support. I published to code on Google Code.

http://code.google.com/p/iphoneos-screen-mirroring/

To use it, you simply have to set it up in your application delegate's app did finish lauching. Like so:

[[UIApplication sharedApplication] setupScreenMirroringOfMainWindow:mainWindow framesPerSecond:20];

I only had one chance to try it out last weekend on a big screen TV with the Apple AV output cables. The performance is not stellar, thus I would not recommend using a frame rate higher than 30 fps...

François P.
Does not work here. Only black screen with [[UIApplication sharedApplication] setupScreenMirroringOfMainWindow:window framesPerSecond:20];How can i debug with VGA-Adapter on iPad?
x2on
The new version works with [[UIApplication sharedApplication] setupScreenMirroringWithFramesPerSecond:20.0]; but it is very slow.
x2on
I've pushed a new version that copies using the CALayer directly. I'll see if the performance is better tomorrow (could not try tonight as the dev iPad is gone).
François P.
Also, the new version runs a different NSRunLoop mode so it can grab pictures while you touch the screen, though it has a strong impact on performance (steals some CPU time to the UIScrollView deceleration timer etc...)
François P.
The new version does not work here. The application crash when an screen is attached. (Low memory)
x2on
It should work better now. Ooops fixed a big bad leak. I missed a CFRelease(mainWindowScreenshot); That's because UIGetScreenImage does NOT respect retain / release semantics. :-(
François P.
Now it works again ;) Thank you.
x2on
This works quite well for iPhone as well on OS4 beta. The screen is centered on the external display but clipped. Is there a way to scale the screen to fit?
mvexel
Hi, thanks for the code, but when you rotate the device, the screen beyond what is being mirrored flickers with some frames of the rotating animation and also the image is squeezed vertically. A circle on iPhone looks like an ellipse on TV.
Digital Robot
A: 

I'm trying to do something similar with an OpenGL project and I think by rendering my view once to a texture and then displaying that texture in two different windows the performance would not suffer. another approach would be to have two opengl contexts share the same framebuffer.

I also think this same technique would work with regular UIviews (as they are GL accelerated under the hood). can anyone with OpenGL experience point to an example of this?

joshue
A: 

Successfully used Francois's code. Thanks.

A: 

Thanks for sharing the code. I have tried it today. This works for iPad Application. But does not work for a iphone application installed in iPad. Part of the screen appears in external display. The UIGetScreenImage API does not capture screen properly when application type is iPhone. Is there any other way of capturing screen instead of using UIGetScreenImage?

OptMe
A: 

Hi,

I could not integrate the code to the xcode. I keep getting compilation references error on the CATranform3DIdentity, CATRansform3DRotation and even CADisplayLink

Could some guide me and enlighten me?

Josh
+4  A: 

This works great -- but app just got rejected for using private API... UIGetScreenImage();

CRUD!

Jay Van Vark
+1  A: 

I think it worth adding that the QuartzCore framework is mandatory, or you'll have 4 errors at compile time.

Undefined symbols:
  "_CATransform3DMakeRotation", referenced from:
      -[UIApplication(ScreenMirroring) updateMirroredWindowTransformForInterfaceOrientation:] in UIApplication+ScreenMirroring.o
      -[UIApplication(ScreenMirroring) updateMirroredWindowTransformForInterfaceOrientation:] in UIApplication+ScreenMirroring.o
      -[UIApplication(ScreenMirroring) updateMirroredWindowTransformForInterfaceOrientation:] in UIApplication+ScreenMirroring.o
  "_kCAGravityResizeAspect", referenced from:
      _kCAGravityResizeAspect$non_lazy_ptr in UIApplication+ScreenMirroring.o
     (maybe you meant: _kCAGravityResizeAspect$non_lazy_ptr)
  "_OBJC_CLASS_$_CADisplayLink", referenced from:
      objc-class-ref-to-CADisplayLink in UIApplication+ScreenMirroring.o
  "_CATransform3DIdentity", referenced from:
      _CATransform3DIdentity$non_lazy_ptr in UIApplication+ScreenMirroring.o
     (maybe you meant: _CATransform3DIdentity$non_lazy_ptr)
ld: symbol(s) not found
collect2: ld returned 1 exit status
Rob