8201240: Improve releasing native resources of BufImgSurfaceData.ICMColorData

Reviewed-by: prr, serb
This commit is contained in:
Alexey Ivanov 2018-04-12 14:03:54 +01:00
parent 0a0fd44713
commit d4040a6d58
2 changed files with 13 additions and 29 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,6 @@
package sun.awt.image;
import java.awt.Color;
import java.awt.Rectangle;
import java.awt.GraphicsConfiguration;
import java.awt.image.ColorModel;
@ -38,9 +37,6 @@ import java.awt.image.DataBuffer;
import sun.java2d.SurfaceData;
import sun.java2d.SunGraphics2D;
import sun.java2d.StateTrackable;
import sun.java2d.StateTrackable.*;
import sun.java2d.StateTracker;
import sun.java2d.loops.SurfaceType;
import sun.java2d.loops.CompositeType;
import sun.java2d.loops.RenderLoops;
@ -446,8 +442,6 @@ public class BufImgSurfaceData extends SurfaceData {
// their pixels are immediately retrievable anyway.
}
private static native void freeNativeICMData(long pData);
/**
* Returns destination Image associated with this SurfaceData.
*/
@ -471,13 +465,5 @@ public class BufImgSurfaceData extends SurfaceData {
private ICMColorData(long pData) {
this.pData = pData;
}
@SuppressWarnings("deprecation")
public void finalize() {
if (pData != 0L) {
BufImgSurfaceData.freeNativeICMData(pData);
pData = 0L;
}
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -32,6 +32,7 @@
#include "jni_util.h"
/* Define uintptr_t */
#include "gdefs.h"
#include "Disposer.h"
/**
* This include file contains support code for loops using the
@ -79,19 +80,6 @@ Java_sun_awt_image_BufImgSurfaceData_initIDs
"Lsun/awt/image/BufImgSurfaceData$ICMColorData;"));
}
/*
* Class: sun_java2d_SurfaceData
* Method: freeNativeICMData
* Signature: (Ljava/awt/image/IndexColorModel;)V
*/
JNIEXPORT void JNICALL
Java_sun_awt_image_BufImgSurfaceData_freeNativeICMData
(JNIEnv *env, jclass sd, jlong pData)
{
ColorData *cdata = (ColorData*)jlong_to_ptr(pData);
freeICMColorData(cdata);
}
/*
* Class: sun_awt_image_BufImgSurfaceData
* Method: initOps
@ -139,6 +127,15 @@ Java_sun_awt_image_BufImgSurfaceData_initRaster(JNIEnv *env, jobject bisd,
bisdo->rasbounds.y2 = height;
}
/*
* Releases native structures associated with BufImgSurfaceData.ICMColorData.
*/
static void BufImg_Dispose_ICMColorData(JNIEnv *env, jlong pData)
{
ColorData *cdata = (ColorData*)jlong_to_ptr(pData);
freeICMColorData(cdata);
}
/*
* Method for disposing native BufImgSD
*/
@ -373,6 +370,7 @@ static ColorData *BufImg_SetupICM(JNIEnv *env,
}
(*env)->SetObjectField(env, bisdo->icm, colorDataID, colorData);
Disposer_AddRecord(env, colorData, BufImg_Dispose_ICMColorData, pData);
}
}