SlideShare a Scribd company logo
1 of 119
Android
Rendering
Romain Guy                   @romainguy
Chet Haase                   @chethaase
May 11, 2011


Feedback goo.gl/wI57L
Hashtags #io2011, #Android
Android Accelerated
Rendering
Romain Guy                   @romainguy
Chet Haase                   @chethaase
May 11, 2011


Feedback goo.gl/wI57L
Hashtags #io2011, #Android
Hardware OpenGL
Why now?
memcpy (MiB/s)
                          Pixel count
1100




 825




 550




 275




   0
       G1   Droid   N1   NS         XOOM
UI on the GPU
on the
 GPU UI
Software rendering
Hardware rendering
Drawing a list
Drawing a list
Drawing a button
Drawing a button
Drawing a path
Drawing a path
Drawing a path
attribute vec4 position;
attribute vec2 texCoords;
uniform mat4 transform;
uniform mat4 screenSpace;
varying vec2 outTexCoords;
varying vec2 linear;

void main(void) {
    outTexCoords = texCoords;
    linear = vec2((screenSpace * position).x, 0.5);
    gl_Position = transform * position;
}



        Text+gradient vertex shader
precision mediump float;

varying   vec2 outTexCoords;
varying   vec2 linear;
uniform   sampler2D sampler;
uniform   sampler2D gradientSampler;

void main(void) {
    lowp vec4 color;
    vec4 gradient = texture2D(gradientSampler, linear);
    color = gradient * texture2D(sampler, outTexCoords).a;
    gl_FragColor = color;
}



            Text+gradient fragment shader
?
android:hardwareAccelerated="true"
Hardware acceleration control
1   <application android:hardwareAccelerated="true">
2       <activity ... />
3       <activity android:hardwareAccelerated="false" />
4   </application>
getWindow().setFlags(
    WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
    WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
View.isHardwareAccelerated();
Canvas.isHardwareAccelerated();




    GPU aware code
Caveats
Canvas   clipPath
         clipRegion
         drawPicture
         drawPoints
         drawPosText
         drawTextOnPath
         drawVertices

Paint    setLinearText
         setMaskFilter
         setRasterizer

Unsupported operations
3D transforms, XOR, Diff,
Canvas   clipRect             ReverseDiff ignored

         drawBitmapMesh       Colors array ignored

         drawLines            No anti-aliasing

         setDrawFilter        Ignored




Paint    setDither            Ignored

         setFilterBitmap      Filtering always on

         setShadowLayer       Works with text only




                Limitations
ComposeShader   Cannot contain another ComposeShader

                Cannot contain two shaders of the
                same type




                Limitations
view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);




                 Workaround
New drawing model
ViewRoot




       ViewGroup




View               View




  Old model
ViewRoot




       ViewGroup




View                  View


                  invalidate()




  Old model
ViewRoot




       ViewGroup




View                  View


                  invalidate()




  Old model
ViewRoot




       ViewGroup

                             invalidate()


View                  View


                  invalidate()




  Old model
ViewRoot




       ViewGroup

                             invalidate()


View                  View


                  invalidate()




  Old model
ViewRoot



                         invalidate()

       ViewGroup

                             invalidate()


View                  View


                  invalidate()




  Old model
ViewRoot



                         invalidate()

       ViewGroup

                             invalidate()


View                  View


                  invalidate()




  Old model
ViewRoot




       ViewGroup




View               View




  Old model
ViewRoot



                      draw()

       ViewGroup




View               View




  Old model
ViewRoot



                      draw()

       ViewGroup




View               View




  Old model
ViewRoot



                      draw()

       ViewGroup

                          draw()


View               View




  Old model
ViewRoot



                      draw()

       ViewGroup

                          draw()


View               View




  Old model
• No logic!
• List of drawing commands
• Cached when a View changes




         DisplayList
Save 3
DrawPatch
Save 3
ClipRect 20.00, 4.00, 99.00, 44.00, 1
Translate 20.00, 12.00
DrawText 9, 18, 9, 0.00, 19.00, 0x17e898
Restore
RestoreToCount 0




  DisplayList to draw a Button
ViewRoot




         ViewGroup                                    DisplayList




View A               View B           DisplayList B                 DisplayList A




                              New model
ViewRoot




         ViewGroup                                      DisplayList




View A                 View B           DisplayList B                 DisplayList A


                    invalidate()




                                New model
ViewRoot




         ViewGroup                                              DisplayList




View A                 View B                   DisplayList B                 DisplayList A

                                   mark dirty
                    invalidate()




                                New model
ViewRoot




         ViewGroup                                              DisplayList




View A                 View B                   DisplayList B                 DisplayList A

                                   mark dirty
                    invalidate()




                                New model
ViewRoot




         ViewGroup                                                DisplayList

                                invalidate()


View A                 View B                     DisplayList B                 DisplayList A

                                     mark dirty
                    invalidate()




                                New model
ViewRoot



                           invalidate()
         ViewGroup                                                DisplayList

                                invalidate()


View A                 View B                     DisplayList B                 DisplayList A

                                     mark dirty
                    invalidate()




                                New model
rebuild
         ViewRoot




         ViewGroup                                       DisplayList




View A               View B              DisplayList B                 DisplayList A




                              New model
rebuild
         ViewRoot




         ViewGroup                       rebuild             DisplayList




View A               View B                  DisplayList B                 DisplayList A




                              New model
ViewRoot




         ViewGroup                                    DisplayList




View A               View B           DisplayList B                 DisplayList A




                              New model
draw()
         ViewRoot




         ViewGroup                                      DisplayList




View A               View B             DisplayList B                 DisplayList A




                              New model
1   background.draw();
2   panel.draw();
3   selector.draw();
4   wifi.draw();
5   turnOnWifi.draw();
6   checkBox.draw();


       Old model
1   selector.draw();
2   drawDisplayLists();




       New model
Old model    New model


View.invalidate()

