Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 352694 - GC can not capture screen correctly in MAC 10.7 lion
Summary: GC can not capture screen correctly in MAC 10.7 lion
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.6.2   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P3 critical (vote)
Target Milestone: 3.7.1   Edit
Assignee: Silenio Quarti CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-20 23:34 EDT by Fan Peng CLA
Modified: 2011-08-03 18:17 EDT (History)
7 users (show)

See Also:


Attachments
Sample to reproduce the issue (4.20 KB, application/octet-stream)
2011-07-21 00:23 EDT, Fan Peng CLA
no flags Details
patch (11.37 KB, patch)
2011-07-28 17:21 EDT, Silenio Quarti CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Fan Peng CLA 2011-07-20 23:34:56 EDT
Build Identifier: Eclipse SDK 3.6.2 carbon M20110105-0951

GC can not capture screen correctly in MAC 10.7 lion

Reproducible: Always

Steps to Reproduce:
Run the sample, it will capture an area and stored the contents into an image.
In MAC 10.7, it can not capture correctly(Both carbon and cocoa has this issue).
10.6 has no problem.
Comment 1 Fan Peng CLA 2011-07-21 00:23:42 EDT
Created attachment 200049 [details]
Sample to reproduce the issue

Sample to reproduce the issue
Comment 2 Felipe Heidrich CLA 2011-07-21 10:18:15 EDT
I believe we should try to fix this for 3.7.1

I request a MacOSX 10.7 today, hopefully I get it soon and the we will be ready to work on this.
Comment 3 Silenio Quarti CLA 2011-07-28 17:21:42 EDT
Created attachment 200560 [details]
patch

This patch uses CGDisplayCreateImage instead of CGDisplayBaseAddress when running in 10.7 and greater.   I have run the code in 10.6 (forcing the code to use CGDisplayCreateImage) and it works fine. I still do not have a 10.7 to try it on.
Comment 4 ChunYan Zhang CLA 2011-07-29 02:29:20 EDT
Put the reason about this problem here for reference.

This problem is caused by an apple API CGDisplayBaseAddress which is deprecated in Mac OS X v10.6.  In the copyArea() method in the GC.java of swt carbon and cocoa, they both called that deprecated API CGDisplayBaseAddress to get the base address in framebuffer memory of an online display. But this API will always return 0 on Mac 10.7. That's why this function both fail in swt carbon and cocoa On Mac 10.7. Apple recommends we should use CGDisplayCreateImage to copy screen data if CGDisplayBaseAddress is
deprecated. 

Quarz display service reference from Apple:
http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/Quartz_Services_Ref/Reference/reference.html#//apple_ref/c/func/CGDisplayCreateImage

CGDisplayBaseAddress
Returns the base address in framebuffer memory of an online display. (Available
in Mac OS X v10.0 through Mac OS X v10.6. There is no replacement; because
direct access to the raw framebuffer is not necessary, there is no need to
retrieve its memory address.)
void * CGDisplayBaseAddress (
   CGDirectDisplayID display
);
Parameters
display
The identifier of the display to be accessed.
Return Value
The base address in framebuffer memory of the specified display. If the display
ID is invalid, the return value is NULL.
Discussion
If the display has not been captured, the returned address may refer to
read-only memory.
Special Considerations
This deprecated function returned an address in framebuffer memory. Instead of
using the raw framebuffer to draw to the screen, you should instead use a
supported drawing engine such as Quartz or OpenGL. While accessing the
framebuffer directly has been deprecated, it is possible to copy screen data
using CGDisplayCreateImage.
Availability
                Available in Mac OS X v10.0 through Mac OS X v10.6.
                Deprecated in Mac OS X v10.6.


CGDisplayCreateImage
Returns an image containing the contents of the specified display.
CGImageRef CGDisplayCreateImage(
   CGDirectDisplayID displayID
);
Parameters
display
The identifier of the display for which an image is being created.
Return Value
An image containing the contents of the specified display. If the display ID is
invalid, the return value is NULL. The caller is responsible for releasing the
image created by calling CGImageRelease.
Availability
                Available in Mac OS X v10.6 and later.
Declared In
CGDirectDisplay.h
Declared In
CGDirectDisplay.h
Comment 5 ChunYan Zhang CLA 2011-07-29 02:30:29 EDT
I tried this patch on Mac 10.7. It works.  We will deliver this changes to resolve this problem. Thanks very much.

(In reply to comment #3)
> Created attachment 200560 [details]
> patch
> 
> This patch uses CGDisplayCreateImage instead of CGDisplayBaseAddress when
> running in 10.7 and greater.   I have run the code in 10.6 (forcing the code to
> use CGDisplayCreateImage) and it works fine. I still do not have a 10.7 to try
> it on.