This makes gears.color() cache patterns in a weak table and returns that cached
pattern when we get called with the same argument again.
To benchmark this change, the following code was used:
local time = require("socket").gettime
function benchmark(func)
local begin = time()
local iter = 0
while time() - begin < 1 do
func()
iter = iter + 1
end
return iter
end
for _, arg in pairs({
"#00aa00",
"solid:#00aa00",
"radial:50,50,10:55,55,30:0,#ff0000:0.5,#00ff00:1,#0000ff",
"linear:1,2:3,4:0,#000000:1,#ffffff",
"png:/home/psychon/Wallpaper/Bars.png",
{ type = "solid", color = "#00aa00" },
{ type = "radial", from = { 50, 50, 10 }, to = { 55, 55, 30 }, stops = { { 0, "#ff0000" }, { 0.5, "#00ff00" }, { 1, "#0000ff" } } },
{ type = "linear", from = { 1, 2 }, to = { 3, 4 }, stops = { { 0, "#000000" }, { 1, "#ffffff" } } },
{ type = "png", file = "/home/psychon/Wallpaper/Bars.png" },
}) do
collectgarbage("collect")
print(benchmark(function() gears.color.create_pattern(arg) end), arg)
end
Before this change (larger numbers are better, this measures how many times we
can create the given pattern per second):
29525 #00aa00
29344 solid:#00aa00
3446 radial:50,50,10:55,55,30:0,#ff0000:0.5,#00ff00:1,#0000ff
4845 linear:1,2:3,4:0,#000000:1,#ffffff
32855 png:/home/psychon/Wallpaper/Bars.png
29883 table: 0x1bb67e0
3868 table: 0x1bb6830
5339 table: 0x1bb6c60
32772 table: 0x1bb6fe0
After this change:
126188 #00aa00
125962 solid:#00aa00
125125 radial:50,50,10:55,55,30:0,#ff0000:0.5,#00ff00:1,#0000ff
125213 linear:1,2:3,4:0,#000000:1,#ffffff
113659 png:/home/psychon/Wallpaper/Bars.png
125586 table: 0x1232680
125249 table: 0x12326d0
125468 table: 0x1232b00
113711 table: 0x1232e80
As you see, this makes some cases about 35 times faster (although I have to
admit that something like this can be expected from such a synthetic benchmark).
Signed-off-by: Uli Schlachter <psychon@znc.in>
If a drawable has an opaque background, we don't need pseudo transparency and
thus its content don't change when it is moved. However, when we need pseudo
transparency, then we have to redraw the drawable to apply the new background.
Previously we just always did the redraw. This commit adds a helper function
gears.color.create_opaque_pattern() that analyzes a cairo pattern for
transparency. We use this new function to only redraw-on-move when there is
actual pseudo transparency in effect. Otherwise, this redraw can be skipped.
Signed-off-by: Uli Schlachter <psychon@znc.in>
This allows to use cairo patterns directly for any kind of "color". This makes
it easier to use things which aren't possible through gears.color.
Signed-off-by: Uli Schlachter <psychon@znc.in>
The corresponding pattern factory that `string_pattern` delegates to is stored
in the `creator` parameter, and not `v`; probably a typo.
Signed-off-by: Anurag Priyam <anurag08priyam@gmail.com>
Signed-off-by: Uli Schlachter <psychon@znc.in>
Replaced all references to image_surface_create_from_png to
awesome.load_image
Signed-off-by: Arvydas Sidorenko <asido4@gmail.com>
Signed-off-by: Uli Schlachter <psychon@znc.in>
Luadoc confuses '<stop>' with an HTML tag otherwise.
Signed-off-by: Anurag Priyam <anurag08priyam@gmail.com>
Signed-off-by: Uli Schlachter <psychon@znc.in>
In general, patterns are specified as 'type:arguments', where 'arguments' is
specific to the pattern used. The example provided in the documentation,
defined the pattern type to be 'linear', but used arguments meant to create
radial pattern. So we modify the example to use the correct type -- 'radial'.
Signed-off-by: Anurag Priyam <anurag08priyam@gmail.com>
Signed-off-by: Uli Schlachter <psychon@znc.in>
The documentation for these functions were hidden (intentionally?) from luadoc
because of misspelt @class and @name tags. Fixed the spelling, so luadoc can do
its job.
Signed-off-by: Anurag Priyam <anurag08priyam@gmail.com>
Signed-off-by: Uli Schlachter <psychon@znc.in>
This option is no longer valid in modelines, so it has been removed from
all modelines using the following shellscript:
#!/bin/ksh
git ls-tree -r HEAD | cut -f2 | while read f; do
egrep -e '^(//|--) vim: .*encoding=' $f >/dev/null || continue
sed -E -e '/^(\/\/|--) vim:/s/:encoding=utf-8//' $f > /tmp/foo
mv /tmp/foo $f
done
Signed-off-by: Gregor Best <gbe@ring0.de>
Signed-off-by: Uli Schlachter <psychon@znc.in>
This adds a lua module for parsing colors. Named colors like "black" aren't
supported, but #rrggbb and #rrggbbaa colors do work.
Signed-off-by: Uli Schlachter <psychon@znc.in>