mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 23:39:07 +07:00
[Java] Basic performance improvement of the compilation chart during zooming
IDEA-356484 GitOrigin-RevId: ad130a0f227d89fd822be9fc64953a01b92bf0ad
This commit is contained in:
committed by
intellij-monorepo-bot
parent
027daf582d
commit
ff15063ad4
@@ -135,26 +135,39 @@ class CompilationChartsDiagramsComponent(private val vm: CompilationChartsViewMo
|
||||
|
||||
override fun paintComponent(g2d: Graphics) {
|
||||
if (g2d !is Graphics2D) return
|
||||
cached(g2d) {
|
||||
return@cached charts.model {
|
||||
progress {
|
||||
data(modules.data.getAndClean())
|
||||
filter = modules.filter
|
||||
}
|
||||
usage(usages[cpuMemory]!!) {
|
||||
data(stats[cpuMemory]!!.getAndClean(), when (cpuMemory) {
|
||||
MEMORY -> vm.statistics.maxMemory
|
||||
CPU -> 100
|
||||
})
|
||||
}
|
||||
}.draw(g2d, this) {
|
||||
val size = Dimension(width().toInt(), height().toInt())
|
||||
if (size != this@CompilationChartsDiagramsComponent.preferredSize) {
|
||||
this@CompilationChartsDiagramsComponent.preferredSize = size
|
||||
this@CompilationChartsDiagramsComponent.revalidate()
|
||||
}
|
||||
return@draw UIUtil.createImage(this@CompilationChartsDiagramsComponent, width().toInt(), height().toInt(), BufferedImage.TYPE_INT_ARGB)
|
||||
val updatedModel = charts.model {
|
||||
progress {
|
||||
data(modules.data.getAndClean())
|
||||
filter = modules.filter
|
||||
}
|
||||
usage(usages[cpuMemory]!!) {
|
||||
data(stats[cpuMemory]!!.getAndClean(), when (cpuMemory) {
|
||||
MEMORY -> vm.statistics.maxMemory
|
||||
CPU -> 100
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (zoom.shouldCacheImage()) {
|
||||
cached(g2d) {
|
||||
updatedModel.drawOnImage(g2d, this) {
|
||||
revalidateDimensions()
|
||||
return@drawOnImage UIUtil.createImage(this@CompilationChartsDiagramsComponent, width().toInt(), height().toInt(), BufferedImage.TYPE_INT_ARGB)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
updatedModel.draw(g2d) {
|
||||
g2d.setupRenderingHints()
|
||||
revalidateDimensions()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun Charts.revalidateDimensions() {
|
||||
val size = Dimension(width().toInt(), height().toInt())
|
||||
if (size != this@CompilationChartsDiagramsComponent.preferredSize) {
|
||||
this@CompilationChartsDiagramsComponent.preferredSize = size
|
||||
this@CompilationChartsDiagramsComponent.revalidate()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,6 +192,7 @@ class CompilationChartsDiagramsComponent(private val vm: CompilationChartsViewMo
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun addNotify() {
|
||||
super.addNotify()
|
||||
setFocus()
|
||||
|
||||
@@ -42,6 +42,8 @@ class Zoom {
|
||||
viewport.viewPosition = Point(correctedViewPositionX, viewport.viewPosition.y)
|
||||
}
|
||||
|
||||
internal fun shouldCacheImage() = System.currentTimeMillis() - lastCorrectionTime > ZOOM_CACHING_DELAY
|
||||
|
||||
private fun correctedViewPosition(newPosition: Double, x: Int, duration: Long): Int {
|
||||
val correctedX = Math.round(max(0.0, newPosition)).toInt()
|
||||
val index = listOf(abs(duration - toDuration(correctedX + x)),
|
||||
|
||||
@@ -49,18 +49,24 @@ class Charts(private val vm: CompilationChartsViewModel, private val zoom: Zoom,
|
||||
axis = ChartAxis(zoom).apply(init)
|
||||
}
|
||||
|
||||
fun draw(g2d: Graphics2D, component: ImageObserver, init: Charts.() -> BufferedImage): BufferedImage {
|
||||
return withImage(init(), g2d, component) { g ->
|
||||
val components = listOf(progress, usage, axis)
|
||||
components.forEach { it.background(g, settings) }
|
||||
components.forEach { it.component(g, settings) }
|
||||
}
|
||||
fun draw(g2d: Graphics2D, init: Charts.() -> Unit) {
|
||||
init()
|
||||
drawChartComponents(g2d)
|
||||
}
|
||||
|
||||
fun drawOnImage(g2d: Graphics2D, component: ImageObserver, init: Charts.() -> BufferedImage): BufferedImage {
|
||||
return withImage(init(), g2d, component) { g -> drawChartComponents(g) }
|
||||
}
|
||||
|
||||
private fun drawChartComponents(g: Graphics2D) {
|
||||
val components = listOf(progress, usage, axis)
|
||||
components.forEach { it.background(g, settings) }
|
||||
components.forEach { it.component(g, settings) }
|
||||
}
|
||||
|
||||
private fun withImage(image: BufferedImage, g2d: Graphics2D, component: ImageObserver, draw: (Graphics2D) -> Unit): BufferedImage {
|
||||
image.createGraphics().run {
|
||||
setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)
|
||||
setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY)
|
||||
setupRenderingHints()
|
||||
|
||||
draw(this)
|
||||
|
||||
|
||||
@@ -43,4 +43,6 @@ const val AXIS_TEXT_PADDING: Int = 2
|
||||
const val MIN_ZOOM_SECONDS = 0.2
|
||||
const val MAX_ZOOM_SECONDS = 1_000.0
|
||||
|
||||
const val MAX_WIDTH = 10_000.0
|
||||
const val MAX_WIDTH = 10_000.0
|
||||
|
||||
const val ZOOM_CACHING_DELAY = 50
|
||||
@@ -120,4 +120,9 @@ internal fun Path2D.Double.curveTo(neighbour: DoubleArray) {
|
||||
curveTo(cx0, cy0, cx1, cy1, x2, y2)
|
||||
}
|
||||
|
||||
internal fun Graphics2D.setupRenderingHints() {
|
||||
setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)
|
||||
setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY)
|
||||
}
|
||||
|
||||
private fun Double.orZero() = if (this.isNaN()) 0.0 else this
|
||||
Reference in New Issue
Block a user