src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLLayer.m
author serb
Tue, 27 Aug 2019 04:43:01 -0700
changeset 58315 07556f8cd819
parent 54873 442e683e65fa
permissions -rw-r--r--
8146238: [macosx] Java2D Queue Flusher crash on OSX after switching between user accounts Reviewed-by: prr, avu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     1
/*
54873
442e683e65fa 7141393: [macosx] CARemoteLayer code refactoring and unit test
serb
parents: 47216
diff changeset
     2
 * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     4
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    10
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    15
 * accompanied this code).
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    16
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    20
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    23
 * questions.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    24
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    25
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    26
#import "CGLGraphicsConfig.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    27
#import "CGLLayer.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    28
#import "ThreadUtilities.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    29
#import "LWCToolkit.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    30
#import "CGLSurfaceData.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    31
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    32
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    33
extern NSOpenGLPixelFormat *sharedPixelFormat;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    34
extern NSOpenGLContext *sharedContext;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    35
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    36
@implementation CGLLayer
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    37
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    38
@synthesize javaLayer;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    39
@synthesize textureID;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    40
@synthesize target;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    41
@synthesize textureWidth;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    42
@synthesize textureHeight;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    43
37787
de878aeb7ed2 8145984: [macosx] sun.lwawt.macosx.CAccessible leaks
ant
parents: 26751
diff changeset
    44
- (id) initWithJavaLayer:(JNFWeakJObjectWrapper *)layer;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    45
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    46
AWT_ASSERT_APPKIT_THREAD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    47
    // Initialize ourselves
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    48
    self = [super init];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    49
    if (self == nil) return self;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    50
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    51
    self.javaLayer = layer;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    52
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    53
    // NOTE: async=YES means that the layer is re-cached periodically
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    54
    self.asynchronous = FALSE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    55
    self.contentsGravity = kCAGravityTopLeft;
14306
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 12047
diff changeset
    56
    //Layer backed view
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 12047
diff changeset
    57
    //self.needsDisplayOnBoundsChange = YES;
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 12047
diff changeset
    58
    //self.autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable;
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 14753
diff changeset
    59
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 14753
diff changeset
    60
    //Disable CALayer's default animation
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 14753
diff changeset
    61
    NSMutableDictionary * actions = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
17411
6a6136a94ebb 8013841: [macosx] Animations not disabled for CALayers used via JAWT
serb
parents: 17151
diff changeset
    62
                                    [NSNull null], @"anchorPoint",
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 14753
diff changeset
    63
                                    [NSNull null], @"bounds",
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 14753
diff changeset
    64
                                    [NSNull null], @"contents",
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 14753
diff changeset
    65
                                    [NSNull null], @"contentsScale",
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 14753
diff changeset
    66
                                    [NSNull null], @"onOrderIn",
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 14753
diff changeset
    67
                                    [NSNull null], @"onOrderOut",
17411
6a6136a94ebb 8013841: [macosx] Animations not disabled for CALayers used via JAWT
serb
parents: 17151
diff changeset
    68
                                    [NSNull null], @"position",
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 14753
diff changeset
    69
                                    [NSNull null], @"sublayers",
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 14753
diff changeset
    70
                                    nil];
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 14753
diff changeset
    71
    self.actions = actions;
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 14753
diff changeset
    72
    [actions release];
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 14753
diff changeset
    73
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    74
    textureID = 0; // texture will be created by rendering pipe
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    75
    target = 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    76
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    77
    return self;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    78
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    79
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    80
- (void) dealloc {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    81
    self.javaLayer = nil;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    82
    [super dealloc];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    83
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    84
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    85
- (CGLPixelFormatObj)copyCGLPixelFormatForDisplayMask:(uint32_t)mask {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    86
    return CGLRetainPixelFormat(sharedPixelFormat.CGLPixelFormatObj);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    87
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    88
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    89
- (CGLContextObj)copyCGLContextForPixelFormat:(CGLPixelFormatObj)pixelFormat {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    90
    CGLContextObj contextObj = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    91
    CGLCreateContext(pixelFormat, sharedContext.CGLContextObj, &contextObj);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    92
    return contextObj;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    93
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    94
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    95
// use texture (intermediate buffer) as src and blit it to the layer
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    96
- (void) blitTexture
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    97
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    98
    if (textureID == 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    99
        return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   100
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   101
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   102
    glEnable(target);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   103
    glBindTexture(target, textureID);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   104
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   105
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); // srccopy
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   106
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   107
    float swid = 1.0f, shgt = 1.0f;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   108
    if (target == GL_TEXTURE_RECTANGLE_ARB) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   109
        swid = textureWidth;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   110
        shgt = textureHeight;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   111
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   112
    glBegin(GL_QUADS);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   113
    glTexCoord2f(0.0f, 0.0f); glVertex2f(-1.0f, -1.0f);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   114
    glTexCoord2f(swid, 0.0f); glVertex2f( 1.0f, -1.0f);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   115
    glTexCoord2f(swid, shgt); glVertex2f( 1.0f,  1.0f);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   116
    glTexCoord2f(0.0f, shgt); glVertex2f(-1.0f,  1.0f);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   117
    glEnd();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   118
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   119
    glBindTexture(target, 0);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   120
    glDisable(target);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   121
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   122
14306
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 12047
diff changeset
   123
-(BOOL)canDrawInCGLContext:(CGLContextObj)glContext pixelFormat:(CGLPixelFormatObj)pixelFormat forLayerTime:(CFTimeInterval)timeInterval displayTime:(const CVTimeStamp *)timeStamp{
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 12047
diff changeset
   124
    return textureID == 0 ? NO : YES;
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 12047
diff changeset
   125
}
8d823e84507a 7198229: Painting during resizing of the frame should be more smooth
serb
parents: 12047
diff changeset
   126
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   127
-(void)drawInCGLContext:(CGLContextObj)glContext pixelFormat:(CGLPixelFormatObj)pixelFormat forLayerTime:(CFTimeInterval)timeInterval displayTime:(const CVTimeStamp *)timeStamp
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   128
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   129
    AWT_ASSERT_APPKIT_THREAD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   130
37787
de878aeb7ed2 8145984: [macosx] sun.lwawt.macosx.CAccessible leaks
ant
parents: 26751
diff changeset
   131
    JNIEnv *env = [ThreadUtilities getJNIEnv];
de878aeb7ed2 8145984: [macosx] sun.lwawt.macosx.CAccessible leaks
ant
parents: 26751
diff changeset
   132
    static JNF_CLASS_CACHE(jc_JavaLayer, "sun/java2d/opengl/CGLLayer");
de878aeb7ed2 8145984: [macosx] sun.lwawt.macosx.CAccessible leaks
ant
parents: 26751
diff changeset
   133
    static JNF_MEMBER_CACHE(jm_drawInCGLContext, jc_JavaLayer, "drawInCGLContext", "()V");
de878aeb7ed2 8145984: [macosx] sun.lwawt.macosx.CAccessible leaks
ant
parents: 26751
diff changeset
   134
de878aeb7ed2 8145984: [macosx] sun.lwawt.macosx.CAccessible leaks
ant
parents: 26751
diff changeset
   135
    jobject javaLayerLocalRef = [self.javaLayer jObjectWithEnv:env];
de878aeb7ed2 8145984: [macosx] sun.lwawt.macosx.CAccessible leaks
ant
parents: 26751
diff changeset
   136
    if ((*env)->IsSameObject(env, javaLayerLocalRef, NULL)) {
de878aeb7ed2 8145984: [macosx] sun.lwawt.macosx.CAccessible leaks
ant
parents: 26751
diff changeset
   137
        return;
de878aeb7ed2 8145984: [macosx] sun.lwawt.macosx.CAccessible leaks
ant
parents: 26751
diff changeset
   138
    }
de878aeb7ed2 8145984: [macosx] sun.lwawt.macosx.CAccessible leaks
ant
parents: 26751
diff changeset
   139
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   140
    // Set the current context to the one given to us.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   141
    CGLSetCurrentContext(glContext);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   142
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 14753
diff changeset
   143
    // Should clear the whole CALayer, because it can be larger than our texture.
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 14753
diff changeset
   144
    glClearColor(0.0, 0.0, 0.0, 0.0);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 14753
diff changeset
   145
    glClear(GL_COLOR_BUFFER_BIT);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 14753
diff changeset
   146
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   147
    glViewport(0, 0, textureWidth, textureHeight);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   148
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   149
    JNFCallVoidMethod(env, javaLayerLocalRef, jm_drawInCGLContext);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   150
    (*env)->DeleteLocalRef(env, javaLayerLocalRef);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   151
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   152
    // Call super to finalize the drawing. By default all it does is call glFlush().
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   153
    [super drawInCGLContext:glContext pixelFormat:pixelFormat forLayerTime:timeInterval displayTime:timeStamp];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   154
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   155
    CGLSetCurrentContext(NULL);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   156
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   157
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   158
@end
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   159
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   160
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   161
 * Class:     sun_java2d_opengl_CGLLayer
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   162
 * Method:    nativeCreateLayer
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   163
 * Signature: ()J
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   164
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   165
JNIEXPORT jlong JNICALL
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   166
Java_sun_java2d_opengl_CGLLayer_nativeCreateLayer
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   167
(JNIEnv *env, jobject obj)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   168
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   169
    __block CGLLayer *layer = nil;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   170
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   171
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   172
37787
de878aeb7ed2 8145984: [macosx] sun.lwawt.macosx.CAccessible leaks
ant
parents: 26751
diff changeset
   173
    JNFWeakJObjectWrapper *javaLayer = [JNFWeakJObjectWrapper wrapperWithJObject:obj withEnv:env];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   174
14753
a56a685d137f 7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents: 14306
diff changeset
   175
    [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
a56a685d137f 7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents: 14306
diff changeset
   176
            AWT_ASSERT_APPKIT_THREAD;
54873
442e683e65fa 7141393: [macosx] CARemoteLayer code refactoring and unit test
serb
parents: 47216
diff changeset
   177
14753
a56a685d137f 7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents: 14306
diff changeset
   178
            layer = [[CGLLayer alloc] initWithJavaLayer: javaLayer];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   179
    }];
54873
442e683e65fa 7141393: [macosx] CARemoteLayer code refactoring and unit test
serb
parents: 47216
diff changeset
   180
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   181
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   182
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   183
    return ptr_to_jlong(layer);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   184
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   185
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   186
// Must be called under the RQ lock.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   187
JNIEXPORT void JNICALL
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   188
Java_sun_java2d_opengl_CGLLayer_validate
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 14753
diff changeset
   189
(JNIEnv *env, jclass cls, jlong layerPtr, jobject surfaceData)
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   190
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   191
    CGLLayer *layer = OBJC(layerPtr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   192
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   193
    if (surfaceData != NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   194
        OGLSDOps *oglsdo = (OGLSDOps*) SurfaceData_GetOps(env, surfaceData);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   195
        layer.textureID = oglsdo->textureID;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   196
        layer.target = GL_TEXTURE_2D;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   197
        layer.textureWidth = oglsdo->width;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   198
        layer.textureHeight = oglsdo->height;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   199
    } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   200
        layer.textureID = 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   201
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   202
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   203
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   204
// Must be called on the AppKit thread and under the RQ lock.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   205
JNIEXPORT void JNICALL
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   206
Java_sun_java2d_opengl_CGLLayer_blitTexture
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 14753
diff changeset
   207
(JNIEnv *env, jclass cls, jlong layerPtr)
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   208
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   209
    CGLLayer *layer = jlong_to_ptr(layerPtr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   210
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   211
    [layer blitTexture];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   212
}
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 14753
diff changeset
   213
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 14753
diff changeset
   214
JNIEXPORT void JNICALL
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 14753
diff changeset
   215
Java_sun_java2d_opengl_CGLLayer_nativeSetScale
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 14753
diff changeset
   216
(JNIEnv *env, jclass cls, jlong layerPtr, jdouble scale)
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 14753
diff changeset
   217
{
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 14753
diff changeset
   218
    JNF_COCOA_ENTER(env);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 14753
diff changeset
   219
    CGLLayer *layer = jlong_to_ptr(layerPtr);
54873
442e683e65fa 7141393: [macosx] CARemoteLayer code refactoring and unit test
serb
parents: 47216
diff changeset
   220
    // We always call all setXX methods asynchronously, exception is only in
17151
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
   221
    // this method where we need to change native texture size and layer's scale
54873
442e683e65fa 7141393: [macosx] CARemoteLayer code refactoring and unit test
serb
parents: 47216
diff changeset
   222
    // in one call on appkit, otherwise we'll get window's contents blinking,
17151
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
   223
    // during screen-2-screen moving.
9bfcf2a592fc 8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents: 16840
diff changeset
   224
    [ThreadUtilities performOnMainThreadWaiting:[NSThread isMainThread] block:^(){
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 14753
diff changeset
   225
        layer.contentsScale = scale;
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 14753
diff changeset
   226
    }];
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 14753
diff changeset
   227
    JNF_COCOA_EXIT(env);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 14753
diff changeset
   228
}