gShowBounds = false
+gUseBlurInTransitions = false
gPath = "/skia/trunk/resources/"
return paint
end
-function center_rect(sw, sh, dst)
- local dw = dst.right - dst.left
- local dh = dst.bottom - dst.top
-
- local rw, rh
-
- if sw / sh > dw / dh then
- rw = dw
- rh = sh * dw / sw
- else
- rh = dh
- rw = sw * dh / sh
- end
-
- local x = dst.left + ((sw - rw) / 2)
- local y = dst.top + ((sh - rh) / 2)
- return make_rect(x, y, x + rw, y + rh)
-end
-
-function draw_image_centered(canvas, image)
- local sw = image:width()
- local sh = image:height()
- local dstR = center_rect(image:width(), image:height(), make_rect(20, 20, 620, 460))
- canvas:drawImageRect(image, nil, dstR)
-end
-
function draw_bullet(canvas, x, y, paint, indent)
if 0 == indent then
return
gSlideIndex = 1
+-----------------------------------------------------------------------------
+
function new_drawable_picture(pic)
return {
picture = pic,
}
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,
}
end
+gNewDrawableFactory = {
+ default = new_drawable_slide,
+ picture = convert_to_picture_drawable,
+ image = convert_to_image_drawable,
+}
+
+-----------------------------------------------------------------------------
+
function next_slide()
local prev = gSlides[gSlideIndex]
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
-
-gMakeDrawable = new_drawable_slide
+gDrawableType = "default"
load_file("slides_transitions")
transition = fade_slide_transition
end
- local prevDrawable = gMakeDrawable(prevSlide)
- local nextDrawable = gMakeDrawable(nextSlide)
+ local prevDrawable = gNewDrawableFactory[gDrawableType](prevSlide)
+ local nextDrawable = gNewDrawableFactory[gDrawableType](nextSlide)
gCurrAnimation = transition(prevDrawable, nextDrawable, is_forward)
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)
Skia Update
+Skia : Access
+- code.google.com/p/skia
+- sites.google.com/site/skiadocs
+
Skia : Overview
-- portable 2D graphics engine
-- src : geometry, images, text
-- attr: shaders, filters, antialiasing, blending
-- dst : raster, gpu, pdf, picture
+- portable graphics engine
+- 2D transformations + perspective
+- primitives: text, geometry, images
+- effects: shaders, filters, antialiasing, blending
Skia : Porting
- C++ and some SIMD assembly
- 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
+- Android : framework
- third parties : e.g. Mozilla
-- sites.google.com/site/skiadocs
Skia In Blink
- Push LCD decision-making out of Blink
Skia In Blink : Record-Time-Rasterization
-- Direct rendering during “Paint” pass
+- What? : direct rendering during “Paint” pass
-- Image scaling, filters
-- SVG patterns, masks
- Problematic in modern Blink
Skia In Blink : RTR response
- SkImageFilter w/ CPU and GPU implementations
-- FilterLevel : none, low, medium (mipmaps), high
+- 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 usuaually backed by SkPicture
+- 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
-- can be done outside of Blink thread
- GPU optimizations
-- layer "hoisting"
--- distance field fonts
+-- 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 In Blink : Roadmap
-- GPU performance
+Skia : Roadmap - performance
+- GPU
-- extended OpenGL features (e.g. geometry shaders)
-- reordering for increased batching
-- support for new low-level OpenGL APIs
-- Cross process support
--- immediate mode ala SkGPipe
--- serialize pictures
+- CPU
+-- SIMD applied to floats
+-- smarter culling in pictures
-Skia API Roadmap
+Skia : Roadmap - API
+- Cross process support
- Direct support for sRGB
-- Stable C API / ABI
--- bindings for JS, Go, Python, Lua
- Robust file format
+- Support PDF viewing
+- Stable C ABI
+-- bindings for JS, Go, Python, Lua
Demo
-
function set_blur(paint, alpha)
local sigma = sqr(1 - alpha) * 20
--- paint:setImageFilter(Sk.newBlurImageFilter(sigma, sigma))
+ if gUseBlurInTransitions then
+ paint:setImageFilter(Sk.newBlurImageFilter(sigma, sigma))
+ end
paint:setAlpha(alpha)
end
end
end
end
--- pretty_print_slides(slides)
+ flush(slides, block)
+
return slides
end
}
static int lsk_newRasterSurface(lua_State* L) {
- int width = lua2int_def(L, 2, 0);
+ int width = lua2int_def(L, 1, 0);
int height = lua2int_def(L, 2, 0);
SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
SkSurface* surface = SkSurface::NewRaster(info);