aboutsummaryrefslogtreecommitdiffhomepage
path: root/resources/lua
diff options
context:
space:
mode:
authorGravatar Hal Canary <halcanary@google.com>2017-12-08 10:21:31 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-12-08 17:16:00 +0000
commitc465d13e6fca5e171bde45d35b2dd43117f4702e (patch)
tree588b2b31ffba95ed8eecb5327cb4335f35c8c1bd /resources/lua
parent4bcef3c40ad8d3a16bbca4ab74fa15256fb4b125 (diff)
resources: orgainize directory.
Should make it easier to ask just for images. Change-Id: If821743dc924c4bfbc6b2b2d29b14affde7b3afd Reviewed-on: https://skia-review.googlesource.com/82684 Commit-Queue: Hal Canary <halcanary@google.com> Reviewed-by: Leon Scroggins <scroggo@google.com>
Diffstat (limited to 'resources/lua')
-rw-r--r--resources/lua/slides.lua356
-rw-r--r--resources/lua/slides_content.lua94
-rw-r--r--resources/lua/slides_content2.lua123
-rw-r--r--resources/lua/slides_transitions.lua208
-rw-r--r--resources/lua/slides_utils.lua102
-rw-r--r--resources/lua/test.lua76
6 files changed, 959 insertions, 0 deletions
diff --git a/resources/lua/slides.lua b/resources/lua/slides.lua
new file mode 100644
index 0000000000..9d61a87273
--- /dev/null
+++ b/resources/lua/slides.lua
@@ -0,0 +1,356 @@
+gShowBounds = false
+gUseBlurInTransitions = false
+
+gPath = "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")
+
+gSlides = parse_file(io.open("resources/slides_content2.lua", "r"))
+
+function make_rect(l, t, r, b)
+ return { left = l, top = t, right = r, bottom = b }
+end
+
+function make_paint(typefacename, style, size, color)
+ local paint = Sk.newPaint();
+ paint:setAntiAlias(true)
+ paint:setSubpixelText(true)
+ paint:setTypeface(Sk.newTypeface(typefacename, style))
+ paint:setTextSize(size)
+ paint:setColor(color)
+ return paint
+end
+
+function draw_bullet(canvas, x, y, paint, indent)
+ if 0 == indent then
+ return
+ end
+ local ps = paint:getTextSize()
+ local cx = x - ps * .8
+ local cy = y - ps * .4
+ local radius = ps * .2
+ canvas:drawCircle(cx, cy, radius, paint)
+end
+
+function stroke_rect(canvas, rect, color)
+ local paint = Sk.newPaint()
+ paint:setStroke(true);
+ paint:setColor(color)
+ canvas:drawRect(rect, paint)
+end
+
+function drawSlide(canvas, slide, master_template)
+
+ if #slide == 1 then
+ template = master_template.title
+ canvas:drawText(slide[1].text, 320, 240, template[1])
+ return
+ end
+
+ template = master_template.slide
+
+ local x = template.margin_x
+ local y = template.margin_y
+ local scale = 1.25
+
+ if slide.blockstyle == "code" then
+ local paint = master_template.codePaint
+ local fm = paint:getFontMetrics()
+ local height = #slide * (fm.descent - fm.ascent)
+ y = (480 - height) / 2
+ for i = 1, #slide do
+ local node = slide[i]
+ y = y - fm.ascent * scale
+ canvas:drawText(node.text, x, y, paint)
+ y = y + fm.descent * scale
+ end
+ return
+ end
+
+ for i = 1, #slide do
+ local node = slide[i]
+ local paint = template[node.indent + 1].paint
+ local extra_dy = template[node.indent + 1].extra_dy
+ local fm = paint:getFontMetrics()
+ local x_offset = -fm.ascent * node.indent * 1.25
+
+ local bounds = make_rect(x + x_offset, y, 620, 640)
+ local blob, newBottom = Sk.newTextBlob(node.text, bounds, paint)
+ draw_bullet(canvas, x + x_offset, y - fm.ascent, paint, node.indent)
+ canvas:drawTextBlob(blob, 0, 0, paint)
+ y = newBottom + paint:getTextSize() * .5 + extra_dy
+
+ if gShowBounds then
+ bounds.bottom = newBottom
+ stroke_rect(canvas, bounds, {a=1,r=0,g=1,b=0})
+ stroke_rect(canvas, blob:bounds(), {a=1,r=1,g=0,b=0})
+ end
+
+ end
+end
+
+--------------------------------------------------------------------------------------
+function make_tmpl(paint, extra_dy)
+ return { paint = paint, extra_dy = extra_dy }
+end
+
+function SkiaPoint_make_template()
+ normal = Sk.newFontStyle()
+ bold = Sk.newFontStyle(700)
+ local title = {
+ margin_x = 30,
+ margin_y = 100,
+ }
+ title[1] = make_paint("Arial", bold, 45, { a=1, r=1, g=1, b=1 })
+ title[1]:setTextAlign("center")
+ title[2] = make_paint("Arial", bold, 25, { a=1, r=.75, g=.75, b=.75 })
+ title[2]:setTextAlign("center")
+
+ local slide = {
+ margin_x = 20,
+ margin_y = 25,
+ }
+ slide[1] = make_tmpl(make_paint("Arial", bold, 35, { a=1, r=1, g=1, b=1 }), 18)
+ slide[2] = make_tmpl(make_paint("Arial", normal, 25, { a=1, r=1, g=1, b=1 }), 10)
+ slide[3] = make_tmpl(make_paint("Arial", normal, 20, { a=1, r=.9, g=.9, b=.9 }), 5)
+
+ return {
+ title = title,
+ slide = slide,
+ codePaint = make_paint("Courier", normal, 20, { a=1, r=.9, g=.9, b=.9 }),
+ }
+end
+
+gTemplate = SkiaPoint_make_template()
+
+gRedPaint = Sk.newPaint()
+gRedPaint:setAntiAlias(true)
+gRedPaint:setColor{a=1, r=1, g=0, b=0 }
+
+-- animation.proc is passed the canvas before drawing.
+-- The animation.proc returns itself or another animation (which means keep animating)
+-- or it returns nil, which stops the animation.
+--
+local gCurrAnimation
+
+gSlideIndex = 1
+
+-----------------------------------------------------------------------------
+
+function new_drawable_picture(pic)
+ return {
+ picture = pic,
+ width = pic:width(),
+ height = pic:height(),
+ draw = function (self, canvas, x, y, paint)
+ canvas:drawPicture(self.picture, x, y, paint)
+ end
+ }
+end
+
+function new_drawable_image(img)
+ return {
+ image = img,
+ width = img:width(),
+ height = img:height(),
+ draw = function (self, canvas, x, y, paint)
+ canvas:drawImage(self.image, x, y, paint)
+ end
+ }
+end
+
+function convert_to_picture_drawable(slide)
+ local rec = Sk.newPictureRecorder()
+ drawSlide(rec:beginRecording(640, 480), slide, gTemplate)
+ return new_drawable_picture(rec:endRecording())
+end
+
+function convert_to_image_drawable(slide)
+ local surf = Sk.newRasterSurface(640, 480)
+ drawSlide(surf:getCanvas(), slide, gTemplate)
+ return new_drawable_image(surf:newImageSnapshot())
+end
+
+function new_drawable_slide(slide)
+ return {
+ slide = slide,
+ draw = function (self, canvas, x, y, paint)
+ if (nil == paint or ("number" == type(paint) and (1 == paint))) then
+ canvas:save()
+ else
+ canvas:saveLayer(paint)
+ end
+ canvas:translate(x, y)
+ drawSlide(canvas, self.slide, gTemplate)
+ canvas:restore()
+ end
+ }
+end
+
+gNewDrawableFactory = {
+ default = new_drawable_slide,
+ picture = convert_to_picture_drawable,
+ image = convert_to_image_drawable,
+}
+
+-----------------------------------------------------------------------------
+
+function next_slide()
+ local prev = gSlides[gSlideIndex]
+
+ if gSlideIndex < #gSlides then
+ gSlideIndex = gSlideIndex + 1
+ spawn_transition(prev, gSlides[gSlideIndex], true)
+ end
+end
+
+function prev_slide()
+ local prev = gSlides[gSlideIndex]
+
+ if gSlideIndex > 1 then
+ gSlideIndex = gSlideIndex - 1
+ spawn_transition(prev, gSlides[gSlideIndex], false)
+ end
+end
+
+gDrawableType = "default"
+
+load_file("slides_transitions")
+
+function spawn_transition(prevSlide, nextSlide, is_forward)
+ local transition
+ if is_forward then
+ transition = gTransitionTable[nextSlide.transition]
+ else
+ transition = gTransitionTable[prevSlide.transition]
+ end
+
+ if not transition then
+ transition = fade_slide_transition
+ end
+
+ local prevDrawable = gNewDrawableFactory[gDrawableType](prevSlide)
+ local nextDrawable = gNewDrawableFactory[gDrawableType](nextSlide)
+ gCurrAnimation = transition(prevDrawable, nextDrawable, is_forward)
+end
+
+--------------------------------------------------------------------------------------
+
+function spawn_rotate_animation()
+ gCurrAnimation = {
+ angle = 0,
+ angle_delta = 5,
+ pivot_x = 320,
+ pivot_y = 240,
+ proc = function (self, canvas, drawSlideProc)
+ if self.angle >= 360 then
+ drawSlideProc(canvas)
+ return nil
+ end
+ canvas:translate(self.pivot_x, self.pivot_y)
+ canvas:rotate(self.angle)
+ canvas:translate(-self.pivot_x, -self.pivot_y)
+ drawSlideProc(canvas)
+
+ self.angle = self.angle + self.angle_delta
+ return self
+ end
+ }
+end
+
+function spawn_scale_animation()
+ gCurrAnimation = {
+ scale = 1,
+ scale_delta = .95,
+ scale_limit = 0.2,
+ pivot_x = 320,
+ pivot_y = 240,
+ proc = function (self, canvas, drawSlideProc)
+ if self.scale < self.scale_limit then
+ self.scale = self.scale_limit
+ self.scale_delta = 1 / self.scale_delta
+ end
+ if self.scale > 1 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)
+ drawSlideProc(canvas)
+
+ self.scale = self.scale * self.scale_delta
+ return self
+ end
+ }
+end
+
+local bgPaint = nil
+
+function draw_bg(canvas)
+ if not bgPaint then
+ bgPaint = Sk.newPaint()
+ local grad = Sk.newLinearGradient( 0, 0, { a=1, r=0, g=0, b=.3 },
+ 640, 480, { a=1, r=0, g=0, b=.8 })
+ bgPaint:setShader(grad)
+ bgPaint:setDither(true)
+ end
+
+ canvas:drawPaint(bgPaint)
+end
+
+function onDrawContent(canvas, width, height)
+ local matrix = Sk.newMatrix()
+ matrix:setRectToRect(make_rect(0, 0, 640, 480), make_rect(0, 0, width, height), "center")
+ canvas:concat(matrix)
+
+ draw_bg(canvas)
+
+ local drawSlideProc = function(canvas)
+ drawSlide(canvas, gSlides[gSlideIndex], gTemplate)
+ end
+
+ if gCurrAnimation then
+ gCurrAnimation = gCurrAnimation:proc(canvas, drawSlideProc)
+ return true
+ else
+ drawSlideProc(canvas)
+ return false
+ end
+end
+
+function onClickHandler(x, y)
+ return false
+end
+
+local keyProcs = {
+ n = next_slide,
+ p = prev_slide,
+ r = spawn_rotate_animation,
+ s = spawn_scale_animation,
+ ["="] = function () scale_text_delta(gTemplate, 1) end,
+ ["-"] = function () scale_text_delta(gTemplate, -1) end,
+
+ b = function () gShowBounds = not gShowBounds end,
+ B = function () gUseBlurInTransitions = not gUseBlurInTransitions end,
+
+ ["1"] = function () gDrawableType = "default" end,
+ ["2"] = function () gDrawableType = "picture" end,
+ ["3"] = function () gDrawableType = "image" end,
+}
+
+function onCharHandler(uni)
+ local proc = keyProcs[uni]
+ if proc then
+ proc()
+ return true
+ end
+ return false
+end
diff --git a/resources/lua/slides_content.lua b/resources/lua/slides_content.lua
new file mode 100644
index 0000000000..9b20e43c6b
--- /dev/null
+++ b/resources/lua/slides_content.lua
@@ -0,0 +1,94 @@
+Skia Overview 2014
+
+< transition =slide>
+
+One API -- many backends
+- Raster [8888, 565, A8]
+- GPU [opengl]
+- PDF
+- XPS
+- Picture
+- Pipe
+
+<transition= fade>
+
+One Team -- many clients
+- Chrome
+- ChromeOS
+- Clank
+- Android Framework
+- 3rd parties (e.g. FireFox)
+
+<transition= rotate>
+
+<blockstyle = code>
+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
+- Imagination
+- ...
+- ES2 -vs- ES3 -vs- Desktop profiles
+
+Lots of testing and measuring
+- build-bots
+-- unittests, micro-benchmarks, image-regressions
+-- http://108.170.217.252:10117/console
+- webpage archives (in progress)
+-- "map-reduce" server for saerching/historgrams
+-- macro-benchmarks, image-reressions
+-- gpu : cpu fuzzy compares
+
+Skia Roadmap [Fall '13]
+
+Roadmap in a nutshell
+- GPU performance
+- Pictures
+- Images
+- Fonts
+- PDF
+
+Roadmap : GPU Performance
+- Clipping changes are expensive
+- Texture cache optimizations
+- Better batching / reordering
+- Rely more on multi-sampling
+- ES3/desktop features (e.g. path-rendering)
+- ... continuo ad absurdum
+
+Roadmap : Pictures
+- Playback performance
+-- improve culling
+-- multi-core support
+- Record performance
+-- improve hash/cache
+-- improve measuring/bbox computation
+- Feedback to clients
+-- annotations
+-- heat-map for time spent drawing
+-- peep-hole optimizations
+
+Roadmap : Images
+- HQ filtering and mipmaps
+- Unpremul support
+- sRGB support (future)
+- Improve cache / lazy-decoding
+
+Roadmap : Fonts
+- Color emoji
+- DirectWrite on windows
+-- subpixel positioning!
+- new FontMgr -- extended styles
+
+Roadmap : PDF
+- Android
+-- perspective, color-filters
+- New Viewer project
+-- print-preview and more
+-- can output picture / gpu directly
diff --git a/resources/lua/slides_content2.lua b/resources/lua/slides_content2.lua
new file mode 100644
index 0000000000..2b293a244a
--- /dev/null
+++ b/resources/lua/slides_content2.lua
@@ -0,0 +1,123 @@
+Skia Update
+
+Skia : Access
+- https://skia.org
+- https://skia.googlesource.com/skia
+
+Skia : Overview
+- portable graphics engine
+- 2D transformations + perspective
+- primitives: text, geometry, images
+- effects: shaders, filters, antialiasing, blending
+
+Skia : Porting
+- C++ and some SIMD assembly
+- Fonts : CoreText, FreeType, GDI, DirectWrite
+- Threads : wrappers for native apis
+- Memory : wrappers for [new, malloc, discardable]
+
+Skia : Backends
+- Surface
+-- raster : ARGB, RGB16, A8 in software
+-- gpu : transcribe to OpenGL
+- Document
+-- transcribe to PDF or XPS
+- Record and Playback
+-- Picture
+-- Pipe
+
+Skia : Clients
+- Blink : under the GraphicsContext hood
+- Chrome : ui/gfx and compositor
+- Android : framework
+- third parties : e.g. Mozilla
+
+Skia In Blink
+
+Skia In Blink : Fonts
+- SkTypeface and SkFontMgr : platform agnostic
+- Runtime switch between GDI and DirectWrite
+- SkTextBlob to encapsulate runs of text
+- Push LCD decision-making out of Blink
+
+Skia In Blink : Record-Time-Rasterization
+- What? : direct rendering during “Paint” pass
+-- Image scaling, filters
+-- SVG patterns, masks
+- Problematic in modern Blink
+-- CTM not always known/knowable
+-- Rendering backend not always known (gpu or cpu)
+-- Rasterization takes (too much) time
+
+Skia In Blink : RTR response
+- SkImageFilter w/ CPU and GPU implementations
+- Bitmap scaling : bilerp, mipmaps, fancy
+- SkPicture for caching SVG
+- SkPicture + saveLayer() for masks
+-- PathOps for resolving complex paths
+- SkPictureShader for device-independent patterns
+
+Skia In Blink : Recording
+- GraphicsContext (now) backed by SkPicture
+-- draw commands are recorded for later playback
+-- all parameters must be copied or (safely) ref'd
+-- may record more than is currently visible
+- Resulting picture may be replayed multiple times
+-- from different thread(s)
+
+Skia In Blink : Recording response
+- New implementation
+- Optimized for recording speed
+-- shallow copies whenever possible
+-- rearchitect all Skia effects to be immutable
+- Reentrant-safe for playback in multiple threads
+-- also affected effect subclasses
+
+Skia In Blink : Playback
+- Separate pass for optimizations (optional)
+-- peep-holes rewrites
+-- compute bounding-box hierarchy for faster tiling
+-- can be done outside of Blink thread
+- GPU optimizations
+-- layer "hoisting"
+-- distance fields : fonts and concave paths
+
+Skia In Blink : multi-picture-draw
+- mpd(canvas[], picture[], matrix[], paint[])
+- Requires independent canvas objects
+-- all other parameters can be shared
+-- draw order is unspecified
+- Examples
+-- 1 picture drawing to multiple tiles (canvases)
+-- multiple pictures each drawing to its own layer
+
+Skia In Blink : MPD optimizations*
+- GPU
+-- "layer hoisting" to reduce rendertarget switching
+-- layer atlasing (also applies to imagefilters)
+-- pre-uploading of textures
+-- atlas yuv (from jpeg) to convert on gpu
+- CPU
+-- parallel execution using thread pool
+-- pre-decoding of images based on visibility
+
+Skia : Roadmap
+
+Skia : Roadmap - performance
+- GPU
+-- extended OpenGL features (e.g. geometry shaders)
+-- reordering for increased batching
+-- support for new low-level OpenGL APIs
+- CPU
+-- SIMD applied to floats
+-- smarter culling in pictures
+
+Skia : Roadmap - API
+- Cross process support
+- Direct support for sRGB
+- Robust file format
+- Support PDF viewing
+- Stable C ABI
+-- bindings for JS, Go, Python, Lua
+
+Demo
diff --git a/resources/lua/slides_transitions.lua b/resources/lua/slides_transitions.lua
new file mode 100644
index 0000000000..bab3827767
--- /dev/null
+++ b/resources/lua/slides_transitions.lua
@@ -0,0 +1,208 @@
+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
+ if gUseBlurInTransitions then
+ paint:setImageFilter(Sk.newBlurImageFilter(sigma, sigma))
+ end
+ 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,
+}
+
diff --git a/resources/lua/slides_utils.lua b/resources/lua/slides_utils.lua
new file mode 100644
index 0000000000..3b1230c10b
--- /dev/null
+++ b/resources/lua/slides_utils.lua
@@ -0,0 +1,102 @@
+function tostr(t)
+ local str = ""
+ for k, v in next, t do
+ if #str > 0 then
+ str = str .. ", "
+ end
+ if type(k) == "number" then
+ str = str .. "[" .. k .. "] = "
+ else
+ str = str .. tostring(k) .. " = "
+ end
+ if type(v) == "table" then
+ str = str .. "{ " .. tostr(v) .. " }"
+ elseif type(v) == "string" then
+ str = str .. '"' .. v .. '"'
+ else
+ str = str .. tostring(v)
+ end
+ end
+ return str
+end
+
+function trim_ws(s)
+ return s:match("^%s*(.*)")
+end
+
+function count_hypens(s)
+ local leftover = s:match("^-*(.*)")
+ return string.len(s) - string.len(leftover)
+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
+ io.write(" ")
+ end
+ io.write("{ ")
+ io.write(tostr(node))
+ io.write(" },\n")
+ end
+ io.write("},\n")
+end
+
+function pretty_print_slides(slides)
+ io.write("gSlides = {\n")
+ for i = 1, #slides do
+ pretty_print_slide(slides[i])
+ end
+ io.write("}\n")
+end
+
+function parse_attr(s, lvalue)
+ local ts = "^<%s*" .. lvalue .. "%s*=%s*(%a+)%s*>$"
+ return s:match(ts)
+end
+
+function flush(slides, block)
+ if #block > 0 then
+ slides[#slides + 1] = block
+ return {}
+ end
+ return block
+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
+ block = flush(slides, block)
+ else
+ local transition_type = parse_attr(s, "transition")
+ local blockstyle = parse_attr(s, "blockstyle")
+ if transition_type then
+ block["transition"] = transition_type
+ elseif blockstyle then
+ block["blockstyle"] = blockstyle
+ else
+ if block.blockstyle == "code" then
+ block[#block + 1] = { text = line }
+ else
+ local n = count_hypens(s)
+ block[#block + 1] = {
+ indent = n,
+ text = trim_ws(s:sub(n + 1, -1))
+ }
+ end
+ end
+ end
+ end
+ flush(slides, block)
+
+ return slides
+end
+
diff --git a/resources/lua/test.lua b/resources/lua/test.lua
new file mode 100644
index 0000000000..03201baeda
--- /dev/null
+++ b/resources/lua/test.lua
@@ -0,0 +1,76 @@
+
+local r = { left = 10, top = 10, right = 100, bottom = 80 }
+local x = 0;
+
+local paint = Sk.newPaint();
+paint:setAntiAlias(true);
+
+local image -- = Sk.loadImage('/skia/sailboat.jpg');
+function setImageFilename(filename)
+ image = Sk.loadImage(filename)
+end
+
+
+local color = {a = 1, r = 1, g = 0, b = 0};
+
+function rnd(range)
+ return math.random() * range;
+end
+
+rndX = function () return rnd(640) end
+rndY = function () return rnd(480) end
+
+function draw_rand_path(canvas);
+ if not path_paint then
+ path_paint = Sk.newPaint();
+ path_paint:setAntiAlias(true);
+ end
+ path_paint:setColor({a = 1, r = math.random(), g = math.random(), b = math.random() });
+
+ local path = Sk.newPath();
+ path:moveTo(rndX(), rndY());
+ for i = 0, 50 do
+ path:quadTo(rndX(), rndY(), rndX(), rndY());
+ end
+ canvas:drawPath(path, path_paint);
+
+ paint:setColor{a=1,r=0,g=0,b=1};
+ local align = { 'left', 'center', 'right' };
+ paint:setTextSize(30);
+ for k, v in next, align do
+ paint:setTextAlign(v);
+ canvas:drawText('Hamburgefons', 320, 200 + 30*k, paint);
+ end
+end
+
+function onStartup()
+ local paint = Sk.newPaint();
+ paint:setColor{a=1, r=1, g=0, b=0};
+ if false then
+ local doc = Sk.newDocumentPDF('out/test.pdf');
+ local canvas = doc:beginPage(72*8.5, 72*11);
+ canvas:drawText('Hello Lua', 300, 300, paint);
+ doc:close();
+ doc = nil;
+ end
+end
+
+function onDrawContent(canvas)
+ draw_rand_path(canvas);
+ color.g = x / 100;
+ paint:setColor(color)
+ canvas:translate(x, 0);
+ canvas:drawOval(r, paint)
+ x = x + 1;
+ local r2 = {}
+ r2.left = x;
+ r2.top = r.bottom + 50;
+ r2.right = r2.left + image:width() * 1;
+ r2.bottom = r2.top + image:height() * 1;
+ canvas:drawImageRect(image, nil, r2, 0.75);
+ if x > 200 then x = 0 end;
+
+ return true -- so we can animate
+end
+
+onStartup()