|
1 /* |
|
2 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Oracle designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Oracle in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 * or visit www.oracle.com if you need additional information or have any |
|
23 * questions. |
|
24 */ |
|
25 |
|
26 #import "QuartzSurfaceData.h" |
|
27 #import <pthread.h> |
|
28 |
|
29 typedef UInt8 Pixel8bit; |
|
30 typedef UInt16 Pixel16bit; |
|
31 typedef UInt32 Pixel32bit; |
|
32 |
|
33 typedef struct _ImageSDOps ImageSDOps; |
|
34 |
|
35 ImageSDOps* LockImage(JNIEnv* env, jobject imageSurfaceData); |
|
36 void UnlockImage(JNIEnv* env, ImageSDOps* isdo); |
|
37 ImageSDOps* LockImagePixels(JNIEnv* env, jobject imageSurfaceData); |
|
38 void UnlockImagePixels(JNIEnv* env, ImageSDOps* isdo); |
|
39 |
|
40 // if there is no image created for isdo.imgRef, it creates and image using the isdo.dataProvider |
|
41 // If there is an image present, this is a no-op |
|
42 void makeSureImageIsCreated(ImageSDOps* isdo); |
|
43 |
|
44 typedef struct _ContextInfo |
|
45 { |
|
46 BOOL useWindowContextReference; |
|
47 BOOL canUseJavaPixelsAsContext; |
|
48 size_t bitsPerComponent; |
|
49 size_t bytesPerPixel; |
|
50 size_t bytesPerRow; |
|
51 CGImageAlphaInfo alphaInfo; |
|
52 CGColorSpaceRef colorSpace; |
|
53 } ContextInfo; |
|
54 |
|
55 typedef struct _ImageInfo |
|
56 { |
|
57 size_t bitsPerComponent; |
|
58 size_t bitsPerPixel; |
|
59 size_t bytesPerPixel; |
|
60 size_t bytesPerRow; |
|
61 CGImageAlphaInfo alphaInfo; |
|
62 CGColorSpaceRef colorSpace; |
|
63 } ImageInfo; |
|
64 |
|
65 struct _ImageSDOps |
|
66 { |
|
67 QuartzSDOps qsdo; // must be the first entry! |
|
68 |
|
69 ContextInfo contextInfo; |
|
70 ImageInfo imageInfo; |
|
71 BOOL isSubImage; |
|
72 |
|
73 jint* javaImageInfo; |
|
74 |
|
75 // parameters specifying this BufferedImage given to us from Java |
|
76 jobject array; |
|
77 jint offset; |
|
78 jint width; |
|
79 jint height; |
|
80 jint javaPixelBytes; |
|
81 jint javaPixelsBytesPerRow; |
|
82 jobject icm; |
|
83 jint type; |
|
84 |
|
85 Pixel8bit* pixels; |
|
86 Pixel8bit* pixelsLocked; |
|
87 |
|
88 // needed by TYPE_BYTE_INDEXED |
|
89 UInt16* indexedColorTable; |
|
90 UInt32* lutData; |
|
91 UInt32 lutDataSize; |
|
92 |
|
93 // Used as a cached image ref created from the isdo.dataprovider. This is only a chached image, and it might become invalid |
|
94 // if somebody draws on the bitmap context, or the pixels are changed in java. In that case, we need to NULL out |
|
95 // this image and recreate it from the data provider. |
|
96 CGImageRef imgRef; |
|
97 |
|
98 // Cached instance of CGDataProvider. dataProvider is alloced the first time a bitmap context is created, providing the |
|
99 // native pixels as a source of the data. The dataProviders life cycle is the same as ISDO. The reference gets |
|
100 // released when we are done with the ISDO. |
|
101 CGDataProviderRef dataProvider; |
|
102 |
|
103 // Pointer in memory that is used for create the CGBitmapContext and the CGDataProvider (used for imgRef). This is a native |
|
104 // copy of the pixels for the Image. There is a spearate copy of the pixels that lives in Java heap. There are two main |
|
105 // reasons why we keep those pixels spearate: 1) CG doesn't support all the Java pixel formats 2) The Garbage collector can |
|
106 // move the java pixels at any time. There are possible workarounds for both problems. Number 2) seems to be a more serious issue, since |
|
107 // we can solve 1) by only supporting certain image types. |
|
108 void * nativePixels; |
|
109 NSGraphicsContext* nsRef; |
|
110 |
|
111 pthread_mutex_t lock; |
|
112 jint nrOfPixelsOwners; |
|
113 }; |
|
114 |