2014年6月22日 星期日

Skia debugger

Skia is 2D graphics library, they provide a debugger to provide step-by-step drawing command.

Sync skia

https://sites.google.com/site/skiadocs/developer-documentation/contributing-code/downloading

Build skia

https://sites.google.com/site/skiadocs/user-documentation/quick-start-guides/linux
https://sites.google.com/site/skiadocs/developer-documentation/skia-debugger


git log to find out the match commit whose PICTURE_VERSION match android/chromium skia
PICTURE_VERSION = 10 --> 2cf444f7040614b43af67e368f3aa636ebeaa45a

# sync to specific revision
# edit .gclient
modify "safesync_url": "rev",

# create file rev and copy sha2 hash to this file
# sync
$ gclient sync
$ ./gyp_skia
# then you can build debugger & tools

Generate .skp file which is used for skia debugger

   SkPicture *pict = new SkPicture;
   SkCanvas *picCanvas = pict->beginRecording(width, height, 0);
   // do your skia drawing ...
   pict->endRecording();
   SkString path(".skp file path");
   SkFILEWStream stream(path.c_str());
   pict->serialize(&stream);
   delete pict;

Note

Make sure SkPicture.h PICTURE_VERSION is match Skia debugger

Android touch event system

Overview

Touch event start from top to bottom (each view can decide whether to intercept event), then back up from bottom to top until some view consumed it!

Overview Flow

Activity.dispatchTouchEvent -> Root View. dispatchTouchEvent
                                                       -> .... -> bottom view.dispatchTouchEvent
   (back up) -> ... -> Root View.onTouchEvent -> Activity.onTouchEvent


Detail flow inside UI view

ViewGroup.dispatchTouchEvent()

  • onInterceptTouchEvent()
    • Check if it should supersede children
    • Return true once consumes all subsequent events
  • For each child view, in reverse order they were added
    • If touch is relevant (inside view), child.dispatchTouchEvent()
    • If not handled by previous, dispatch to next view
  • If no children handle event, listener gets a chance
    • OnTouchListener.onTouch()
  • If no listener, or not handled by child
    • OnTouchEvent

Intercept touch event


  • Override ViewGropu.onInterceptHoverEvent and return true
  • After return true, all subsequent events for the current gesture will come to your onTouchEvent() directly
  • onInterceptHoverEvent  will not be called for input event of current gesture  
  • Current target view will receive ACTION_CANCEL
  • Intercept cannot be reversed until the next gesture

Misc

  • use TouchDelegate if you want to touch area different from view bounding

Reference