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 (20)

Jetpack Compose beginner.pdf
Jetpack Compose beginner.pdfJetpack Compose beginner.pdf
Jetpack Compose beginner.pdf
 
Swift in SwiftUI
Swift in SwiftUISwift in SwiftUI
Swift in SwiftUI
 
OpenGLES - Graphics Programming in Android
OpenGLES - Graphics Programming in Android OpenGLES - Graphics Programming in Android
OpenGLES - Graphics Programming in Android
 
[KGC2014] DX9에서DX11로의이행경험공유
[KGC2014] DX9에서DX11로의이행경험공유[KGC2014] DX9에서DX11로의이행경험공유
[KGC2014] DX9에서DX11로의이행경험공유
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
 
Introduction to 2D/3D Graphics
Introduction to 2D/3D GraphicsIntroduction to 2D/3D Graphics
Introduction to 2D/3D Graphics
 
Jdbc Ppt
Jdbc PptJdbc Ppt
Jdbc Ppt
 
NVIDIA OpenGL in 2016
NVIDIA OpenGL in 2016NVIDIA OpenGL in 2016
NVIDIA OpenGL in 2016
 
CS 354 Vector Graphics & Path Rendering
CS 354 Vector Graphics & Path RenderingCS 354 Vector Graphics & Path Rendering
CS 354 Vector Graphics & Path Rendering
 
Advance oops concepts
Advance oops conceptsAdvance oops concepts
Advance oops concepts
 
Android graphics
Android graphicsAndroid graphics
Android graphics
 
Hibernate
HibernateHibernate
Hibernate
 
JDBC ppt
JDBC pptJDBC ppt
JDBC ppt
 
OpenGL 4.4 - Scene Rendering Techniques
OpenGL 4.4 - Scene Rendering TechniquesOpenGL 4.4 - Scene Rendering Techniques
OpenGL 4.4 - Scene Rendering Techniques
 
.Net Assemblies
.Net Assemblies.Net Assemblies
.Net Assemblies
 
Swing
SwingSwing
Swing
 
Programming with OpenGL
Programming with OpenGLProgramming with OpenGL
Programming with OpenGL
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Java &amp; advanced java
Java &amp; advanced javaJava &amp; advanced java
Java &amp; advanced java
 
jpa-hibernate-presentation
jpa-hibernate-presentationjpa-hibernate-presentation
jpa-hibernate-presentation
 

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

Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 

Recently uploaded (20)

Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 

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