84917

Android partial invalidation doesn't work as expected with hardware acceleration

Question:

I know this is quite the same question as <a href="https://stackoverflow.com/questions/7233830/partial-invalidation-in-custom-android-view-with-hardware-acceleration" rel="nofollow">partial-invalidation-in-custom-android-view-with-hardware-acceleration</a> but I thought I will explain my problem more detailled and hope someone will have an answer on how to solve the problem.

I wrote a simple TicTacToe app which was working fine on the emulator. But wasn't working on the device since I found out it was working as expected on the device when I disabled hardware acceleration.

All the fields are drawn with Canvas.drawBitmap(), also the "empty" fields with an empty white image. The lines are drawn with Canvas.drawLine() I'm using partial invalidation with invalidate(Rect) because I want to redraw only the area which was choosen to set a cross/circle with the according image using again Canvas.drawBitmap(). But then the whole area is invalidated, means I see the whole area/screen is gray (the white images and lines disappeared) and only the image for the cross/circle is set in the choosen area.

When I print out the invalidated field rect with Canvas.getClipBounds() in the method onDraw(), with hardware acceleration it is the whole area (example "0,0,320,407") and without hardware acceleration the same rect which I invalidated with invalidate(Rect) (e.g. "106,135,106,135").

At the moment as workaround I redraw all the fields whith the according image and lines. How can I prevent to have the whole area invalidated with hardware acceleration?

If this matters: I'm using Android version 4.1.2 on Samsung Galaxy Young Duos S6312.

Regards Sandro

Answer1:

I have post my answer in your given <a href="https://stackoverflow.com/questions/7233830/partial-invalidation-in-custom-android-view-with-hardware-acceleration" rel="nofollow">link</a>. To understand the problem , you should know the difference between software rendering and hardware rendering. That's really a big topic which I won't cover here. I think the best approach is to read the <a href="https://github.com/android/platform_frameworks_base/" rel="nofollow">source code</a>(I did the same thing a few days ago). The key question is "what is DisplayList and when it is used" . Repeat my answer here, the Canvas in onDraw is simply used to rebuild the DisplayList. That doesn't mean everything in your View will be redrawn.

Recommend

  • Android image transformation with matrix, translate touch coordinates back
  • How to save draw paint with custom view android?
  • Bitmap drawable (Map Overlay Item) pixelizes after rotation in android
  • How to draw the contour of a union of Path
  • Draw a bitmap from a control taller than the screen
  • Drawing a polygon over the entire map
  • Workflow - Database Design
  • IE11 textarea loses focus if another textarea is disabled
  • How can I reset dropdown data if modal closed on vue component?
  • How to draw a line dynamically in android [duplicate]
  • How to split circle in to the sectors in google maps?
  • Eclipse MTJ doesn't see Java ME SDK 3.0 devices
  • blade.php method outputting it's result to the form
  • How to getText() from the input field of an angularjs Application
  • Django model inheritance, filtering models
  • Using a canvas object in a thread to do simple animations - Java
  • How can I enlarge video fullscreen without the affected interface project in as3?
  • Chart.js Multiple dataset
  • WPF - CanExecute dosn't fire when raising Commands from a UserControl
  • Jackson Parser: ignore deserializing for type mismatch
  • PHP buffered output depending on server setting?
  • Functions in global context
  • How to use remove-erase idiom for removing empty vectors in a vector?
  • Python urlparse: small issue
  • Android fill_parent issue
  • FileReader+canvas image loading problem
  • R - Combining Columns to String Based on Logical Match
  • Repeat a vertical line on every page in Report Builder / SSRS
  • Why is an OPTIONS request sent to the server?
  • Read text file and split every line in MSBuild
  • Why HTML5 Canvas with a larger size stretch a drawn line?
  • How to draw moving and Running sine wave chart using JFree chart in java?
  • Sony Xperia Z Tablet not found by adb
  • Is possible to count alias result on mysql
  • Check if a string to interpolate provides expected placeholders
  • Can I make an Android app that runs a web view in Chrome 39?
  • Return words with double consecutive letters
  • how to add data labels for bar graph in matlab
  • python draw pie shapes with colour filled
  • Android Heatmap on canvas or ImageView