break transitions into separate file

BUG=skia:
TBR=
NOTRY=True

Review URL: https://codereview.chromium.org/692543004
This commit is contained in:
reed 2014-10-29 20:36:05 -07:00 committed by Commit bot
parent 7a6184fdf7
commit 07dada770b
4 changed files with 256 additions and 116 deletions

View File

@ -2,8 +2,10 @@
gPath = "/skia/trunk/resources/"
function load_file(file)
local prev_path = package.path
package.path = package.path .. ";" .. gPath .. file .. ".lua"
require(file)
package.path = prev_path
end
load_file("slides_utils")
@ -44,97 +46,6 @@ function drawSlide(canvas, slide, template)
end
end
function scale_text_delta(template, delta)
template = template.slide
for i = 1, #template do
local paint = template[i].paint
paint:setTextSize(paint:getTextSize() + delta)
end
end
function slide_transition(prev, next, is_forward)
local rec = {
proc = function(self, canvas, drawSlideProc)
if self:isDone() then
drawSlideProc(canvas)
return nil
end
self.prevDrawable:draw(canvas, self.curr_x, 0)
self.nextDrawable:draw(canvas, self.curr_x + 640, 0)
self.curr_x = self.curr_x + self.step_x
return self
end
}
if is_forward then
rec.prevDrawable = prev
rec.nextDrawable = next
rec.curr_x = 0
rec.step_x = -15
rec.isDone = function (self) return self.curr_x <= -640 end
else
rec.prevDrawable = next
rec.nextDrawable = prev
rec.curr_x = -640
rec.step_x = 15
rec.isDone = function (self) return self.curr_x >= 0 end
end
return rec
end
function sqr(value) return value * value end
function set_blur(paint, alpha)
local sigma = sqr(1 - alpha) * 20
-- paint:setImageFilter(Sk.newBlurImageFilter(sigma, sigma))
paint:setAlpha(alpha)
end
function fade_slide_transition(prev, next, is_forward)
local rec = {
paint = Sk.newPaint(),
prevDrawable = prev,
nextDrawable = next,
proc = function(self, canvas, drawSlideProc)
if self:isDone() then
drawSlideProc(canvas)
return nil
end
set_blur(self.paint, self.prev_a)
self.prevDrawable:draw(canvas, self.prev_x, 0, self.paint)
set_blur(self.paint, self.next_a)
self.nextDrawable:draw(canvas, self.next_x, 0, self.paint)
self:step()
return self
end
}
if is_forward then
rec.prev_x = 0
rec.prev_a = 1
rec.next_x = 640
rec.next_a = 0
rec.isDone = function (self) return self.next_x <= 0 end
rec.step = function (self)
self.next_x = self.next_x - 20
self.next_a = (640 - self.next_x) / 640
self.prev_a = 1 - self.next_a
end
else
rec.prev_x = 0
rec.prev_a = 1
rec.next_x = 0
rec.next_a = 0
rec.isDone = function (self) return self.prev_x >= 640 end
rec.step = function (self)
self.prev_x = self.prev_x + 20
self.prev_a = (640 - self.prev_x) / 640
self.next_a = 1 - self.prev_a
end
end
return rec
end
--------------------------------------------------------------------------------------
function make_tmpl(paint, extra_dy)
return { paint = paint, extra_dy = extra_dy }
@ -253,12 +164,14 @@ end
-- gMakeDrawable = convert_to_picture_drawable
gMakeDrawable = new_drawable_slide
load_file("slides_transitions")
function spawn_transition(prevSlide, nextSlide, is_forward)
local transition
if is_forward then
transition = prevSlide.transition
transition = gTransitionTable[nextSlide.transition]
else
transition = nextSlide.transition
transition = gTransitionTable[prevSlide.transition]
end
if not transition then

View File

@ -1,4 +1,6 @@
Skia Overview [Fall '13]
Skia Overview 2014
< transition =slide>
One API -- many backends
- Raster [8888, 565, A8]
@ -8,6 +10,8 @@ One API -- many backends
- Picture
- Pipe
<transition= fade>
One Team -- many clients
- Chrome
- ChromeOS
@ -15,11 +19,15 @@ One Team -- many clients
- Android Framework
- 3rd parties (e.g. FireFox)
<transition= rotate>
Optimize for CPU variety
- x86 - 32bit (SSE, SSE2, ...), 64bit
- Arm - thumb, arm, NEON, ... 64bit?
- MIPS (just starting)
<transition= zoom>
Optimize for GPU variety
- Nvidia
- Qualcom

View File

@ -0,0 +1,206 @@
function scale_text_delta(template, delta)
template = template.slide
for i = 1, #template do
local paint = template[i].paint
paint:setTextSize(paint:getTextSize() + delta)
end
end
function slide_transition(prev, next, is_forward)
local rec = {
proc = function(self, canvas, drawSlideProc)
if self:isDone() then
drawSlideProc(canvas)
return nil
end
self.prevDrawable:draw(canvas, self.curr_x, 0)
self.nextDrawable:draw(canvas, self.curr_x + 640, 0)
self.curr_x = self.curr_x + self.step_x
return self
end
}
if is_forward then
rec.prevDrawable = prev
rec.nextDrawable = next
rec.curr_x = 0
rec.step_x = -15
rec.isDone = function (self) return self.curr_x <= -640 end
else
rec.prevDrawable = next
rec.nextDrawable = prev
rec.curr_x = -640
rec.step_x = 15
rec.isDone = function (self) return self.curr_x >= 0 end
end
return rec
end
function sqr(value) return value * value end
function set_blur(paint, alpha)
local sigma = sqr(1 - alpha) * 20
-- paint:setImageFilter(Sk.newBlurImageFilter(sigma, sigma))
paint:setAlpha(alpha)
end
function fade_slide_transition(prev, next, is_forward)
local rec = {
paint = Sk.newPaint(),
prevDrawable = prev,
nextDrawable = next,
proc = function(self, canvas, drawSlideProc)
if self:isDone() then
drawSlideProc(canvas)
return nil
end
set_blur(self.paint, self.prev_a)
self.prevDrawable:draw(canvas, self.prev_x, 0, self.paint)
set_blur(self.paint, self.next_a)
self.nextDrawable:draw(canvas, self.next_x, 0, self.paint)
self:step()
return self
end
}
if is_forward then
rec.prev_x = 0
rec.prev_a = 1
rec.next_x = 640
rec.next_a = 0
rec.isDone = function (self) return self.next_x <= 0 end
rec.step = function (self)
self.next_x = self.next_x - 20
self.next_a = (640 - self.next_x) / 640
self.prev_a = 1 - self.next_a
end
else
rec.prev_x = 0
rec.prev_a = 1
rec.next_x = 0
rec.next_a = 0
rec.isDone = function (self) return self.prev_x >= 640 end
rec.step = function (self)
self.prev_x = self.prev_x + 20
self.prev_a = (640 - self.prev_x) / 640
self.next_a = 1 - self.prev_a
end
end
return rec
end
function fade_transition(prev, next, is_forward)
local rec = {
paint = Sk.newPaint(),
prevDrawable = prev,
nextDrawable = next,
proc = function(self, canvas, drawSlideProc)
if self:isDone() then
drawSlideProc(canvas)
return nil
end
set_blur(self.paint, self.prev_a)
self.prevDrawable:draw(canvas, 0, 0, self.paint)
set_blur(self.paint, self.next_a)
self.nextDrawable:draw(canvas, 0, 0, self.paint)
self:step()
return self
end
}
rec.prev_a = 1
rec.next_a = 0
rec.isDone = function (self) return self.next_a >= 1 end
rec.step = function (self)
self.prev_a = math.max(self.prev_a - 0.025, 0)
self.next_a = 1 - self.prev_a
end
return rec
end
function rotate_transition(prev, next, is_forward)
local rec = {
angle = 0,
prevDrawable = prev,
nextDrawable = next,
activeDrawable = prev,
proc = function(self, canvas, drawSlideProc)
if self:isDone() then
drawSlideProc(canvas)
return nil
end
canvas:save()
canvas:translate(320, 240)
canvas:rotate(self.angle)
canvas:translate(-320, -240)
self.activeDrawable:draw(canvas, 0, 0)
self:step()
return self
end,
isDone = function (self) return self.angle >= 360 or self.angle <= -360 end
}
if is_forward then
rec.step = function (self)
self.angle = self.angle + 10
if self.angle >= 180 then
self.activeDrawable = self.nextDrawable
end
end
else
rec.step = function (self)
self.angle = self.angle - 10
if self.angle <= -180 then
self.activeDrawable = self.nextDrawable
end
end
end
return rec
end
function zoom_transition(prev, next, is_forward)
local rec = {
scale = 1,
scale_delta = .95,
scale_limit = 0.2,
pivot_x = 320,
pivot_y = 240,
prevDrawable = prev,
nextDrawable = next,
activeDrawable = prev,
proc = function(self, canvas, drawSlideProc)
if self:isDone() then
drawSlideProc(canvas)
return nil
end
canvas:translate(self.pivot_x, self.pivot_y)
canvas:scale(self.scale, self.scale)
canvas:translate(-self.pivot_x, -self.pivot_y)
self.activeDrawable:draw(canvas, 0, 0)
self:step()
return self
end,
isDone = function (self) return self.scale > 1 end,
step = function (self)
if self.scale < self.scale_limit then
self.scale = self.scale_limit
self.scale_delta = 1 / self.scale_delta
self.activeDrawable = self.nextDrawable
end
self.scale = self.scale * self.scale_delta
end
}
return rec
end
gTransitionTable = {
fade = fade_transition,
slide = slide_transition,
fade_slide = fade_slide_transition,
rotate = rotate_transition,
zoom = zoom_transition,
}

View File

@ -29,30 +29,11 @@ function count_hypens(s)
return string.len(s) - string.len(leftover)
end
function parse_file(file)
local slides = {}
local block = {}
for line in file:lines() do
local s = trim_ws(line)
if #s == 0 then -- done with a block
if #block > 0 then
slides[#slides + 1] = block
block = {}
end
else
local n = count_hypens(s)
block[#block + 1] = {
indent = n,
text = trim_ws(s:sub(n + 1, -1))
}
end
end
return slides
end
function pretty_print_slide(slide)
io.write("{\n")
if slide.transition then
io.write(" transition = \"", slide.transition, "\",\n")
end
for i = 1, #slide do
local node = slide[i]
for j = 0, node.indent do
@ -73,3 +54,35 @@ function pretty_print_slides(slides)
io.write("}\n")
end
function parse_transition_type(s)
return s:match("^<%s*transition%s*=%s*(%a+)%s*>$")
end
function parse_file(file)
local slides = {}
local block = {}
for line in file:lines() do
local s = trim_ws(line)
if #s == 0 then -- done with a block
if #block > 0 then
slides[#slides + 1] = block
block = {}
end
else
local transition_type = parse_transition_type(s)
if transition_type then
block["transition"] = transition_type
else
local n = count_hypens(s)
block[#block + 1] = {
indent = n,
text = trim_ws(s:sub(n + 1, -1))
}
end
end
end
-- pretty_print_slides(slides)
return slides
end