Slide 1

Slide 1 text

ONscreen vs. OFFscreen rendering Tomáš Jukin @Inza

Slide 2

Slide 2 text

Březen 2013 - iOS

Slide 3

Slide 3 text

www.for-mobile.cz @forMobileCZ #forMobileCZ www.srazy.info/for-mobile Březen 2013 - iOS

Slide 4

Slide 4 text

www.juicymo.cz

Slide 5

Slide 5 text

www.iknow.eu/cvut/

Slide 6

Slide 6 text

ONscreen vs. OFFscreen rendering Tomáš Jukin @Inza

Slide 7

Slide 7 text

iOS Stack UIKit UIKit Core Animation Core Animation OpenGL ES Core Graphics GPU CPU

Slide 8

Slide 8 text

iOS Stack UIKit UIKit Core Animation Core Animation OpenGL ES Core Graphics GPU CPU UIButton UILabel smooth transitions 2D/3D Graphics Quartz

Slide 9

Slide 9 text

iOS Stack UIKit UIKit Core Animation Core Animation OpenGL ES Core Graphics GPU CPU UIButton UILabel smooth transitions 2D/3D Graphics Quartz C language C language

Slide 10

Slide 10 text

iOS Stack UIKit UIKit Core Animation Core Animation OpenGL ES Core Graphics GPU CPU Hardware Acceleration

Slide 11

Slide 11 text

GPU ONscreen rendering data obrazovka

Slide 12

Slide 12 text

OFFscreen rendering CPU data GPU bitmapa obrazovka

Slide 13

Slide 13 text

Kdy se použije OFFscreen rendering? • Core Graphics (když použiju cokoliv s CG*) • drawRect() metoda, i prázdná! • CALayer s shouldRasterize == YES. • CALayer s maskami (setMasksToBounds) dynamickými stíny (setShadow*). • drawText včetně Core Text. • použití group opacity (UIViewGroupOpacity).

Slide 14

Slide 14 text

Proč a kdy to vadí? “Offscreen drawing affects performance when animation is involved”

Slide 15

Slide 15 text

Jak to testovat? Nebo to umí i Instruments...

Slide 16

Slide 16 text

Case Study: UIButton Předrenderované assety CALayer drawRect Jak udělat grafiku pro UIButton?

Slide 17

Slide 17 text

Předrenderované assety GPU + předrenderované malé resizeable/tileable obrázky ZENové, náročné na údržbu a realizaci

Slide 18

Slide 18 text

CALayer nutné OFFscreen průběhy pro maskování rohů v Core Animation je defaultně zapnutá animace Overkill

Slide 19

Slide 19 text

drawRect drawRect -> Core Graphics touch -> setNeedsDisplay -> redraw CPU & memory waste hodně tlačítek v UI naráz = smrt

Slide 20

Slide 20 text

Závěr? Máme tedy JEN assety? NE! Je tu hybridní přístup: Kód -> obrázek -> assetový postup pro všechny instance

Slide 21

Slide 21 text

One more thing...

Slide 22

Slide 22 text

GPU OFFscreen rendering! CPU OFFscreen rendering je synchronní s aplikací - je to zápis do bitmapy pixel by pixel OFFscreen rendering může dělat i GPU! -> render server - asynchronně Změna kontextu mezi ON a OFF je pro GPU ale strašně drahá!

Slide 23

Slide 23 text

GPU OFFscreen rendering! důsledek: GPU může kreslit pomaleji než CPU! (flush + bariéra) Proto je CoreGraphics přes CPU [CALayer setShouldRasterize:] vs. CG - nutno testovat!

Slide 24

Slide 24 text

Next

Slide 25

Slide 25 text

Next ? KVC, KVO a Cocoa Bindings Document Oriented Programing v Cocoa Advanced Cora Data