Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Aparapi Examples
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
We are moving to Forgejo!
You are on a read-only GitLab instance.
Show more breadcrumbs
Aparapi
Aparapi Examples
Commits
c6983da1
Commit
c6983da1
authored
12 years ago
by
Gary Frost
Browse files
Options
Downloads
Patches
Plain Diff
No commit message
No commit message
parent
41c7fb40
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/javaonedemo/src/com/amd/aparapi/examples/javaonedemo/Mandel.java
+69
-9
69 additions, 9 deletions
...demo/src/com/amd/aparapi/examples/javaonedemo/Mandel.java
with
69 additions
and
9 deletions
examples/javaonedemo/src/com/amd/aparapi/examples/javaonedemo/Mandel.java
+
69
−
9
View file @
c6983da1
...
@@ -38,10 +38,17 @@ under those regulations, please refer to the U.S. Bureau of Industry and Securit
...
@@ -38,10 +38,17 @@ under those regulations, please refer to the U.S. Bureau of Industry and Securit
package
com.amd.aparapi.examples.javaonedemo
;
package
com.amd.aparapi.examples.javaonedemo
;
import
java.awt.BorderLayout
;
import
java.awt.Color
;
import
java.awt.Color
;
import
java.awt.Dimension
;
import
java.awt.Dimension
;
import
java.awt.FlowLayout
;
import
java.awt.Font
;
import
java.awt.Graphics
;
import
java.awt.Graphics
;
import
java.awt.Point
;
import
java.awt.Point
;
import
java.awt.event.ActionEvent
;
import
java.awt.event.ActionListener
;
import
java.awt.event.ItemEvent
;
import
java.awt.event.ItemListener
;
import
java.awt.event.MouseAdapter
;
import
java.awt.event.MouseAdapter
;
import
java.awt.event.MouseEvent
;
import
java.awt.event.MouseEvent
;
import
java.awt.event.WindowAdapter
;
import
java.awt.event.WindowAdapter
;
...
@@ -50,8 +57,11 @@ import java.awt.image.BufferedImage;
...
@@ -50,8 +57,11 @@ import java.awt.image.BufferedImage;
import
java.awt.image.DataBufferInt
;
import
java.awt.image.DataBufferInt
;
import
java.util.List
;
import
java.util.List
;
import
javax.swing.JButton
;
import
javax.swing.JComboBox
;
import
javax.swing.JComponent
;
import
javax.swing.JComponent
;
import
javax.swing.JFrame
;
import
javax.swing.JFrame
;
import
javax.swing.JPanel
;
import
com.amd.aparapi.Kernel
;
import
com.amd.aparapi.Kernel
;
import
com.amd.aparapi.ProfileInfo
;
import
com.amd.aparapi.ProfileInfo
;
...
@@ -162,6 +172,10 @@ public class Mandel{
...
@@ -162,6 +172,10 @@ public class Mandel{
/** User selected zoom-in point on the Mandelbrot view. */
/** User selected zoom-in point on the Mandelbrot view. */
public
static
volatile
Point
to
=
null
;
public
static
volatile
Point
to
=
null
;
public
static
int
frames
=
0
;
public
static
long
start
=
0
;
@SuppressWarnings
(
"serial"
)
public
static
void
main
(
String
[]
_args
)
{
@SuppressWarnings
(
"serial"
)
public
static
void
main
(
String
[]
_args
)
{
JFrame
frame
=
new
JFrame
(
"MandelBrot"
);
JFrame
frame
=
new
JFrame
(
"MandelBrot"
);
...
@@ -178,14 +192,66 @@ public class Mandel{
...
@@ -178,14 +192,66 @@ public class Mandel{
/** Image for Mandelbrot view. */
/** Image for Mandelbrot view. */
final
BufferedImage
image
=
new
BufferedImage
(
width
,
height
,
BufferedImage
.
TYPE_INT_RGB
);
final
BufferedImage
image
=
new
BufferedImage
(
width
,
height
,
BufferedImage
.
TYPE_INT_RGB
);
final
BufferedImage
offscreen
=
new
BufferedImage
(
width
,
height
,
BufferedImage
.
TYPE_INT_RGB
);
final
BufferedImage
offscreen
=
new
BufferedImage
(
width
,
height
,
BufferedImage
.
TYPE_INT_RGB
);
// Extract the underlying RGB buffer from the image.
// Pass this to the kernel so it operates directly on the RGB buffer of the image
final
int
[]
rgb
=
((
DataBufferInt
)
offscreen
.
getRaster
().
getDataBuffer
()).
getData
();
final
int
[]
imageRgb
=
((
DataBufferInt
)
image
.
getRaster
().
getDataBuffer
()).
getData
();
// Create a Kernel passing the size, RGB buffer and the palette.
final
MandelKernel
kernel
=
new
MandelKernel
(
width
,
height
,
rgb
);
kernel
.
setExecutionMode
(
Kernel
.
EXECUTION_MODE
.
JTP
);
final
Font
font
=
new
Font
(
"Garamond"
,
Font
.
BOLD
,
100
);
// Draw Mandelbrot image
// Draw Mandelbrot image
JComponent
viewer
=
new
JComponent
(){
JComponent
viewer
=
new
JComponent
(){
@Override
public
void
paintComponent
(
Graphics
g
)
{
@Override
public
void
paintComponent
(
Graphics
g
)
{
g
.
drawImage
(
image
,
0
,
0
,
width
,
height
,
this
);
g
.
drawImage
(
image
,
0
,
0
,
width
,
height
,
this
);
g
.
setFont
(
font
);
long
now
=
System
.
currentTimeMillis
();
// if (now - start > 1000) {
double
framesPerSecond
=
(
frames
*
1000.0
)
/
(
now
-
start
);
g
.
drawString
(
String
.
format
(
"%5.2f"
,
framesPerSecond
),
20
,
100
);
// generationsPerSecond.setText(String.format("%5.2f", generationsPerSecondField));
frames
++;
// }
}
}
};
};
JPanel
controlPanel
=
new
JPanel
(
new
FlowLayout
());
frame
.
getContentPane
().
add
(
controlPanel
,
BorderLayout
.
SOUTH
);
final
String
[]
choices
=
new
String
[]
{
// "Java Sequential",
"Java Threads"
,
"GPU OpenCL"
};
final
JComboBox
modeButton
=
new
JComboBox
(
choices
);
modeButton
.
addItemListener
(
new
ItemListener
(){
@Override
public
void
itemStateChanged
(
ItemEvent
e
)
{
String
item
=
(
String
)
modeButton
.
getSelectedItem
();
// if (item.equals(choices[2])) {
// modeButton = gpuMandelBrot;
// } else
if
(
item
.
equals
(
choices
[
0
]))
{
kernel
.
setExecutionMode
(
Kernel
.
EXECUTION_MODE
.
JTP
);
frames
=
0
;
start
=
System
.
currentTimeMillis
();
// modeButton = javaMandelBrot;
}
else
if
(
item
.
equals
(
choices
[
1
]))
{
kernel
.
setExecutionMode
(
Kernel
.
EXECUTION_MODE
.
GPU
);
frames
=
0
;
start
=
System
.
currentTimeMillis
();
// modeButton = javaMandelBrotMultiThread;
}
}
});
controlPanel
.
add
(
modeButton
);
// Set the size of JComponent which displays Mandelbrot image
// Set the size of JComponent which displays Mandelbrot image
viewer
.
setPreferredSize
(
new
Dimension
(
width
,
height
));
viewer
.
setPreferredSize
(
new
Dimension
(
width
,
height
));
...
@@ -202,18 +268,11 @@ public class Mandel{
...
@@ -202,18 +268,11 @@ public class Mandel{
});
});
// Swing housework to create the frame
// Swing housework to create the frame
frame
.
getContentPane
().
add
(
viewer
);
frame
.
getContentPane
().
add
(
viewer
,
BorderLayout
.
CENTER
);
frame
.
pack
();
frame
.
pack
();
frame
.
setLocationRelativeTo
(
null
);
frame
.
setLocationRelativeTo
(
null
);
frame
.
setVisible
(
true
);
frame
.
setVisible
(
true
);
// Extract the underlying RGB buffer from the image.
// Pass this to the kernel so it operates directly on the RGB buffer of the image
final
int
[]
rgb
=
((
DataBufferInt
)
offscreen
.
getRaster
().
getDataBuffer
()).
getData
();
final
int
[]
imageRgb
=
((
DataBufferInt
)
image
.
getRaster
().
getDataBuffer
()).
getData
();
// Create a Kernel passing the size, RGB buffer and the palette.
final
MandelKernel
kernel
=
new
MandelKernel
(
width
,
height
,
rgb
);
float
defaultScale
=
3
f
;
float
defaultScale
=
3
f
;
// Set the default scale and offset, execute the kernel and force a repaint of the viewer.
// Set the default scale and offset, execute the kernel and force a repaint of the viewer.
...
@@ -247,7 +306,8 @@ public class Mandel{
...
@@ -247,7 +306,8 @@ public class Mandel{
}
}
}
}
}
}
frames
=
0
;
start
=
System
.
currentTimeMillis
();
float
x
=
-
1
f
;
float
x
=
-
1
f
;
float
y
=
0
f
;
float
y
=
0
f
;
float
scale
=
defaultScale
;
float
scale
=
defaultScale
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment