skia project run in Android.4.2, Does there exists difference define in Android 4.2 and Android 2.2?

303 views Asked by At

I try to display YUV video on the Andorid In Android 2.2 version, it is OK however in Android 4.2 the screen is total black

In the project, I use JAVA to display the content of image and use jni to read YUV and return the YUV data back to JAVA

The following is my jni code #include "SkiaDemoJni.h" #include "mylog.h"

#include "GraphicsJNI.h"
#include "SkPaint.h"
#include "SkCanvas.h"

#include"opj_includes.h"
#include <wchar.h>
#include <android\log.h> 
#include <android\bitmap.h>

#define two_pi (6.283)

unsigned char cur_image_y[101376];
unsigned char cur_image_u[101376];
unsigned char cur_image_v[101376];

inline int32_t color(int32_t pColorY,int32_t pColorU,int32_t pColorV) {
int32_t pColorR;
int32_t pColorG;
 int32_t pColorB;
 pColorR = pColorY+1.4075*(pColorV-128);
 pColorG = pColorY-0.3455*(pColorU-128)-0.7169*(pColorV-128);
 pColorB = pColorY+1.7790*(pColorU-128);
 if(pColorR>255)
  pColorR=255;
 if(pColorG>255)
  pColorG=255;
 if(pColorB>255)
 pColorB=255;   

 if(pColorR<0)
 pColorR=0;
 if(pColorG<0)
 pColorG=0;
 if(pColorB<0)
 pColorB=0;     

 return 0xFF000000 | ((pColorB << 16) & 0x00FF0000) | ((pColorG << 8) & 0x0000FF00) |       
 ((pColorR) & 0x000000FF);
     }
  void Java_com_whtr_example_skiademo_SkiaView_renderHello(JNIEnv *env, jobject thizz,     
  jobject canvas, jint FrameNum,jobject rect)
  {   
  jclass bitmapConfig = env->FindClass("android/graphics/Bitmap$Config");
  jfieldID rgb565FieldID = env->GetStaticFieldID(bitmapConfig, "ARGB_8888",   
  "Landroid/graphics/Bitmap$Config;");
  jobject rgb565Obj = env->GetStaticObjectField(bitmapConfig, rgb565FieldID); 

  jclass bitmapClass = env->FindClass("android/graphics/Bitmap");
  jmethodID createBitmapMethodID = env->GetStaticMethodID(bitmapClass,"createBitmap", 
  "(IILandroid/graphics/Bitmap$Config;)Landroid/graphics/Bitmap;");
  jobject bitmapObj = env->CallStaticObjectMethod(bitmapClass, createBitmapMethodID,  
  352, 288, rgb565Obj);//width,height 
  int a[101376]={0};
  AndroidBitmapInfo   info;   
  int*                pixels;
  int                ret;    
  ret = AndroidBitmap_getInfo(env, bitmapObj, &info);    
  ret = AndroidBitmap_lockPixels(env, bitmapObj, (void**)&pixels);       
  int                width=(int)info.width;  
  int                height=(int)info.height;
  SkBitmap bmp = SkBitmap();  
  bmp.setConfig(SkBitmap::kARGB_8888_Config,width,height);   
  bmp.setPixels((void*)pixels);
  SkCanvas background(bmp);
  SkCanvas* canv = GraphicsJNI::getNativeCanvas(env, canvas);
  if (!canv)
  {
  LOGE("!canv");
  return;
  } 
   systemPara sys;   

  sys.width = 352;

  sys.height = 288;
  sys.frameNO = 1;
  sys.startFrm = 0;
  sys.inFileName = new char[strlen("/mnt/sdcard/out_352x288_P420_final.yuv")+1];
  strcpy(sys.inFileName, "/mnt/sdcard/out_352x288_P420_final.yuv");
  for(int i=0;i<sys.frameNO;i++){
   //sys.startFrm = i;
   YUV_play_read(cur_image_y, cur_image_u, cur_image_v, sys.inFileName, sys.width, sys.height, FrameNum);
   for(int x=0;x<sys.width;x++){
    for(int y=0;y<sys.height;y++){
        a[x + y * 352] = color(cur_image_y[x + y * 352], cur_image_u[x + y * 352], cur_image_v[x + y *   352]);
    }
   }
  }  
  pixels = a;
  AndroidBitmap_unlockPixels(env, bitmapObj);
  bmp.setPixels((void*)pixels);
  canv->drawBitmap(bmp, 0, 0, NULL);

 }
1

There are 1 answers

0
Robin On BEST ANSWER

You need to make sure your are not using hardware rendering, by:

  1. call view.setLayerType(LAYER_TYPE_SOFTWARE, null); or set android:hardwareAccelerated="false" in your application section of your AndroidManifest.xml

  2. Go to the developer options, and uncheck "force GPU rendering"