Commit Graph

19 Commits

Author SHA1 Message Date
Emmanuel Lepage Vallee 7349f3b902 Make sure gears.color.create_png_pattern are being repeated 2014-04-08 22:57:05 +02:00
Uli Schlachter ed6d5e0246 gears.color: Handle nil arguments correctly again
Signed-off-by: Uli Schlachter <psychon@znc.in>
2014-04-03 20:27:45 +02:00
Uli Schlachter b9361d54c6 gears.color: Add a pattern cache
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>
2014-03-29 22:52:04 +01:00
Uli Schlachter 1847b0ae1f gears.color.create_opaque_pattern: Fix for SurfacePatterns (FS#1236)
Sorry!

Signed-off-by: Uli Schlachter <psychon@znc.in>
2014-03-23 21:51:29 +01:00
Uli Schlachter 1924ee9e6e drawin: Only redraw on move with translucent background
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>
2014-03-16 14:58:14 +01:00
Uli Schlachter fca2f3e58d gears.color: Accept cairo patterns as arguments
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>
2013-02-11 14:26:05 +01:00
Arvydas Sidorenko 997de2726c Ported lib/gears to lua 5.2
Tested with lua 5.1: all good

Signed-off-by: Arvydas Sidorenko <asido4@gmail.com>
Signed-off-by: Uli Schlachter <psychon@znc.in>
2012-06-16 17:37:30 +02:00
Arvydas Sidorenko e789cfaf66 Ported lib/gears to lua 5.2
Tested with lua 5.1: all good

Signed-off-by: Arvydas Sidorenko <asido4@gmail.com>
2012-06-16 17:37:30 +02:00
Arvydas Sidorenko 9623b8e42f Changed unpack in portable way
Signed-off-by: Arvydas Sidorenko <asido4@gmail.com>
Signed-off-by: Uli Schlachter <psychon@znc.in>
2012-06-16 13:00:13 +02:00
Uli Schlachter 4f30dfd198 Switch from oocairo to lgi.cairo
Signed-off-by: Uli Schlachter <psychon@znc.in>
2012-05-27 19:20:34 +02:00
Anurag Priyam 69a96fc505 gears.color: call the correct creator function in local string_pattern function
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>
2012-02-29 20:58:01 +01:00
Uli Schlachter 2216b6a341 gears.color: Add table-based color definitions
Signed-off-by: Uli Schlachter <psychon@znc.in>
2012-02-17 17:48:11 +01:00
Arvydas Sidorenko e052bd99b0 oocairo.image_surface_create_from_png TO awesome.load_image
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>
2012-01-29 16:18:18 +01:00
Anurag Priyam 54a9ecbd27 gears.color docs: replace literal '<' and '>' with respective HTML entities
Luadoc confuses '<stop>' with an HTML tag otherwise.

Signed-off-by: Anurag Priyam <anurag08priyam@gmail.com>
Signed-off-by: Uli Schlachter <psychon@znc.in>
2012-01-13 20:07:52 +01:00
Anurag Priyam d3e8dfed2b gears.colors() docs: fix pattern string used in the example
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>
2012-01-13 20:07:52 +01:00
Anurag Priyam 765db33757 gears.color: expose documentation for create_(linear|radial)_pattern functions
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>
2012-01-13 20:07:52 +01:00
Gregor Best c2ea920ca0 remove encoding=utf-8 from modelines
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>
2011-09-11 17:34:09 +02:00
Uli Schlachter d74198b7db gears.color: Add much more sophiscated stuff
Signed-off-by: Uli Schlachter <psychon@znc.in>
2010-09-29 18:54:20 +02:00
Uli Schlachter 9a24779425 Implement color parsing
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>
2010-09-09 16:54:57 +02:00