Intersects a dirty
      View



           When does View.draw() run?
ViewRoot




       ViewGroup




View               View




  Old model
ViewRoot




       ViewGroup   invalidate()



View               View




  Old model
ViewRoot




       ViewGroup   invalidate()



View               View




  Old model
ViewRoot



                      invalidate()

       ViewGroup   invalidate()



View               View




  Old model
ViewRoot



                      invalidate()

       ViewGroup   invalidate()



View               View




  Old model
ViewRoot




       ViewGroup




View               View




  Old model
ViewRoot



                      draw()

       ViewGroup




View               View




  Old model
ViewRoot



                      draw()

       ViewGroup




View               View




  Old model
ViewRoot



                               draw()

                ViewGroup
draw()


         View               View




           Old model
ViewRoot



                               draw()

                ViewGroup
draw()                             draw()


         View               View




           Old model
ViewRoot




         ViewGroup                                    DisplayList




View A               View B           DisplayList B                 DisplayList A




                              New model
ViewRoot




invalidate()     ViewGroup                                    DisplayList




        View A               View B           DisplayList B                 DisplayList A




                                      New model
ViewRoot




invalidate()     ViewGroup                                           DisplayList
                                        mark dirty



        View A               View B                  DisplayList B                 DisplayList A




                                      New model
ViewRoot




invalidate()     ViewGroup                                           DisplayList
                                        mark dirty



        View A               View B                  DisplayList B                 DisplayList A




                                      New model
ViewRoot



                                 invalidate()

invalidate()     ViewGroup                                      DisplayList




        View A               View B             DisplayList B                 DisplayList A




                                      New model
ViewRoot



                                 draw()

invalidate()     ViewGroup                                    DisplayList




        View A               View B           DisplayList B                 DisplayList A




                                      New model
ViewRoot




invalidate()     ViewGroup                                        DisplayList
                                        rebuild



        View A               View B               DisplayList B                 DisplayList A




                                      New model
ViewRoot




invalidate()     ViewGroup                                        DisplayList
                                        rebuild



        View A               View B               DisplayList B                 DisplayList A




                                      New model
View.setLayerType(int type, Paint p)
Button


                    draw()
DisplayList                  Display




                Save



              DrawPatch



              ClipRect



              Translate



              DrawText



               Restore
Button


              draw()              draw()
DisplayList               Layer            Display




                Save



              DrawPatch



              ClipRect



              Translate



              DrawText



               Restore
view.setLayerType(View.LAYER_TYPE_NONE, null)




             3 types of layers
view.setLayerType(View.LAYER_TYPE_SOFTWARE, null)




                Software layer
view.setLayerType(View.LAYER_TYPE_HARDWARE, null)




               Hardware layer
1. Performance
 Hardware layers
Drawing a ListView

                              Hardware layer                           DisplayList   Software


 Time in ms                             0.009                             2.1          10.3




Measured when drawing a ListView with Android 3.0 on a Motorola XOOM
2. Visual effects
Hardware and software layers
ColorMatrix m = new ColorMatrix();
m.setSaturation(0.0f);

Paint p = new Paint();
p.setColorFilter(new ColorMatrixColorFilter(m));

page.setLayerType(LAYER_TYPE_HARDWARE, p);
3. Compatibility
 Software layers
4. Animations
Hardware and software layers
Opacity    Position       Size    Orientation   Origin
 alpha         x         scaleX    rotation     pivotX
               y         scaleY    rotationX    pivotY
          translationX             rotationY
          translationY



           Layers-friendly properties
ViewRoot




         ViewGroup                          DisplayList




View A               View B       Layer B                 DisplayList A




               Layers-friendly properties
ViewRoot




         ViewGroup                          DisplayList




View A               View B       Layer B                 DisplayList A



              setRotationY(45)




               Layers-friendly properties
ViewRoot




         ViewGroup                                     DisplayList

                              invalidate()


View A               View B                  Layer B                 DisplayList A



              setRotationY(45)




               Layers-friendly properties
ViewRoot


                                   mark dirty

         ViewGroup                                        DisplayList

                              invalidate()


View A               View B                     Layer B                 DisplayList A



              setRotationY(45)




               Layers-friendly properties
ViewRoot


                                   mark dirty

         ViewGroup                                        DisplayList

                              invalidate()


View A               View B                     Layer B                 DisplayList A



              setRotationY(45)




               Layers-friendly properties
Save 3
DrawDisplayList A
DrawLayer B
Restore




           Parent DisplayList
viewB.setRotationY(45)



Save 3
DrawDisplayList A
DrawLayer B
Restore




           Parent DisplayList
viewB.setRotationY(45)



Save 3                          Save 3
DrawDisplayList A               DrawDisplayList A
DrawLayer B                     Rotate 0.0, 45.0, 0.0
Restore                         DrawLayer B
                                Restore




           Parent DisplayList
view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
ObjectAnimator.ofFloat(view, "rotationY", 180).start();




     Animating a complex View efficiently
view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
ObjectAnimator animator = ObjectAnimator.ofFloat(
    view, "rotationY", 180);

animator.addListener(new AnimatorListenerAdapter() {
    @Override
    public void onAnimationEnd(Animator animation) {
        view.setLayerType(View.LAYER_TYPE_NONE, null);
    }
});

animator.start();
Tips & tricks
1. Don’t use too many views
    Keep your hierarchy flat
2. Be careful of setAlpha()
Without hardware layers, it costs 2x the fill-rate
3. Reuse rendering objects
Don’t create new Paints, Bitmaps, etc. in draw()
4. Don’t modify Bitmaps often
Every change causes a texture upload
5. Don’t modify Paths often
Every change causes a new rasterization
6. Avoid overdraw
GPUs are fill-rate limited
7. Profile
DDMS and traceview are your friends
Android blog d.android.com
Romain’s blog curious-creature.org
   Chet’s blog graphics-geek.blogspot.com
