Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
a91c078e
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a91c078e
编写于
6月 07, 2012
作者:
K
kizune
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7124247: [macosx] Implement GraphicsDevice.setDisplayMode()
Reviewed-by: anthony, swingler
上级
952a919f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
192 addition
and
2 deletion
+192
-2
src/macosx/classes/sun/awt/CGraphicsDevice.java
src/macosx/classes/sun/awt/CGraphicsDevice.java
+31
-1
src/macosx/native/sun/awt/CGraphicsDevice.m
src/macosx/native/sun/awt/CGraphicsDevice.m
+161
-1
未找到文件。
src/macosx/classes/sun/awt/CGraphicsDevice.java
浏览文件 @
a91c078e
/*
* Copyright (c) 201
1
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 201
2
, 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
...
...
@@ -29,6 +29,7 @@ import java.awt.GraphicsConfiguration;
import
java.awt.GraphicsDevice
;
import
java.awt.Window
;
import
java.awt.AWTPermission
;
import
java.awt.DisplayMode
;
import
sun.java2d.opengl.CGLGraphicsConfig
;
...
...
@@ -178,4 +179,33 @@ public class CGraphicsDevice extends GraphicsDevice {
peer
.
exitFullScreenMode
();
}
}
@Override
public
boolean
isDisplayChangeSupported
()
{
return
true
;
}
@Override
public
void
setDisplayMode
(
DisplayMode
dm
)
{
nativeSetDisplayMode
(
displayID
,
dm
.
getWidth
(),
dm
.
getHeight
(),
dm
.
getBitDepth
(),
dm
.
getRefreshRate
());
if
(
isFullScreenSupported
()
&&
getFullScreenWindow
()
!=
null
)
{
getFullScreenWindow
().
setSize
(
dm
.
getWidth
(),
dm
.
getHeight
());
}
}
@Override
public
DisplayMode
getDisplayMode
()
{
return
nativeGetDisplayMode
(
displayID
);
}
@Override
public
DisplayMode
[]
getDisplayModes
()
{
return
nativeGetDisplayModes
(
displayID
);
}
private
native
void
nativeSetDisplayMode
(
int
displayID
,
int
w
,
int
h
,
int
bpp
,
int
refrate
);
private
native
DisplayMode
nativeGetDisplayMode
(
int
displayID
);
private
native
DisplayMode
[]
nativeGetDisplayModes
(
int
displayID
);
}
src/macosx/native/sun/awt/CGraphicsDevice.m
浏览文件 @
a91c078e
/*
* Copyright (c) 201
1
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 201
2
, 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,6 +25,84 @@
#include "LWCToolkit.h"
/*
* Convert the mode string to the more convinient bits per pixel value
*/
static
int
getBPPFromModeString
(
CFStringRef
mode
)
{
if
((
CFStringCompare
(
mode
,
CFSTR
(
kIO30BitDirectPixels
),
kCFCompareCaseInsensitive
)
==
kCFCompareEqualTo
))
{
// This is a strange mode, where we using 10 bits per RGB component and pack it into 32 bits
// Java is not ready to work with this mode but we have to specify it as supported
return
30
;
}
else
if
(
CFStringCompare
(
mode
,
CFSTR
(
IO32BitDirectPixels
),
kCFCompareCaseInsensitive
)
==
kCFCompareEqualTo
)
{
return
32
;
}
else
if
(
CFStringCompare
(
mode
,
CFSTR
(
IO16BitDirectPixels
),
kCFCompareCaseInsensitive
)
==
kCFCompareEqualTo
)
{
return
16
;
}
else
if
(
CFStringCompare
(
mode
,
CFSTR
(
IO8BitIndexedPixels
),
kCFCompareCaseInsensitive
)
==
kCFCompareEqualTo
)
{
return
8
;
}
return
0
;
}
/*
* Find the best possible match in the list of display modes that we can switch to based on
* the provided parameters.
*/
static
CGDisplayModeRef
getBestModeForParameters
(
CFArrayRef
allModes
,
int
w
,
int
h
,
int
bpp
,
int
refrate
)
{
CGDisplayModeRef
bestGuess
=
NULL
;
CFIndex
numModes
=
CFArrayGetCount
(
allModes
),
n
;
int
thisBpp
=
0
;
for
(
n
=
0
;
n
<
numModes
;
n
++
)
{
CGDisplayModeRef
cRef
=
(
CGDisplayModeRef
)
CFArrayGetValueAtIndex
(
allModes
,
n
);
if
(
cRef
==
NULL
)
{
continue
;
}
CFStringRef
modeString
=
CGDisplayModeCopyPixelEncoding
(
cRef
);
thisBpp
=
getBPPFromModeString
(
modeString
);
CFRelease
(
modeString
);
if
(
thisBpp
!=
bpp
||
(
int
)
CGDisplayModeGetHeight
(
cRef
)
!=
h
||
(
int
)
CGDisplayModeGetWidth
(
cRef
)
!=
w
)
{
// One of the key parameters does not match
continue
;
}
// Refresh rate might be 0 in display mode and we ask for specific display rate
// but if we do not find exact match then 0 refresh rate might be just Ok
if
(
CGDisplayModeGetRefreshRate
(
cRef
)
==
refrate
)
{
// Exact match
return
cRef
;
}
if
(
CGDisplayModeGetRefreshRate
(
cRef
)
==
0
)
{
// Not exactly what was asked for, but may fit our needs if we don't find an exact match
bestGuess
=
cRef
;
}
}
return
bestGuess
;
}
/*
* Create a new java.awt.DisplayMode instance based on provided CGDisplayModeRef
*/
static
jobject
createJavaDisplayMode
(
CGDisplayModeRef
mode
,
JNIEnv
*
env
,
jint
displayID
)
{
jobject
ret
=
NULL
;
jint
h
,
w
,
bpp
,
refrate
;
JNF_COCOA_ENTER
(
env
);
CFStringRef
currentBPP
=
CGDisplayModeCopyPixelEncoding
(
mode
);
bpp
=
getBPPFromModeString
(
currentBPP
);
refrate
=
CGDisplayModeGetRefreshRate
(
mode
);
h
=
CGDisplayPixelsHigh
(
displayID
);
w
=
CGDisplayPixelsWide
(
displayID
);
CFRelease
(
currentBPP
);
static
JNF_CLASS_CACHE
(
jc_DisplayMode
,
"java/awt/DisplayMode"
);
static
JNF_CTOR_CACHE
(
jc_DisplayMode_ctor
,
jc_DisplayMode
,
"(IIII)V"
);
ret
=
JNFNewObject
(
env
,
jc_DisplayMode_ctor
,
w
,
h
,
bpp
,
refrate
);
JNF_COCOA_EXIT
(
env
);
return
ret
;
}
/*
* Class: sun_awt_CGraphicsDevice
* Method: nativeGetXResolution
...
...
@@ -62,3 +140,85 @@ Java_sun_awt_CGraphicsDevice_nativeGetYResolution
jfloat
dpi
=
rect
.
size
.
height
/
inches
;
return
dpi
;
}
/*
* Class: sun_awt_CGraphicsDevice
* Method: nativeSetDisplayMode
* Signature: (IIIII)V
*/
JNIEXPORT
void
JNICALL
Java_sun_awt_CGraphicsDevice_nativeSetDisplayMode
(
JNIEnv
*
env
,
jclass
class
,
jint
displayID
,
jint
w
,
jint
h
,
jint
bpp
,
jint
refrate
)
{
JNF_COCOA_ENTER
(
env
);
CFArrayRef
allModes
=
CGDisplayCopyAllDisplayModes
(
displayID
,
NULL
);
CGDisplayModeRef
closestMatch
=
getBestModeForParameters
(
allModes
,
(
int
)
w
,
(
int
)
h
,
(
int
)
bpp
,
(
int
)
refrate
);
if
(
closestMatch
!=
NULL
)
{
CGDisplayConfigRef
config
;
CGError
retCode
=
CGBeginDisplayConfiguration
(
&
config
);
if
(
retCode
==
kCGErrorSuccess
)
{
CGConfigureDisplayWithDisplayMode
(
config
,
displayID
,
closestMatch
,
NULL
);
CGCompleteDisplayConfiguration
(
config
,
kCGConfigureForAppOnly
);
CFRelease
(
config
);
}
}
CFRelease
(
allModes
);
JNF_COCOA_EXIT
(
env
);
}
/*
* Class: sun_awt_CGraphicsDevice
* Method: nativeGetDisplayMode
* Signature: (I)Ljava/awt/DisplayMode
*/
JNIEXPORT
jobject
JNICALL
Java_sun_awt_CGraphicsDevice_nativeGetDisplayMode
(
JNIEnv
*
env
,
jclass
class
,
jint
displayID
)
{
jobject
ret
=
NULL
;
CGDisplayModeRef
currentMode
=
CGDisplayCopyDisplayMode
(
displayID
);
ret
=
createJavaDisplayMode
(
currentMode
,
env
,
displayID
);
CGDisplayModeRelease
(
currentMode
);
return
ret
;
}
/*
* Class: sun_awt_CGraphicsDevice
* Method: nativeGetDisplayMode
* Signature: (I)[Ljava/awt/DisplayModes
*/
JNIEXPORT
jobjectArray
JNICALL
Java_sun_awt_CGraphicsDevice_nativeGetDisplayModes
(
JNIEnv
*
env
,
jclass
class
,
jint
displayID
)
{
jobjectArray
jreturnArray
=
NULL
;
JNF_COCOA_ENTER
(
env
);
CFArrayRef
allModes
=
CGDisplayCopyAllDisplayModes
(
displayID
,
NULL
);
CFIndex
numModes
=
CFArrayGetCount
(
allModes
);
static
JNF_CLASS_CACHE
(
jc_DisplayMode
,
"java/awt/DisplayMode"
);
jreturnArray
=
JNFNewObjectArray
(
env
,
&
jc_DisplayMode
,
(
jsize
)
numModes
);
if
(
!
jreturnArray
)
{
NSLog
(
@"CGraphicsDevice can't create java array of DisplayMode objects"
);
return
nil
;
}
CFIndex
n
;
for
(
n
=
0
;
n
<
numModes
;
n
++
)
{
CGDisplayModeRef
cRef
=
(
CGDisplayModeRef
)
CFArrayGetValueAtIndex
(
allModes
,
n
);
if
(
cRef
!=
NULL
)
{
jobject
oneMode
=
createJavaDisplayMode
(
cRef
,
env
,
displayID
);
(
*
env
)
->
SetObjectArrayElement
(
env
,
jreturnArray
,
n
,
oneMode
);
if
((
*
env
)
->
ExceptionOccurred
(
env
))
{
(
*
env
)
->
ExceptionDescribe
(
env
);
(
*
env
)
->
ExceptionClear
(
env
);
continue
;
}
(
*
env
)
->
DeleteLocalRef
(
env
,
oneMode
);
}
}
CFRelease
(
allModes
);
JNF_COCOA_EXIT
(
env
);
return
jreturnArray
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录