Home | History | Annotate | Download | only in plugins
      1 /*
      2  * Copyright 2010, The Android Open Source Project
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions
      6  * are met:
      7  *  * Redistributions of source code must retain the above copyright
      8  *    notice, this list of conditions and the following disclaimer.
      9  *  * Redistributions in binary form must reproduce the above copyright
     10  *    notice, this list of conditions and the following disclaimer in the
     11  *    documentation and/or other materials provided with the distribution.
     12  *
     13  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
     14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 #include "PluginDebugAndroid.h"
     27 #include "utils/Log.h"
     28 #include "utils/SystemClock.h"
     29 #include <stdarg.h>
     30 
     31 #define ARRAY_COUNT(array) static_cast<int32_t>(sizeof(array) / sizeof(array[0]))
     32 
     33 // used for key, mouse, and touch inputs
     34 static const char* const inputActions[] = {
     35     "down",
     36     "up",
     37     "move",         /* touch only */
     38     "cancel",       /* touch only */
     39     "longPress",    /* touch only */
     40     "doubleTap"     /* touch only */
     41 };
     42 
     43 static const char* const lifecycleActions[] = {
     44     "kPause_ANPLifecycleAction",
     45     "kResume_ANPLifecycleAction",
     46     "kGainFocus_ANPLifecycleAction",
     47     "kLoseFocus_ANPLifecycleAction",
     48     "kFreeMemory_ANPLifecycleAction",
     49     "kOnLoad_ANPLifecycleAction",
     50     "kEnterFullScreen_ANPLifecycleAction",
     51     "kExitFullScreen_ANPLifecycleAction",
     52     "kOnScreen_ANPLifecycleAction",
     53     "kOffScreen_ANPLifecycleAction"
     54 };
     55 
     56 void anp_logPlugin(const char format[], ...) {
     57     va_list args;
     58     va_start(args, format);
     59     LOG_PRI_VA(ANDROID_LOG_DEBUG, "webkit_plugin", format, args);
     60     va_end(args);
     61 }
     62 
     63 void anp_logPluginEvent(void* npp, const ANPEvent* evt, int16_t returnVal, int elapsedTime) {
     64 
     65     switch(evt->eventType) {
     66 
     67         case kNull_ANPEventType:
     68             PLUGIN_LOG("%p EVENT::NULL", npp);
     69             break;
     70 
     71         case kKey_ANPEventType:
     72             if(evt->data.key.action < ARRAY_COUNT(inputActions)) {
     73                 anp_logPlugin("%p EVENT::KEY[%d] time=%d action=%s code=%d vcode=%d unichar=%d repeat=%d mods=%x",
     74                         npp, returnVal, elapsedTime, inputActions[evt->data.key.action],
     75                         evt->data.key.nativeCode, evt->data.key.virtualCode,
     76                         evt->data.key.unichar, evt->data.key.repeatCount,
     77                         evt->data.key.modifiers);
     78             } else {
     79                 PLUGIN_LOG("%p EVENT::KEY[%d] unknown action", npp, returnVal);
     80             }
     81             break;
     82 
     83         case kMouse_ANPEventType:
     84             if(evt->data.mouse.action < ARRAY_COUNT(inputActions)) {
     85                 anp_logPlugin("%p EVENT::MOUSE[%d] time=%d action=%s [%d %d]", npp,
     86                         returnVal, elapsedTime, inputActions[evt->data.mouse.action],
     87                         evt->data.touch.x, evt->data.touch.y);
     88             } else {
     89                 anp_logPlugin("%p EVENT::MOUSE[%d] unknown action", npp, returnVal);
     90             }
     91             break;
     92 
     93         case kTouch_ANPEventType:
     94             if(evt->data.touch.action < ARRAY_COUNT(inputActions)) {
     95 
     96                 anp_logPlugin("%p EVENT::TOUCH[%d] time=%d action=%s [%d %d]",
     97                         npp, returnVal, elapsedTime,
     98                         inputActions[evt->data.touch.action], evt->data.touch.x,
     99                         evt->data.touch.y);
    100             } else {
    101                 anp_logPlugin("%p EVENT::TOUCH[%d] unknown action", npp, returnVal);
    102             }
    103             break;
    104 
    105         case kDraw_ANPEventType:
    106             if (evt->data.draw.model == kBitmap_ANPDrawingModel) {
    107                 anp_logPlugin("%p EVENT::DRAW bitmap time=%d format=%d clip=[%d,%d,%d,%d]",
    108                         npp, elapsedTime, evt->data.draw.data.bitmap.format,
    109                         evt->data.draw.clip.left, evt->data.draw.clip.top,
    110                         evt->data.draw.clip.right, evt->data.draw.clip.bottom);
    111             } else if (evt->data.draw.model == kOpenGL_ANPDrawingModel) {
    112                 anp_logPlugin("%p EVENT::DRAW openGL time=%d dimensions=[%d,%d]",
    113                         npp, elapsedTime, evt->data.draw.data.surface.width,
    114                         evt->data.draw.data.surface.height);
    115             } else {
    116                 anp_logPlugin("%p EVENT::DRAW unknown drawing model", npp);
    117             }
    118             break;
    119 
    120         case kLifecycle_ANPEventType:
    121             if(evt->data.lifecycle.action < ARRAY_COUNT(lifecycleActions)) {
    122                 anp_logPlugin("%p EVENT::LIFECYCLE time=%d action=%s", npp, elapsedTime,
    123                         lifecycleActions[evt->data.lifecycle.action]);
    124             } else {
    125                 anp_logPlugin("%p EVENT::LIFECYCLE unknown action", npp);
    126             }
    127             break;
    128 
    129         case kCustom_ANPEventType:
    130             anp_logPlugin("%p EVENT::CUSTOM time=%d", npp, elapsedTime);
    131             break;
    132 
    133         default:
    134             anp_logPlugin("%p EVENT::UNKNOWN", npp);
    135             break;
    136     }
    137 }
    138