Feedback http://goo.gl/wI57L
Hashtags #io2011, #Android
Q&A   Feedback http://goo.gl/wI57L
      Hashtags #io2011, #Android
Google I/O 2011, Android Accelerated Rendering

More Related Content

What's hot

Kotlin vs Java | Edureka
Kotlin vs Java | EdurekaKotlin vs Java | Edureka
Kotlin vs Java | EdurekaEdureka!
 
Hybrid mobile app development
Hybrid mobile app developmentHybrid mobile app development
Hybrid mobile app developmentChamil Madusanka
 
Android Multimedia Framework
Android Multimedia FrameworkAndroid Multimedia Framework
Android Multimedia FrameworkPicker Weng
 
Learning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessLearning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessNanik Tolaram
 
Introduction to Skia by Ryan Chou @20141008
Introduction to Skia by Ryan Chou @20141008Introduction to Skia by Ryan Chou @20141008
Introduction to Skia by Ryan Chou @20141008Ryan Chou
 
React.js Web Programlama
React.js Web ProgramlamaReact.js Web Programlama
React.js Web ProgramlamaCihan Özhan
 
BKK16-315 Graphics Stack Update
BKK16-315 Graphics Stack UpdateBKK16-315 Graphics Stack Update
BKK16-315 Graphics Stack UpdateLinaro
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced JavascriptDhruvin Shah
 
Overview of Android binder IPC implementation
Overview of Android binder IPC implementationOverview of Android binder IPC implementation
Overview of Android binder IPC implementationChethan Pchethan
 
CS 354 Vector Graphics & Path Rendering
CS 354 Vector Graphics & Path RenderingCS 354 Vector Graphics & Path Rendering
CS 354 Vector Graphics & Path RenderingMark Kilgard
 
Microsoft dot net framework
Microsoft dot net frameworkMicrosoft dot net framework
Microsoft dot net frameworkAshish Verma
 
Multithreading in Android
Multithreading in AndroidMultithreading in Android
Multithreading in Androidcoolmirza143
 
Understanding the Android System Server
Understanding the Android System ServerUnderstanding the Android System Server
Understanding the Android System ServerOpersys inc.
 
Introduction to React JS for beginners
Introduction to React JS for beginners Introduction to React JS for beginners
Introduction to React JS for beginners Varun Raj
 

What's hot (20)

Kotlin vs Java | Edureka
Kotlin vs Java | EdurekaKotlin vs Java | Edureka
Kotlin vs Java | Edureka
 
Hybrid mobile app development
Hybrid mobile app developmentHybrid mobile app development
Hybrid mobile app development
 
Android Multimedia Framework
Android Multimedia FrameworkAndroid Multimedia Framework
Android Multimedia Framework
 
Learning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessLearning AOSP - Android Booting Process
Learning AOSP - Android Booting Process
 
Introduction to Skia by Ryan Chou @20141008
Introduction to Skia by Ryan Chou @20141008Introduction to Skia by Ryan Chou @20141008
Introduction to Skia by Ryan Chou @20141008
 
React.js Web Programlama
React.js Web ProgramlamaReact.js Web Programlama
React.js Web Programlama
 
Java seminar
Java seminarJava seminar
Java seminar
 
BKK16-315 Graphics Stack Update
BKK16-315 Graphics Stack UpdateBKK16-315 Graphics Stack Update
BKK16-315 Graphics Stack Update
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
 
Explore Android Internals
Explore Android InternalsExplore Android Internals
Explore Android Internals
 
Android ipm 20110409
Android ipm 20110409Android ipm 20110409
Android ipm 20110409
 
Overview of Android binder IPC implementation
Overview of Android binder IPC implementationOverview of Android binder IPC implementation
Overview of Android binder IPC implementation
 
CS 354 Vector Graphics & Path Rendering
CS 354 Vector Graphics & Path RenderingCS 354 Vector Graphics & Path Rendering
CS 354 Vector Graphics & Path Rendering
 
Android presentation
Android presentationAndroid presentation
Android presentation
 
Hybrid Mobile App
Hybrid Mobile AppHybrid Mobile App
Hybrid Mobile App
 
Microsoft dot net framework
Microsoft dot net frameworkMicrosoft dot net framework
Microsoft dot net framework
 
Binder: Android IPC
Binder: Android IPCBinder: Android IPC
Binder: Android IPC
 
Multithreading in Android
Multithreading in AndroidMultithreading in Android
Multithreading in Android
 
Understanding the Android System Server
Understanding the Android System ServerUnderstanding the Android System Server
Understanding the Android System Server
 
Introduction to React JS for beginners
Introduction to React JS for beginners Introduction to React JS for beginners
Introduction to React JS for beginners
 

Viewers also liked

Meet Henry
Meet HenryMeet Henry
Meet HenryEthos3
 
Odoo - Create themes for website
Odoo - Create themes for websiteOdoo - Create themes for website
Odoo - Create themes for websiteOdoo
 
faradays law and its applications ppt
faradays law and its applications pptfaradays law and its applications ppt
faradays law and its applications pptIndira Kundu
 
Classification of yarn yarn classification. Textile yarn. Yarn count.
Classification of yarn   yarn classification. Textile yarn. Yarn count. Classification of yarn   yarn classification. Textile yarn. Yarn count.
Classification of yarn yarn classification. Textile yarn. Yarn count. Vaibhav Mathankar
 
Engaging Learners with Technology
Engaging Learners with TechnologyEngaging Learners with Technology
Engaging Learners with TechnologyDean Shareski
 
Web Trends to Watch in 2014
Web Trends to Watch in 2014Web Trends to Watch in 2014
Web Trends to Watch in 2014David King
 
Thai tech startup ecosystem report 2017
Thai tech startup ecosystem report 2017Thai tech startup ecosystem report 2017
Thai tech startup ecosystem report 2017Techsauce Media
 
