12047
|
1 |
/*
|
|
2 |
* Copyright (c) 2011, 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 |
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 |
}
|
|
54 |
typedef ContextInfo;
|
|
55 |
|
|
56 |
struct _ImageInfo
|
|
57 |
{
|
|
58 |
size_t bitsPerComponent;
|
|
59 |
size_t bitsPerPixel;
|
|
60 |
size_t bytesPerPixel;
|
|
61 |
size_t bytesPerRow;
|
|
62 |
CGImageAlphaInfo alphaInfo;
|
|
63 |
CGColorSpaceRef colorSpace;
|
|
64 |
}
|
|
65 |
typedef ImageInfo;
|
|
66 |
|
|
67 |
struct _ImageSDOps
|
|
68 |
{
|
|
69 |
QuartzSDOps qsdo; // must be the first entry!
|
|
70 |
|
|
71 |
ContextInfo contextInfo;
|
|
72 |
ImageInfo imageInfo;
|
|
73 |
BOOL isSubImage;
|
|
74 |
|
|
75 |
jint* javaImageInfo;
|
|
76 |
|
|
77 |
// parameters specifying this BufferedImage given to us from Java
|
|
78 |
jobject array;
|
|
79 |
jint offset;
|
|
80 |
jint width;
|
|
81 |
jint height;
|
|
82 |
jint javaPixelBytes;
|
|
83 |
jint javaPixelsBytesPerRow;
|
|
84 |
jobject icm;
|
|
85 |
jint type;
|
|
86 |
|
|
87 |
Pixel8bit* pixels;
|
|
88 |
Pixel8bit* pixelsLocked;
|
|
89 |
|
|
90 |
// needed by TYPE_BYTE_INDEXED
|
|
91 |
UInt16* indexedColorTable;
|
|
92 |
UInt32* lutData;
|
|
93 |
UInt32 lutDataSize;
|
|
94 |
|
|
95 |
// Used as a cached image ref created from the isdo.dataprovider. This is only a chached image, and it might become invalid
|
|
96 |
// if somebody draws on the bitmap context, or the pixels are changed in java. In that case, we need to NULL out
|
|
97 |
// this image and recreate it from the data provider.
|
|
98 |
CGImageRef imgRef;
|
|
99 |
|
|
100 |
// Cached instance of CGDataProvider. dataProvider is alloced the first time a bitmap context is created, providing the
|
|
101 |
// native pixels as a source of the data. The dataProviders life cycle is the same as ISDO. The reference gets
|
|
102 |
// released when we are done with the ISDO.
|
|
103 |
CGDataProviderRef dataProvider;
|
|
104 |
|
|
105 |
// Pointer in memory that is used for create the CGBitmapContext and the CGDataProvider (used for imgRef). This is a native
|
|
106 |
// copy of the pixels for the Image. There is a spearate copy of the pixels that lives in Java heap. There are two main
|
|
107 |
// reasons why we keep those pixels spearate: 1) CG doesn't support all the Java pixel formats 2) The Garbage collector can
|
|
108 |
// move the java pixels at any time. There are possible workarounds for both problems. Number 2) seems to be a more serious issue, since
|
|
109 |
// we can solve 1) by only supporting certain image types.
|
|
110 |
void * nativePixels;
|
|
111 |
NSGraphicsContext* nsRef;
|
|
112 |
|
|
113 |
pthread_mutex_t lock;
|
|
114 |
jint nrOfPixelsOwners;
|
|
115 |
};
|
|
116 |
|