• R/O
  • HTTP
  • SSH
  • HTTPS

ruby-gtk3: Commit

Ruby GTK3移行後のメインリポジトリ


Commit MetaInfo

Revisionca1404a16b75bca1cd09fcfe2c747816aed46e85 (tree)
Time2019-01-06 14:34:24
AuthorShyouzou Sugitani <shy@user...>
CommiterShyouzou Sugitani

Log Message

reduce the drawing load(3)

Change Summary

Incremental Difference

--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
1+Sun January 6 2019 Shyouzou Sugitani <shy@users.osdn.me>
2+ * ウインドウ形状算出処理の負荷対策を実装した.
3+
14 Fri January 4 2019 Shyouzou Sugitani <shy@users.osdn.me>
25 * バージョン5.0.8リリース.
36 * Ruby移植時のミスなどを修正した.
--- a/lib/ninix/pix.rb
+++ b/lib/ninix/pix.rb
@@ -23,14 +23,12 @@ module Pix
2323 width = surface.width
2424 pix_na = NArray.to_na(surface.data, NArray::BYTE)
2525 pix_na.reshape!(4, pix_na.size / 4)
26- alpha = pix_na[3, true]
27- curr_y = -1
28- start_x = -1
29- end_x = -1
30- alpha.where.each {|i|
31- y = (i / width)
32- x = (i % width)
33- if start_x != -1
26+ curr_y = nil
27+ start_x = nil
28+ end_x = nil
29+ pix_na[3, true].where.each {|i|
30+ y, x = i.divmod(width)
31+ unless start_x.nil?
3432 if y != curr_y or x != (end_x + 1)
3533 region.union!(start_x, curr_y, end_x - start_x + 1, 1)
3634 curr_y = y
@@ -42,7 +40,44 @@ module Pix
4240 end
4341 end_x = x
4442 }
45- region.union!(start_x, curr_y, end_x - start_x + 1, 1) unless start_x == -1
43+ region.union!(start_x, curr_y, end_x - start_x + 1, 1) unless start_x.nil?
44+ return region
45+ end
46+
47+ def self.surface_to_region_with_hints(surface, device_extents)
48+ device_x1, device_y1, device_x2, device_y2 = device_extents
49+ region = Cairo::Region.new()
50+ width = surface.width
51+ height = surface.height
52+ stride = surface.stride
53+ device_x1 =[0, [device_x1, width - 1].min].max
54+ device_x2 =[0, [device_x2, width - 1].min].max
55+ device_y1 =[0, [device_y1, height - 1].min].max
56+ device_y2 =[0, [device_y2, height - 1].min].max
57+ device_w = device_x2 - device_x1 + 1
58+ device_h = device_y2 - device_y1 + 1
59+ pix_na = NArray.to_na(surface.data[device_y1 * stride, device_h * stride], NArray::BYTE)
60+ pix_na.reshape!(4, width, device_h)
61+ pix_na = pix_na.slice(3, device_x1..device_x2, true)
62+ curr_y = nil
63+ start_x = nil
64+ end_x = nil
65+ pix_na.where.each {|i|
66+ y, x = i.divmod(device_w)
67+ unless start_x.nil?
68+ if y != curr_y or x != (end_x + 1)
69+ region.union!(start_x, curr_y, end_x - start_x + 1, 1)
70+ curr_y = y
71+ start_x = x
72+ end
73+ else
74+ curr_y = y
75+ start_x = x
76+ end
77+ end_x = x
78+ }
79+ region.union!(start_x, curr_y, end_x - start_x + 1, 1) unless start_x.nil?
80+ region.translate!(device_x1, device_y1)
4681 return region
4782 end
4883
@@ -97,6 +132,7 @@ module Pix
97132 @darea.show()
98133 add(@darea)
99134 @region = nil
135+ @device_extents = nil
100136 end
101137
102138 def move(x, y)
@@ -128,6 +164,14 @@ module Pix
128164 cr.set_operator(Cairo::OPERATOR_SOURCE)
129165 # copy rectangle on the destination
130166 cr.rectangle(0, 0, surface.width, surface.height)
167+ extents = cr.path_extents # cr.fill_extents
168+ device_x1, device_y1 = cr.user_to_device(
169+ extents[0],
170+ extents[1])
171+ device_x2, device_y2 = cr.user_to_device(
172+ extents[2],
173+ extents[3])
174+ @device_extents = [device_x1, device_y1, device_x2, device_y2].map {|f| f.to_i}
131175 cr.fill()
132176 cr.restore()
133177 end
@@ -135,7 +179,11 @@ module Pix
135179 def set_shape(cr, reshape)
136180 return if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
137181 if @region.nil? or reshape
138- @region = Pix.surface_to_region(cr.target.map_to_image)
182+ if @device_extents.nil?
183+ @region = Pix.surface_to_region(cr.target.map_to_image)
184+ else
185+ @region = Pix.surface_to_region_with_hints(cr.target.map_to_image, @device_extents)
186+ end
139187 else
140188 dx, dy = @__surface_position.zip(@prev_position).map {|new, prev| new - prev}
141189 @region.translate!(dx, dy)
Show on old repository browser