Environmental Impact Assessment (EIA) report on Rampal 1320MW coal-based powe...
Environmental Impact Assessment (EIA) report on Rampal 1320MW coal-based powe...Environmental Impact Assessment (EIA) report on Rampal 1320MW coal-based powe...
Environmental Impact Assessment (EIA) report on Rampal 1320MW coal-based powe...Probir Bidhan
 
4. heredity and evolution
4. heredity and evolution4. heredity and evolution
4. heredity and evolutionAbhay Goyal
 
Ion exchange chromatography
Ion exchange chromatographyIon exchange chromatography
Ion exchange chromatographyshishirkawde
 
Fintech and Transformation of the Financial Services Industry
Fintech and Transformation of the Financial Services IndustryFintech and Transformation of the Financial Services Industry
Fintech and Transformation of the Financial Services IndustryRobin Teigland
 
What I Carry: 10 Tools for Success
What I Carry: 10 Tools for SuccessWhat I Carry: 10 Tools for Success
What I Carry: 10 Tools for SuccessJonathon Colman
 
The Ultimate Guide to Creating Visually Appealing Content
The Ultimate Guide to Creating Visually Appealing ContentThe Ultimate Guide to Creating Visually Appealing Content
The Ultimate Guide to Creating Visually Appealing ContentNeil Patel
 
Stanford E245 Lean LaunchPad winter 10 session 01 course overview rev 4
Stanford E245 Lean LaunchPad winter 10 session 01 course overview rev 4Stanford E245 Lean LaunchPad winter 10 session 01 course overview rev 4
Stanford E245 Lean LaunchPad winter 10 session 01 course overview rev 4Stanford University
 
Dear NSA, let me take care of your slides.
Dear NSA, let me take care of your slides.Dear NSA, let me take care of your slides.
Dear NSA, let me take care of your slides.Emiland
 
Fmcg training modules-bfg
Fmcg training modules-bfgFmcg training modules-bfg
Fmcg training modules-bfgRomy Cagampan
 

Viewers also liked (20)

Meet Henry
Meet HenryMeet Henry
Meet Henry
 
Odoo - Create themes for website
Odoo - Create themes for websiteOdoo - Create themes for website
Odoo - Create themes for website
 
Means of transportation
Means of transportationMeans of transportation
Means of transportation
 
faradays law and its applications ppt
faradays law and its applications pptfaradays law and its applications ppt
faradays law and its applications ppt
 
Classification of yarn yarn classification. Textile yarn. Yarn count.
Classification of yarn   yarn classification. Textile yarn. Yarn count. Classification of yarn   yarn classification. Textile yarn. Yarn count.
Classification of yarn yarn classification. Textile yarn. Yarn count.
 
Visual Cryptography
Visual CryptographyVisual Cryptography
Visual Cryptography
 
Engaging Learners with Technology
Engaging Learners with TechnologyEngaging Learners with Technology
Engaging Learners with Technology
 
Web Trends to Watch in 2014
Web Trends to Watch in 2014Web Trends to Watch in 2014
Web Trends to Watch in 2014
 
Thai tech startup ecosystem report 2017
Thai tech startup ecosystem report 2017Thai tech startup ecosystem report 2017
Thai tech startup ecosystem report 2017
 
5000 Sat Words With Definitions
5000 Sat Words With Definitions5000 Sat Words With Definitions
5000 Sat Words With Definitions
 
Environmental Impact Assessment (EIA) report on Rampal 1320MW coal-based powe...
Environmental Impact Assessment (EIA) report on Rampal 1320MW coal-based powe...Environmental Impact Assessment (EIA) report on Rampal 1320MW coal-based powe...
Environmental Impact Assessment (EIA) report on Rampal 1320MW coal-based powe...
 
4. heredity and evolution
4. heredity and evolution4. heredity and evolution
4. heredity and evolution
 
Ion exchange chromatography
Ion exchange chromatographyIon exchange chromatography
Ion exchange chromatography
 
Fintech and Transformation of the Financial Services Industry
Fintech and Transformation of the Financial Services IndustryFintech and Transformation of the Financial Services Industry
Fintech and Transformation of the Financial Services Industry
 
What I Carry: 10 Tools for Success
What I Carry: 10 Tools for SuccessWhat I Carry: 10 Tools for Success
What I Carry: 10 Tools for Success
 
Mri brain anatomy Dr Muhammad Bin Zulfiqar
Mri brain anatomy Dr Muhammad Bin ZulfiqarMri brain anatomy Dr Muhammad Bin Zulfiqar
Mri brain anatomy Dr Muhammad Bin Zulfiqar
 
The Ultimate Guide to Creating Visually Appealing Content
The Ultimate Guide to Creating Visually Appealing ContentThe Ultimate Guide to Creating Visually Appealing Content
The Ultimate Guide to Creating Visually Appealing Content
 
Stanford E245 Lean LaunchPad winter 10 session 01 course overview rev 4
Stanford E245 Lean LaunchPad winter 10 session 01 course overview rev 4Stanford E245 Lean LaunchPad winter 10 session 01 course overview rev 4
Stanford E245 Lean LaunchPad winter 10 session 01 course overview rev 4
 
Dear NSA, let me take care of your slides.
Dear NSA, let me take care of your slides.Dear NSA, let me take care of your slides.
Dear NSA, let me take care of your slides.
 
Fmcg training modules-bfg
Fmcg training modules-bfgFmcg training modules-bfg
Fmcg training modules-bfg
 

Recently uploaded

Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 

Recently uploaded (20)

Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 

