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

Print this page




  40 @synthesize target;
  41 @synthesize textureWidth;
  42 @synthesize textureHeight;
  43 #ifdef REMOTELAYER
  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.autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable;
  61     self.contentsGravity = kCAGravityTopLeft;
  62     self.needsDisplayOnBoundsChange = YES;


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


  90 
  91     glEnable(target);
  92     glBindTexture(target, textureID);
  93 
  94     glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); // srccopy
  95 
  96     float swid = 1.0f, shgt = 1.0f;
  97     if (target == GL_TEXTURE_RECTANGLE_ARB) {
  98         swid = textureWidth;
  99         shgt = textureHeight;
 100     }
 101     glBegin(GL_QUADS);
 102     glTexCoord2f(0.0f, 0.0f); glVertex2f(-1.0f, -1.0f);
 103     glTexCoord2f(swid, 0.0f); glVertex2f( 1.0f, -1.0f);
 104     glTexCoord2f(swid, shgt); glVertex2f( 1.0f,  1.0f);
 105     glTexCoord2f(0.0f, shgt); glVertex2f(-1.0f,  1.0f);
 106     glEnd();
 107 
 108     glBindTexture(target, 0);
 109     glDisable(target);




 110 }
 111 
 112 -(void)drawInCGLContext:(CGLContextObj)glContext pixelFormat:(CGLPixelFormatObj)pixelFormat forLayerTime:(CFTimeInterval)timeInterval displayTime:(const CVTimeStamp *)timeStamp
 113 {
 114     AWT_ASSERT_APPKIT_THREAD;
 115 
 116     // Set the current context to the one given to us.
 117     CGLSetCurrentContext(glContext);
 118 
 119     glViewport(0, 0, textureWidth, textureHeight);
 120 
 121     JNIEnv *env = [ThreadUtilities getJNIEnv];
 122     static JNF_CLASS_CACHE(jc_JavaLayer, "sun/java2d/opengl/CGLLayer");
 123     static JNF_MEMBER_CACHE(jm_drawInCGLContext, jc_JavaLayer, "drawInCGLContext", "()V");
 124 
 125     jobject javaLayerLocalRef = [self.javaLayer jObjectWithEnv:env];
 126     JNFCallVoidMethod(env, javaLayerLocalRef, jm_drawInCGLContext);
 127     (*env)->DeleteLocalRef(env, javaLayerLocalRef);
 128 
 129     // Call super to finalize the drawing. By default all it does is call glFlush().




  40 @synthesize target;
  41 @synthesize textureWidth;
  42 @synthesize textureHeight;
  43 #ifdef REMOTELAYER
  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 }


  91 
  92     glEnable(target);
  93     glBindTexture(target, textureID);
  94 
  95     glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); // srccopy
  96 
  97     float swid = 1.0f, shgt = 1.0f;
  98     if (target == GL_TEXTURE_RECTANGLE_ARB) {
  99         swid = textureWidth;
 100         shgt = textureHeight;
 101     }
 102     glBegin(GL_QUADS);
 103     glTexCoord2f(0.0f, 0.0f); glVertex2f(-1.0f, -1.0f);
 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().