src/macosx/native/sun/java2d/opengl/CGLLayer.m

Print this page




  44 @synthesize parentLayer;
  45 @synthesize remoteLayer;
  46 @synthesize jrsRemoteLayer;
  47 #endif
  48 
  49 - (id) initWithJavaLayer:(JNFJObjectWrapper *)layer;
  50 {
  51 AWT_ASSERT_APPKIT_THREAD;
  52     // Initialize ourselves
  53     self = [super init];
  54     if (self == nil) return self;
  55 
  56     self.javaLayer = layer;
  57 
  58     // NOTE: async=YES means that the layer is re-cached periodically
  59     self.asynchronous = FALSE;
  60     self.contentsGravity = kCAGravityTopLeft;
  61     //Layer backed view
  62     //self.needsDisplayOnBoundsChange = YES;
  63     //self.autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable;













  64     textureID = 0; // texture will be created by rendering pipe
  65     target = 0;
  66 
  67     return self;
  68 }
  69 
  70 - (void) dealloc {
  71     self.javaLayer = nil;
  72     [super dealloc];
  73 }
  74 
  75 - (CGLPixelFormatObj)copyCGLPixelFormatForDisplayMask:(uint32_t)mask {
  76     return CGLRetainPixelFormat(sharedPixelFormat.CGLPixelFormatObj);
  77 }
  78 
  79 - (CGLContextObj)copyCGLContextForPixelFormat:(CGLPixelFormatObj)pixelFormat {
  80     CGLContextObj contextObj = NULL;
  81     CGLCreateContext(pixelFormat, sharedContext.CGLContextObj, &contextObj);
  82     return contextObj;
  83 }


 104     glTexCoord2f(swid, 0.0f); glVertex2f( 1.0f, -1.0f);
 105     glTexCoord2f(swid, shgt); glVertex2f( 1.0f,  1.0f);
 106     glTexCoord2f(0.0f, shgt); glVertex2f(-1.0f,  1.0f);
 107     glEnd();
 108 
 109     glBindTexture(target, 0);
 110     glDisable(target);
 111 }
 112 
 113 -(BOOL)canDrawInCGLContext:(CGLContextObj)glContext pixelFormat:(CGLPixelFormatObj)pixelFormat forLayerTime:(CFTimeInterval)timeInterval displayTime:(const CVTimeStamp *)timeStamp{
 114     return textureID == 0 ? NO : YES;
 115 }
 116 
 117 -(void)drawInCGLContext:(CGLContextObj)glContext pixelFormat:(CGLPixelFormatObj)pixelFormat forLayerTime:(CFTimeInterval)timeInterval displayTime:(const CVTimeStamp *)timeStamp
 118 {
 119     AWT_ASSERT_APPKIT_THREAD;
 120 
 121     // Set the current context to the one given to us.
 122     CGLSetCurrentContext(glContext);
 123 




 124     glViewport(0, 0, textureWidth, textureHeight);
 125 
 126     JNIEnv *env = [ThreadUtilities getJNIEnv];
 127     static JNF_CLASS_CACHE(jc_JavaLayer, "sun/java2d/opengl/CGLLayer");
 128     static JNF_MEMBER_CACHE(jm_drawInCGLContext, jc_JavaLayer, "drawInCGLContext", "()V");
 129 
 130     jobject javaLayerLocalRef = [self.javaLayer jObjectWithEnv:env];
 131     JNFCallVoidMethod(env, javaLayerLocalRef, jm_drawInCGLContext);
 132     (*env)->DeleteLocalRef(env, javaLayerLocalRef);
 133 
 134     // Call super to finalize the drawing. By default all it does is call glFlush().
 135     [super drawInCGLContext:glContext pixelFormat:pixelFormat forLayerTime:timeInterval displayTime:timeStamp];
 136 
 137     CGLSetCurrentContext(NULL);
 138 }
 139 
 140 @end
 141 
 142 /*
 143  * Class:     sun_java2d_opengl_CGLLayer


 151     __block CGLLayer *layer = nil;
 152 
 153 JNF_COCOA_ENTER(env);
 154 
 155     JNFJObjectWrapper *javaLayer = [JNFJObjectWrapper wrapperWithJObject:obj withEnv:env];
 156 
 157     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
 158             AWT_ASSERT_APPKIT_THREAD;
 159         
 160             layer = [[CGLLayer alloc] initWithJavaLayer: javaLayer];
 161     }];
 162     
 163 JNF_COCOA_EXIT(env);
 164 
 165     return ptr_to_jlong(layer);
 166 }
 167 
 168 // Must be called under the RQ lock.
 169 JNIEXPORT void JNICALL
 170 Java_sun_java2d_opengl_CGLLayer_validate
 171 (JNIEnv *env, jobject obj, jlong layerPtr, jobject surfaceData)
 172 {
 173     CGLLayer *layer = OBJC(layerPtr);
 174 
 175     if (surfaceData != NULL) {
 176         OGLSDOps *oglsdo = (OGLSDOps*) SurfaceData_GetOps(env, surfaceData);
 177         layer.textureID = oglsdo->textureID;
 178         layer.target = GL_TEXTURE_2D;
 179         layer.textureWidth = oglsdo->width;
 180         layer.textureHeight = oglsdo->height;
 181     } else {
 182         layer.textureID = 0;
 183     }
 184 }
 185 
 186 // Must be called on the AppKit thread and under the RQ lock.
 187 JNIEXPORT void JNICALL
 188 Java_sun_java2d_opengl_CGLLayer_blitTexture
 189 (JNIEnv *env, jobject obj, jlong layerPtr)
 190 {
 191     CGLLayer *layer = jlong_to_ptr(layerPtr);
 192 
 193     [layer blitTexture];
 194 }














  44 @synthesize parentLayer;
  45 @synthesize remoteLayer;
  46 @synthesize jrsRemoteLayer;
  47 #endif
  48 
  49 - (id) initWithJavaLayer:(JNFJObjectWrapper *)layer;
  50 {
  51 AWT_ASSERT_APPKIT_THREAD;
  52     // Initialize ourselves
  53     self = [super init];
  54     if (self == nil) return self;
  55 
  56     self.javaLayer = layer;
  57 
  58     // NOTE: async=YES means that the layer is re-cached periodically
  59     self.asynchronous = FALSE;
  60     self.contentsGravity = kCAGravityTopLeft;
  61     //Layer backed view
  62     //self.needsDisplayOnBoundsChange = YES;
  63     //self.autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable;
  64 
  65     //Disable CALayer's default animation
  66     NSMutableDictionary * actions = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
  67                                     [NSNull null], @"bounds",
  68                                     [NSNull null], @"contents",
  69                                     [NSNull null], @"contentsScale",
  70                                     [NSNull null], @"onOrderIn",
  71                                     [NSNull null], @"onOrderOut",
  72                                     [NSNull null], @"sublayers",
  73                                     nil];
  74     self.actions = actions;
  75     [actions release];
  76 
  77     textureID = 0; // texture will be created by rendering pipe
  78     target = 0;
  79 
  80     return self;
  81 }
  82 
  83 - (void) dealloc {
  84     self.javaLayer = nil;
  85     [super dealloc];
  86 }
  87 
  88 - (CGLPixelFormatObj)copyCGLPixelFormatForDisplayMask:(uint32_t)mask {
  89     return CGLRetainPixelFormat(sharedPixelFormat.CGLPixelFormatObj);
  90 }
  91 
  92 - (CGLContextObj)copyCGLContextForPixelFormat:(CGLPixelFormatObj)pixelFormat {
  93     CGLContextObj contextObj = NULL;
  94     CGLCreateContext(pixelFormat, sharedContext.CGLContextObj, &contextObj);
  95     return contextObj;
  96 }


 117     glTexCoord2f(swid, 0.0f); glVertex2f( 1.0f, -1.0f);
 118     glTexCoord2f(swid, shgt); glVertex2f( 1.0f,  1.0f);
 119     glTexCoord2f(0.0f, shgt); glVertex2f(-1.0f,  1.0f);
 120     glEnd();
 121 
 122     glBindTexture(target, 0);
 123     glDisable(target);
 124 }
 125 
 126 -(BOOL)canDrawInCGLContext:(CGLContextObj)glContext pixelFormat:(CGLPixelFormatObj)pixelFormat forLayerTime:(CFTimeInterval)timeInterval displayTime:(const CVTimeStamp *)timeStamp{
 127     return textureID == 0 ? NO : YES;
 128 }
 129 
 130 -(void)drawInCGLContext:(CGLContextObj)glContext pixelFormat:(CGLPixelFormatObj)pixelFormat forLayerTime:(CFTimeInterval)timeInterval displayTime:(const CVTimeStamp *)timeStamp
 131 {
 132     AWT_ASSERT_APPKIT_THREAD;
 133 
 134     // Set the current context to the one given to us.
 135     CGLSetCurrentContext(glContext);
 136 
 137     // Should clear the whole CALayer, because it can be larger than our texture.
 138     glClearColor(0.0, 0.0, 0.0, 0.0);
 139     glClear(GL_COLOR_BUFFER_BIT);
 140 
 141     glViewport(0, 0, textureWidth, textureHeight);
 142     
 143     JNIEnv *env = [ThreadUtilities getJNIEnv];
 144     static JNF_CLASS_CACHE(jc_JavaLayer, "sun/java2d/opengl/CGLLayer");
 145     static JNF_MEMBER_CACHE(jm_drawInCGLContext, jc_JavaLayer, "drawInCGLContext", "()V");
 146 
 147     jobject javaLayerLocalRef = [self.javaLayer jObjectWithEnv:env];
 148     JNFCallVoidMethod(env, javaLayerLocalRef, jm_drawInCGLContext);
 149     (*env)->DeleteLocalRef(env, javaLayerLocalRef);
 150 
 151     // Call super to finalize the drawing. By default all it does is call glFlush().
 152     [super drawInCGLContext:glContext pixelFormat:pixelFormat forLayerTime:timeInterval displayTime:timeStamp];
 153 
 154     CGLSetCurrentContext(NULL);
 155 }
 156 
 157 @end
 158 
 159 /*
 160  * Class:     sun_java2d_opengl_CGLLayer


 168     __block CGLLayer *layer = nil;
 169 
 170 JNF_COCOA_ENTER(env);
 171 
 172     JNFJObjectWrapper *javaLayer = [JNFJObjectWrapper wrapperWithJObject:obj withEnv:env];
 173 
 174     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
 175             AWT_ASSERT_APPKIT_THREAD;
 176         
 177             layer = [[CGLLayer alloc] initWithJavaLayer: javaLayer];
 178     }];
 179     
 180 JNF_COCOA_EXIT(env);
 181 
 182     return ptr_to_jlong(layer);
 183 }
 184 
 185 // Must be called under the RQ lock.
 186 JNIEXPORT void JNICALL
 187 Java_sun_java2d_opengl_CGLLayer_validate
 188 (JNIEnv *env, jclass cls, jlong layerPtr, jobject surfaceData)
 189 {
 190     CGLLayer *layer = OBJC(layerPtr);
 191 
 192     if (surfaceData != NULL) {
 193         OGLSDOps *oglsdo = (OGLSDOps*) SurfaceData_GetOps(env, surfaceData);
 194         layer.textureID = oglsdo->textureID;
 195         layer.target = GL_TEXTURE_2D;
 196         layer.textureWidth = oglsdo->width;
 197         layer.textureHeight = oglsdo->height;
 198     } else {
 199         layer.textureID = 0;
 200     }
 201 }
 202 
 203 // Must be called on the AppKit thread and under the RQ lock.
 204 JNIEXPORT void JNICALL
 205 Java_sun_java2d_opengl_CGLLayer_blitTexture
 206 (JNIEnv *env, jclass cls, jlong layerPtr)
 207 {
 208     CGLLayer *layer = jlong_to_ptr(layerPtr);
 209 
 210     [layer blitTexture];
 211 }
 212 
 213 JNIEXPORT void JNICALL
 214 Java_sun_java2d_opengl_CGLLayer_nativeSetScale
 215 (JNIEnv *env, jclass cls, jlong layerPtr, jdouble scale)
 216 {
 217     JNF_COCOA_ENTER(env);
 218     CGLLayer *layer = jlong_to_ptr(layerPtr);
 219     [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
 220         layer.contentsScale = scale;
 221     }];
 222     JNF_COCOA_EXIT(env);
 223 }