Skip to content

Commit

Permalink
emulated screen flash on Emulator
Browse files Browse the repository at this point in the history
This (re-)introduces a simulated "flash" (for now: invert, invert back)
of refresh sections with the Emulator. Since this is only useful when
debugging, it is off by default. It can be enabled by setting an
environment variable EMULATE_READER_FLASH. Set it to the number of
microseconds you want the flash to take. Suggested are values 200-700,
depending on how closely you want to look at refreshes :-)
  • Loading branch information
hwhw committed Nov 27, 2014
1 parent 338c578 commit b632bdf
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 10 deletions.
33 changes: 27 additions & 6 deletions ffi/framebuffer_SDL1_2.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-- load common SDL input/video library
local SDL = require("ffi/SDL1_2")
local BB = require("ffi/blitbuffer")
local util = require("ffi/util")

local framebuffer = {}

Expand All @@ -20,12 +21,7 @@ function framebuffer:init()
framebuffer.parent.init(self)
end

function framebuffer:refreshFullImp()
if self.dummy then return end

-- adapt to possible rotation changes
self.bb:setRotation(self.bb:getRotation())

local function flip()
if SDL.SDL.SDL_LockSurface(SDL.screen) < 0 then
error("Locking screen surface")
end
Expand All @@ -34,6 +30,31 @@ function framebuffer:refreshFullImp()
SDL.SDL.SDL_Flip(SDL.screen)
end

function framebuffer:refreshFullImp(x, y, w, h)
if self.dummy then return end

local bb = self.full_bb or self.bb

if not (x and y and w and h) then
x = 0
y = 0
w = bb:getWidth()
h = bb:getHeight()
end

self.debug("refresh on physical rectangle", x, y, w, h)

local flash = os.getenv("EMULATE_READER_FLASH")
if flash then
bb:invertRect(x, y, w, h)
flip()
util.usleep(tonumber(flash)*1000)
bb:invertRect(x, y, w, h)
end

flip()
end

function framebuffer:close()
SDL.SDL.SDL_Quit()
end
Expand Down
31 changes: 27 additions & 4 deletions ffi/framebuffer_SDL2_0.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-- load common SDL input/video library
local SDL = require("ffi/SDL2_0")
local BB = require("ffi/blitbuffer")
local util = require("ffi/util")

local framebuffer = {}

Expand All @@ -19,15 +20,37 @@ function framebuffer:init()
framebuffer.parent.init(self)
end

function framebuffer:refreshFullImp()
if self.dummy then return end

SDL.SDL.SDL_UpdateTexture(SDL.texture, nil, self.bb.data, self.bb.pitch)
local function render(bb)
SDL.SDL.SDL_UpdateTexture(SDL.texture, nil, bb.data, bb.pitch)
SDL.SDL.SDL_RenderClear(SDL.renderer)
SDL.SDL.SDL_RenderCopy(SDL.renderer, SDL.texture, nil, nil)
SDL.SDL.SDL_RenderPresent(SDL.renderer)
end

function framebuffer:refreshFullImp()
if self.dummy then return end

local bb = self.full_bb or self.bb

if not (x and y and w and h) then
x = 0
y = 0
w = bb:getWidth()
h = bb:getHeight()
end

self.debug("refresh on physical rectangle", x, y, w, h)

local flash = os.getenv("EMULATE_READER_FLASH")
if flash then
bb:invertRect(x, y, w, h)
render(bb)
util.usleep(tonumber(flash)*1000)
bb:invertRect(x, y, w, h)
end
render(bb)
end

function framebuffer:close()
SDL.SDL.SDL_Quit()
end
Expand Down

0 comments on commit b632bdf

Please sign in to comment.