Google I/O 2011, Android Accelerated Rendering

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. Since Android 1.0: hardware OpenGL ES 1.x and 2.x support\nWindows composition\nGames\nRich media (live wallpapers)\n
  5. But the UI remains in software\n
  6. Aren&amp;#x2019;t we done?\nFaster CPUs, multi-cores, etc.\n
  7. New, richer experiences\nMore smoother animations\nMore and more pixels (tablets, hdpi screens)\n
  8. Software cannot keep up\nGraph from 2008 to 2011\nYellow bar increase at the same rate or faster rate\n
  9. Android 3.0 has many new features\nFavorite new UI toolkit feature: GPU support\nAll 2D ops run with OpenGL on the GPU\nAll standard apps run on the GPU\n
  10. Android 3.0 has many new features\nFavorite new UI toolkit feature: GPU support\nAll 2D ops run with OpenGL on the GPU\nAll standard apps run on the GPU\n
  11. Android 3.0 has many new features\nFavorite new UI toolkit feature: GPU support\nAll 2D ops run with OpenGL on the GPU\nAll standard apps run on the GPU\n
  12. Android 3.0 has many new features\nFavorite new UI toolkit feature: GPU support\nAll 2D ops run with OpenGL on the GPU\nAll standard apps run on the GPU\n
  13. Android 3.0 has many new features\nFavorite new UI toolkit feature: GPU support\nAll 2D ops run with OpenGL on the GPU\nAll standard apps run on the GPU\n
  14. How does it work?\nHere&amp;#x2019;s the software rendering pipeline (pre-3.0 or apps without h/w in 3.0+)\n
  15. The new hw accelerated pipeline translates Canvas calls to OpenGL\nOpenGL primitives are rasterized by the GPU\n
  16. We have points, lines, triangles and textures\nEach draw call is a combo of those\nHere is a ListView, you can notice the fades at top/bottom\n
  17. A simple button, 9patches are great in OpenGL\nResult is a simple mesh + texture\n
  18. A path is rendered using a combination of geometry (quad) and an alpha texture\nColor is applied in the fragment shader\nText is drawn in a similar way\n
  19. A path is rendered using a combination of geometry (quad) and an alpha texture\nColor is applied in the fragment shader\nText is drawn in a similar way\n
  20. A path is rendered using a combination of geometry (quad) and an alpha texture\nColor is applied in the fragment shader\nText is drawn in a similar way\n
  21. A path is rendered using a combination of geometry (quad) and an alpha texture\nColor is applied in the fragment shader\nText is drawn in a similar way\n
  22. A path is rendered using a combination of geometry (quad) and an alpha texture\nColor is applied in the fragment shader\nText is drawn in a similar way\n
  23. A path is rendered using a combination of geometry (quad) and an alpha texture\nColor is applied in the fragment shader\nText is drawn in a similar way\n
  24. A path is rendered using a combination of geometry (quad) and an alpha texture\nColor is applied in the fragment shader\nText is drawn in a similar way\n
  25. Here&amp;#x2019;s an example of the vertex shader used to draw text filled with a gradient\nShaders are generated at runtime by the pipeline\nSeveral millions of shaders can be thus generated\n
  26. Drawing text with a gradient requires 2 textures:\n- an alpha texture for text\n- the gradient texture\n
  27. To enable 2D h/w acceleration, put this in AndroidManifest.xml\nThat&amp;#x2019;s all you need to do\n
  28. To enable 2D h/w acceleration, put this in AndroidManifest.xml\nThat&amp;#x2019;s all you need to do\n
  29. Hardware acceleration can be enabled/disabled at several levels\nLet&amp;#x2019;s see how it can be done at each level\n
  30. Here, enabled for the app, disabled for an activity\n
  31. It can also be enabled for a specific window\n(for instance in Activity.onCreate())\n
  32. H/w acceleration can be disabled per View\nWe&amp;#x2019;ll talk more about layers later\n
  33. If you write custom views, checking the hw accel. status might be important\nCanvas.isHardwareAccelerated() is the preferred method\nView.isHA() &amp;&amp; !Canvas.isHA() is possible (e.g. bitmap cache)\n
  34. Because of the nature of the 2D API and what GL can do, not everything will work\nSome features are missing, some are limited\nAll standard views/drawables will work\n
  35. Some ops will be supported in future releases (drawPoints for instance)\nIf these ops are needed, draw in a Bitmap, or use a software layer\n
  36. Some limitations will be lifted in future releases (AA lines for instance)\n
  37. ComposeShaders are very useful\nCurrent constraints\n
  38. An easy workaround is to use a software layer\nYou can also use a Bitmap, or Canvas.isHardwareAccelerated()\n
  39. The new rendering pipeline changes the way rendering works\nIt&amp;#x2019;s still an immediate mode\nBut with a special kind of caching\n
  40. In the old model, invalidate()ing a View meant redrawing each parent\nThis executes a lot of Java code\nBut the logic remains the same for the parents!\nExpensive!\n
  41. In the old model, invalidate()ing a View meant redrawing each parent\nThis executes a lot of Java code\nBut the logic remains the same for the parents!\nExpensive!\n
  42. In the old model, invalidate()ing a View meant redrawing each parent\nThis executes a lot of Java code\nBut the logic remains the same for the parents!\nExpensive!\n
  43. In the old model, invalidate()ing a View meant redrawing each parent\nThis executes a lot of Java code\nBut the logic remains the same for the parents!\nExpensive!\n
  44. In the old model, invalidate()ing a View meant redrawing each parent\nThis executes a lot of Java code\nBut the logic remains the same for the parents!\nExpensive!\n
  45. In the old model, invalidate()ing a View meant redrawing each parent\nThis executes a lot of Java code\nBut the logic remains the same for the parents!\nExpensive!\n
  46. In the old model, invalidate()ing a View meant redrawing each parent\nThis executes a lot of Java code\nBut the logic remains the same for the parents!\nExpensive!\n
  47. In the old model, invalidate()ing a View meant redrawing each parent\nThis executes a lot of Java code\nBut the logic remains the same for the parents!\nExpensive!\n
  48. In the old model, invalidate()ing a View meant redrawing each parent\nThis executes a lot of Java code\nBut the logic remains the same for the parents!\nExpensive!\n
  49. In the old model, invalidate()ing a View meant redrawing each parent\nThis executes a lot of Java code\nBut the logic remains the same for the parents!\nExpensive!\n
  50. In the old model, invalidate()ing a View meant redrawing each parent\nThis executes a lot of Java code\nBut the logic remains the same for the parents!\nExpensive!\n
  51. In the old model, invalidate()ing a View meant redrawing each parent\nThis executes a lot of Java code\nBut the logic remains the same for the parents!\nExpensive!\n
  52. In the old model, invalidate()ing a View meant redrawing each parent\nThis executes a lot of Java code\nBut the logic remains the same for the parents!\nExpensive!\n
  53. In the old model, invalidate()ing a View meant redrawing each parent\nThis executes a lot of Java code\nBut the logic remains the same for the parents!\nExpensive!\n
  54. In the old model, invalidate()ing a View meant redrawing each parent\nThis executes a lot of Java code\nBut the logic remains the same for the parents!\nExpensive!\n
  55. In the old model, invalidate()ing a View meant redrawing each parent\nThis executes a lot of Java code\nBut the logic remains the same for the parents!\nExpensive!\n
  56. In the old model, invalidate()ing a View meant redrawing each parent\nThis executes a lot of Java code\nBut the logic remains the same for the parents!\nExpensive!\n
  57. In the old model, invalidate()ing a View meant redrawing each parent\nThis executes a lot of Java code\nBut the logic remains the same for the parents!\nExpensive!\n
  58. In the old model, invalidate()ing a View meant redrawing each parent\nThis executes a lot of Java code\nBut the logic remains the same for the parents!\nExpensive!\n
  59. In the old model, invalidate()ing a View meant redrawing each parent\nThis executes a lot of Java code\nBut the logic remains the same for the parents!\nExpensive!\n
  60. DisplayList are simplified lists of drawing commands\nOne DisplayList per View, cached when a View changes\nTo redraw a View, we just re-issue its DisplayList\n
  61. Here is an example of a DisplayList: this draws a button\nSeveral 100s of lines of Java code are required to produce this\n
  62. A DisplayList can reference other DisplayLists\nNote that only one DisplayList is rebuilt, nothing else is touched!\nMuch less code is executed\nDrawing a display list = native code only\n\n
  63. A DisplayList can reference other DisplayLists\nNote that only one DisplayList is rebuilt, nothing else is touched!\nMuch less code is executed\nDrawing a display list = native code only\n\n
  64. A DisplayList can reference other DisplayLists\nNote that only one DisplayList is rebuilt, nothing else is touched!\nMuch less code is executed\nDrawing a display list = native code only\n\n
  65. A DisplayList can reference other DisplayLists\nNote that only one DisplayList is rebuilt, nothing else is touched!\nMuch less code is executed\nDrawing a display list = native code only\n\n
  66. A DisplayList can reference other DisplayLists\nNote that only one DisplayList is rebuilt, nothing else is touched!\nMuch less code is executed\nDrawing a display list = native code only\n\n
  67. A DisplayList can reference other DisplayLists\nNote that only one DisplayList is rebuilt, nothing else is touched!\nMuch less code is executed\nDrawing a display list = native code only\n\n
  68. A DisplayList can reference other DisplayLists\nNote that only one DisplayList is rebuilt, nothing else is touched!\nMuch less code is executed\nDrawing a display list = native code only\n\n
  69. A DisplayList can reference other DisplayLists\nNote that only one DisplayList is rebuilt, nothing else is touched!\nMuch less code is executed\nDrawing a display list = native code only\n\n
  70. A DisplayList can reference other DisplayLists\nNote that only one DisplayList is rebuilt, nothing else is touched!\nMuch less code is executed\nDrawing a display list = native code only\n\n
  71. A DisplayList can reference other DisplayLists\nNote that only one DisplayList is rebuilt, nothing else is touched!\nMuch less code is executed\nDrawing a display list = native code only\n\n
  72. A DisplayList can reference other DisplayLists\nNote that only one DisplayList is rebuilt, nothing else is touched!\nMuch less code is executed\nDrawing a display list = native code only\n\n
  73. A DisplayList can reference other DisplayLists\nNote that only one DisplayList is rebuilt, nothing else is touched!\nMuch less code is executed\nDrawing a display list = native code only\n\n
  74. A DisplayList can reference other DisplayLists\nNote that only one DisplayList is rebuilt, nothing else is touched!\nMuch less code is executed\nDrawing a display list = native code only\n\n
  75. A DisplayList can reference other DisplayLists\nNote that only one DisplayList is rebuilt, nothing else is touched!\nMuch less code is executed\nDrawing a display list = native code only\n\n
  76. A DisplayList can reference other DisplayLists\nNote that only one DisplayList is rebuilt, nothing else is touched!\nMuch less code is executed\nDrawing a display list = native code only\n\n
  77. A DisplayList can reference other DisplayLists\nNote that only one DisplayList is rebuilt, nothing else is touched!\nMuch less code is executed\nDrawing a display list = native code only\n\n
  78. A DisplayList can reference other DisplayLists\nNote that only one DisplayList is rebuilt, nothing else is touched!\nMuch less code is executed\nDrawing a display list = native code only\n\n
  79. A DisplayList can reference other DisplayLists\nNote that only one DisplayList is rebuilt, nothing else is touched!\nMuch less code is executed\nDrawing a display list = native code only\n\n
  80. A DisplayList can reference other DisplayLists\nNote that only one DisplayList is rebuilt, nothing else is touched!\nMuch less code is executed\nDrawing a display list = native code only\n\n
  81. A DisplayList can reference other DisplayLists\nNote that only one DisplayList is rebuilt, nothing else is touched!\nMuch less code is executed\nDrawing a display list = native code only\n\n
  82. A DisplayList can reference other DisplayLists\nNote that only one DisplayList is rebuilt, nothing else is touched!\nMuch less code is executed\nDrawing a display list = native code only\n\n
  83. A DisplayList can reference other DisplayLists\nNote that only one DisplayList is rebuilt, nothing else is touched!\nMuch less code is executed\nDrawing a display list = native code only\n\n
  84. A DisplayList can reference other DisplayLists\nNote that only one DisplayList is rebuilt, nothing else is touched!\nMuch less code is executed\nDrawing a display list = native code only\n\n
  85. A DisplayList can reference other DisplayLists\nNote that only one DisplayList is rebuilt, nothing else is touched!\nMuch less code is executed\nDrawing a display list = native code only\n\n
  86. A DisplayList can reference other DisplayLists\nNote that only one DisplayList is rebuilt, nothing else is touched!\nMuch less code is executed\nDrawing a display list = native code only\n\n
  87. A DisplayList can reference other DisplayLists\nNote that only one DisplayList is rebuilt, nothing else is touched!\nMuch less code is executed\nDrawing a display list = native code only\n\n
  88. Let&amp;#x2019;s examine what happens when enabling WiFi in Settings\nWe&amp;#x2019;re going to tap the Wi-Fi list item and look at what happens in both models\n\n
  89. Let&amp;#x2019;s examine what happens when enabling WiFi in Settings\nWe&amp;#x2019;re going to tap the Wi-Fi list item and look at what happens in both models\n\n
  90. Let&amp;#x2019;s examine what happens when enabling WiFi in Settings\nWe&amp;#x2019;re going to tap the Wi-Fi list item and look at what happens in both models\n\n
  91. Let&amp;#x2019;s examine what happens when enabling WiFi in Settings\nWe&amp;#x2019;re going to tap the Wi-Fi list item and look at what happens in both models\n\n
  92. Let&amp;#x2019;s examine what happens when enabling WiFi in Settings\nWe&amp;#x2019;re going to tap the Wi-Fi list item and look at what happens in both models\n\n
  93. When the selector turns blue, here are all the views that need to redraw\nEach View executes all of its Java drawing logic\nLot of code!\n
  94. With the new model, only one piece of Java code is executed\nDrawing display lists is done in native\nOnly a series of draw calls, no logic whatsoever\n
  95. If you change a View, call invalidate() on it\nDO NOT rely on calling invalidate() on a parent or sibling\nIt may have worked before, it won&amp;#x2019;t anymore\nIt was incorrect before, but worked anyway\n
  96. In the old model, invalidate()ing a View meant redrawing intersecting Views (children for instance)\nNotice how both leaves are drawn even though they are not dirty\n
  97. In the old model, invalidate()ing a View meant redrawing intersecting Views (children for instance)\nNotice how both leaves are drawn even though they are not dirty\n
  98. In the old model, invalidate()ing a View meant redrawing intersecting Views (children for instance)\nNotice how both leaves are drawn even though they are not dirty\n
  99. In the old model, invalidate()ing a View meant redrawing intersecting Views (children for instance)\nNotice how both leaves are drawn even though they are not dirty\n
  100. In the old model, invalidate()ing a View meant redrawing intersecting Views (children for instance)\nNotice how both leaves are drawn even though they are not dirty\n
  101. In the old model, invalidate()ing a View meant redrawing intersecting Views (children for instance)\nNotice how both leaves are drawn even though they are not dirty\n
  102. In the old model, invalidate()ing a View meant redrawing intersecting Views (children for instance)\nNotice how both leaves are drawn even though they are not dirty\n
  103. In the old model, invalidate()ing a View meant redrawing intersecting Views (children for instance)\nNotice how both leaves are drawn even though they are not dirty\n
  104. In the old model, invalidate()ing a View meant redrawing intersecting Views (children for instance)\nNotice how both leaves are drawn even though they are not dirty\n
  105. In the old model, invalidate()ing a View meant redrawing intersecting Views (children for instance)\nNotice how both leaves are drawn even though they are not dirty\n
  106. In the old model, invalidate()ing a View meant redrawing intersecting Views (children for instance)\nNotice how both leaves are drawn even though they are not dirty\n
  107. In the old model, invalidate()ing a View meant redrawing intersecting Views (children for instance)\nNotice how both leaves are drawn even though they are not dirty\n
  108. In the old model, invalidate()ing a View meant redrawing intersecting Views (children for instance)\nNotice how both leaves are drawn even though they are not dirty\n
  109. In the old model, invalidate()ing a View meant redrawing intersecting Views (children for instance)\nNotice how both leaves are drawn even though they are not dirty\n
  110. In the old model, invalidate()ing a View meant redrawing intersecting Views (children for instance)\nNotice how both leaves are drawn even though they are not dirty\n
  111. In the old model, invalidate()ing a View meant redrawing intersecting Views (children for instance)\nNotice how both leaves are drawn even though they are not dirty\n
  112. In the new model, invalidating a parent redraws that parent only\nNote how the children are not redrawn\n\n
  113. In the new model, invalidating a parent redraws that parent only\nNote how the children are not redrawn\n\n
  114. In the new model, invalidating a parent redraws that parent only\nNote how the children are not redrawn\n\n
  115. In the new model, invalidating a parent redraws that parent only\nNote how the children are not redrawn\n\n
  116. In the new model, invalidating a parent redraws that parent only\nNote how the children are not redrawn\n\n
  117. In the new model, invalidating a parent redraws that parent only\nNote how the children are not redrawn\n\n
  118. In the new model, invalidating a parent redraws that parent only\nNote how the children are not redrawn\n\n
  119. In the new model, invalidating a parent redraws that parent only\nNote how the children are not redrawn\n\n
  120. In the new model, invalidating a parent redraws that parent only\nNote how the children are not redrawn\n\n
  121. In the new model, invalidating a parent redraws that parent only\nNote how the children are not redrawn\n\n
  122. In the new model, invalidating a parent redraws that parent only\nNote how the children are not redrawn\n\n
  123. In the new model, invalidating a parent redraws that parent only\nNote how the children are not redrawn\n\n
  124. In the new model, invalidating a parent redraws that parent only\nNote how the children are not redrawn\n\n
  125. In the new model, invalidating a parent redraws that parent only\nNote how the children are not redrawn\n\n
  126. In the new model, invalidating a parent redraws that parent only\nNote how the children are not redrawn\n\n
  127. In the new model, invalidating a parent redraws that parent only\nNote how the children are not redrawn\n\n
  128. In the new model, invalidating a parent redraws that parent only\nNote how the children are not redrawn\n\n
  129. We briefly mentioned layers earlier, for compatibility\nBut layers can do much more, they are very useful and efficient\nThe option Paint can be used to control compositing\n
  130. Even with display lists, drawing is expensive\nA display list can have many operations\nAnimating a View requires to rerun these operations on every frame\nAnimating complex Views can be more efficient\n
  131. With a layer (or offscreen cache/bitmap), drawing happens once (or when the view invalidates)\nOnly the layer is drawn on screen, it&amp;#x2019;s just a texture\nIt&amp;#x2019;s *very* efficient, especially for the GPU\nAnd layers have other advantages too\n
  132. The type of layer LAYER_TYPE_NONE disables caching\nDefault value, View is not backed by an off-screen buffer\n
  133. The View is rendered into a Bitmap, just like setDrawingCacheEnabled(true)\nForces software rendering, good for compatibility\nExpensive to refresh a software layer (sw rendering + texture upload)\nUse only if necessary! (costs Dalvik heap memory!!!!)\n\n
  134. The View is rendered into an FBO, using OpenGL/HW acceleration\nReally fast, costs only GPU memory\nOptimized for blending\n
  135. Hardware layers render View into a hardware texture\nDrawing code runs only when View.invalidate() is called\nSome animations are applied directly onto the layer\n
  136. Perf comparison of \nDrawing a hardware layer is much faster, recommended when animating a complex View\nBut layers cost memory and refreshing a layer costs 2x the fillrate\n
  137. Use the optional Paint to apply visual treatments:\nopacity, color filter, blending modes etc.\nYou can tint a view, make it grayscale, etc.\n
  138. Launcher modified to display the icons in gray\nThe pages of icons are backed by hardware layers\nVery easy to do\n
  139. Here is the code used in the previous screenshot\nJust sets a ColorFilter on the paint used by the hardware layer\nEasy!\n
  140. Forces a View to render in software\nWorkaround for hw limitations or GL pipeline limitations\n
  141. Related to performance, but worth talking about in detail\nSome View properties affect layers directly, which make them very cheap\n
  142. When changing one of these properties, the View does not invalidate\nThe layer is not redrawn, instead the parent&amp;#x2019;s DisplayList is updated\nThis is a very efficient way to animate Views\nThese properties are also DisplayLists friendly\n
  143. When setting one of these properties, the parent is invalidated, and the parent&amp;#x2019;s DisplayList is dirtied\nRebuilding the parent&amp;#x2019;s display list is usually very cheap, since it refers to DisplayLists/Layers\n
  144. When setting one of these properties, the parent is invalidated, and the parent&amp;#x2019;s DisplayList is dirtied\nRebuilding the parent&amp;#x2019;s display list is usually very cheap, since it refers to DisplayLists/Layers\n
  145. When setting one of these properties, the parent is invalidated, and the parent&amp;#x2019;s DisplayList is dirtied\nRebuilding the parent&amp;#x2019;s display list is usually very cheap, since it refers to DisplayLists/Layers\n
  146. When setting one of these properties, the parent is invalidated, and the parent&amp;#x2019;s DisplayList is dirtied\nRebuilding the parent&amp;#x2019;s display list is usually very cheap, since it refers to DisplayLists/Layers\n
  147. When setting one of these properties, the parent is invalidated, and the parent&amp;#x2019;s DisplayList is dirtied\nRebuilding the parent&amp;#x2019;s display list is usually very cheap, since it refers to DisplayLists/Layers\n
  148. When setting one of these properties, the parent is invalidated, and the parent&amp;#x2019;s DisplayList is dirtied\nRebuilding the parent&amp;#x2019;s display list is usually very cheap, since it refers to DisplayLists/Layers\n
  149. Here is a simplified version of the parent&amp;#x2019;s display list\nDoes NOT execute() viewB.draw()\n
  150. Here is a simplified version of the parent&amp;#x2019;s display list\nDoes NOT execute() viewB.draw()\n
  151. Here is a simplified version of the parent&amp;#x2019;s display list\nDoes NOT execute() viewB.draw()\n
  152. If you want to animated a complex View (a ListView for instance), use layers\nThis is an example of a 3D rotation optimized with layers\nBut layers are costly to maintain (memory, refresh/fillrate)\n
  153. Keep layers only for the duration of the animation\nEasy to do with an AnimatorListener\nSaves time and space\n
  154. The new rendering pipeline changes the way rendering works\nIt&amp;#x2019;s still an immediate mode\nBut with a special kind of caching\n
  155. The more views you have, the longer is takes to draw\nViewGroups in particular are very costly\nKeep your hierarchy flat\n
  156. Changing the alpha of a View costs 2x the fillrate, if you are not using layers\nAvoid it on large views (half the size of the screen) or make sure you use hardware layers\n
  157. Do NOT create Paints, Bitmaps, Shaders, etc. in draw methods\nCreating new ones is costly and will defeat internal caches and optimizations\nIt also avoids unnecessary GCs\n
  158. Changing a Bitmap, even one pixel, is expensive\nIt will cause a texture upload, which is a copy to GPU memory\nAvoid doing it if you can\n
  159. Paths are rendered using texture\nChanging a path causes the generation of an offscreen bitmap, software rasterization and texture upload\n
  160. On current hardware, no more than 2.5x times the entire screen\nRemove obscured views (useless background bitmap for instance)\n
  161. Profile profile profile\nWe&amp;#x2019;ve spent weeks profiling our code to optimize it on tablets\nNasty surprises sometimes (new bitmaps created on every frame, etc.)\nAlways profile your code before blaming someone else!\n
  162. \n
  163. \n
  164. \n