add code-style for slides
BUG=skia: TBR= Review URL: https://codereview.chromium.org/697923002
This commit is contained in:
parent
181093939c
commit
de330ffc56
@ -10,7 +10,7 @@ end
|
||||
|
||||
load_file("slides_utils")
|
||||
|
||||
gSlides = parse_file(io.open("/skia/trunk/resources/slides_content.lua", "r"))
|
||||
gSlides = parse_file(io.open("/skia/trunk/resources/slides_content2.lua", "r"))
|
||||
|
||||
function make_rect(l, t, r, b)
|
||||
return { left = l, top = t, right = r, bottom = b }
|
||||
@ -26,12 +26,26 @@ function make_paint(typefacename, stylebits, size, color)
|
||||
return paint
|
||||
end
|
||||
|
||||
function drawSlide(canvas, slide, template)
|
||||
template = template.slide -- need to sniff the slide to know if we're title or slide
|
||||
function drawSlide(canvas, slide, master_template)
|
||||
template = master_template.slide -- need to sniff the slide to know if we're title or slide
|
||||
|
||||
local x = template.margin_x
|
||||
local y = template.margin_y
|
||||
|
||||
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
|
||||
canvas:drawText(node.text, x, y, paint)
|
||||
y = y + fm.descent
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
local scale = 1.25
|
||||
for i = 1, #slide do
|
||||
local node = slide[i]
|
||||
@ -72,6 +86,7 @@ function SkiaPoint_make_template()
|
||||
return {
|
||||
title = title,
|
||||
slide = slide,
|
||||
codePaint = make_paint("Courier", 0, 24, { a=1, r=.9, g=.9, b=.9 }),
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -21,6 +21,7 @@ One Team -- many clients
|
||||
|
||||
<transition= rotate>
|
||||
|
||||
<blockstyle = code>
|
||||
Optimize for CPU variety
|
||||
- x86 - 32bit (SSE, SSE2, ...), 64bit
|
||||
- Arm - thumb, arm, NEON, ... 64bit?
|
||||
|
96
resources/slides_content2.lua
Normal file
96
resources/slides_content2.lua
Normal file
@ -0,0 +1,96 @@
|
||||
Skia Update
|
||||
|
||||
Skia : Overview
|
||||
- portable 2D graphics engine
|
||||
- src: geometry, images, text
|
||||
- dst : raster, gpu, pdf, displaylist, *user-defined
|
||||
- attr: shaders, filters, antialiasing, blending, *user-defined
|
||||
|
||||
Skia : Clients
|
||||
- Blink : direct and via GraphicsContext
|
||||
- Chrome : ui/gfx and compositor
|
||||
- Android framework
|
||||
- third parties : e.g. Mozilla
|
||||
- code.google.com/p/skia
|
||||
|
||||
Skia : Porting
|
||||
- C++ and some SIMD assembly
|
||||
- Fonts : CoreText, FreeType, GDI, DirectWrite, *user-define
|
||||
- Threads : wrappers for native apis
|
||||
- Memory : wrappers for [new, malloc, discardable]
|
||||
|
||||
Skia : API
|
||||
- SkCanvas
|
||||
-- save, saveLayer, restore
|
||||
-- translate, scale, rotate, concat
|
||||
-- clipRect, clipPath
|
||||
- SkPaint
|
||||
-- color, stroking, antialiasing, filtering
|
||||
-- typeface, textSize, text-flags
|
||||
-- effects: shader, color-filter, image-filter, mask-filter, xfermode
|
||||
|
||||
<blockstyle = code>
|
||||
void onDraw(SkCanvas* canvas) {
|
||||
SkPaint paint;
|
||||
paint.setFoo(...);
|
||||
canvas->drawRect(..., paint);
|
||||
paint.setBar(...);
|
||||
canvas->drawOval(..., paint);
|
||||
}
|
||||
|
||||
<blockstyle = code>
|
||||
void onDraw(SkCanvas* canvas) {
|
||||
canvas->drawRect(..., fPaint0);
|
||||
canvas->drawOval(..., fPaint1);
|
||||
}
|
||||
|
||||
Skia In Blink : GraphicsContext
|
||||
- Similar
|
||||
-- rects, paths, images, text
|
||||
-- matrices, clips
|
||||
- Different
|
||||
-- save/restore affect matrix+clip PLUS all paint settings
|
||||
-- both fill and stroke settings are specified
|
||||
-- hence: fillRect(), strokeRect(), drawRect()
|
||||
|
||||
<blockstyle = code>
|
||||
void onDraw(GraphicsContext* gc) {
|
||||
gc->save();
|
||||
gc->setFoo(...);
|
||||
gc->fillRect(...);
|
||||
gc->setBar(...);
|
||||
gc->fillOval(...);
|
||||
gc->restore();
|
||||
}
|
||||
|
||||
Skia In Blink : more than GraphicsContext
|
||||
- Simple wrappers
|
||||
-- FloatRect -- SkRect
|
||||
-- Path -- SkPath
|
||||
- Font.h + 21 others
|
||||
-- SkTypeface + flags
|
||||
- Image.h + 25 others
|
||||
-- SkBitmap, SkImage
|
||||
|
||||
Skia In Blink : Fonts
|
||||
- Assist with code-sharing between platforms
|
||||
- Runtime switch between GDI and DirectWrite
|
||||
- Add SkFontMgr for selection
|
||||
- Push LCD decision-making out of Blink
|
||||
|
||||
Skia In Blink : Record-Time-Rasterization
|
||||
- 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
|
||||
- SkPaint::FilterLevel : none, low, medium (mipmaps), high
|
||||
- SkPicture for caching SVG
|
||||
- SkPicture + saveLayer() for masks
|
||||
-- PathOps for resolving complex paths
|
||||
- SkPictureShader for device-independent patterns
|
@ -58,6 +58,10 @@ function parse_transition_type(s)
|
||||
return s:match("^<%s*transition%s*=%s*(%a+)%s*>$")
|
||||
end
|
||||
|
||||
function parse_blockstyle_type(s)
|
||||
return s:match("^<%s*blockstyle%s*=%s*(%a+)%s*>$")
|
||||
end
|
||||
|
||||
function parse_file(file)
|
||||
local slides = {}
|
||||
local block = {}
|
||||
@ -71,14 +75,21 @@ function parse_file(file)
|
||||
end
|
||||
else
|
||||
local transition_type = parse_transition_type(s)
|
||||
local blockstyle = parse_blockstyle_type(s)
|
||||
if transition_type then
|
||||
block["transition"] = transition_type
|
||||
elseif blockstyle then
|
||||
block["blockstyle"] = blockstyle
|
||||
else
|
||||
local n = count_hypens(s)
|
||||
block[#block + 1] = {
|
||||
indent = n,
|
||||
text = trim_ws(s:sub(n + 1, -1))
|
||||
}
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user