[frameworks/native] auto-detecting 3d video
This commit is contained in:
@ -1144,7 +1144,7 @@ public:
|
||||
virtual int32_t getAlreadyStereo() const {
|
||||
return getLayer()->alreadyStereo;
|
||||
}
|
||||
|
||||
|
||||
virtual int32_t getDisplayStereo() const {
|
||||
return getLayer()->displayStereo;
|
||||
}
|
||||
|
||||
@ -84,7 +84,6 @@ Layer::Layer(SurfaceFlinger* flinger, const sp<Client>& client,
|
||||
mPotentialCursor(false),
|
||||
mDrawingScreenshot(false),
|
||||
mStereoMode(0)
|
||||
|
||||
{
|
||||
mCurrentCrop.makeInvalid();
|
||||
mFlinger->getRenderEngine().genTextures(1, &mTextureName);
|
||||
@ -765,7 +764,7 @@ void Layer::onDraw(const sp<const DisplayDevice>& hw, const Region& clip,
|
||||
|
||||
|
||||
#ifdef ENABLE_VR
|
||||
void print3dLog(int alreadyStereo, int displayStereo){
|
||||
void Layer::print3dLog(int alreadyStereo, int displayStereo) const {
|
||||
//The other part of 3d log is written in GLES20RenderEngine.
|
||||
char value[PROPERTY_VALUE_MAX];
|
||||
property_get("sys.3d.log", value, "0");
|
||||
@ -830,33 +829,32 @@ void print3dLog(int alreadyStereo, int displayStereo){
|
||||
}
|
||||
}
|
||||
|
||||
void setStereoDraw(const sp<const DisplayDevice>& hw, RenderEngine& engine,
|
||||
Mesh& mMesh, int alreadyStereo, int displayStereo)
|
||||
void Layer::setStereoDraw(const sp<const DisplayDevice>& hw, RenderEngine& engine,
|
||||
Mesh& mMesh, int alreadyStereo, int displayStereo) const
|
||||
{
|
||||
ALOGD("325-djw:%d",alreadyStereo);
|
||||
Mesh::VertexArray<vec2> position(mMesh.getPositionArray<vec2>());
|
||||
Mesh::VertexArray<vec2> texCoords(mMesh.getTexCoordArray<vec2>());
|
||||
|
||||
char value[PROPERTY_VALUE_MAX];
|
||||
property_get("sys.3d.height", value, "0.5");
|
||||
float heightScale = atof(value);
|
||||
property_get("sys.3d.on_off", value, "1");
|
||||
int vrSwitch = atoi(value);
|
||||
|
||||
vec2 margin = vec2(0.0, 0.0);
|
||||
|
||||
// ALOGD("djw:position[0]=(%f,%f)",position[0].x,position[0].y);
|
||||
// ALOGD("djw:position[1]=(%f,%f)",position[1].x,position[1].y);
|
||||
// ALOGD("djw:position[2]=(%f,%f)",position[2].x,position[2].y);
|
||||
// ALOGD("djw:position[3]=(%f,%f)",position[3].x,position[3].y);
|
||||
// ALOGD("layer-djw:position[0]=(%f,%f)",position[0].x,position[0].y);
|
||||
// ALOGD("layer-djw:position[1]=(%f,%f)",position[1].x,position[1].y);
|
||||
// ALOGD("layer-djw:position[2]=(%f,%f)",position[2].x,position[2].y);
|
||||
// ALOGD("layer-djw:position[3]=(%f,%f)",position[3].x,position[3].y);
|
||||
|
||||
// ALOGD("djw:texCoords[0]=[%f,%f]",texCoords[0].x,texCoords[0].y);
|
||||
// ALOGD("djw:texCoords[1]=[%f,%f]",texCoords[1].x,texCoords[1].y);
|
||||
// ALOGD("djw:texCoords[2]=[%f,%f]",texCoords[2].x,texCoords[2].y);
|
||||
// ALOGD("djw:texCoords[3]=[%f,%f]",texCoords[3].x,texCoords[3].y);
|
||||
// ALOGD("layer-djw:texCoords[0]=[%f,%f]",texCoords[0].x,texCoords[0].y);
|
||||
// ALOGD("layer-djw:texCoords[1]=[%f,%f]",texCoords[1].x,texCoords[1].y);
|
||||
// ALOGD("layer-djw:texCoords[2]=[%f,%f]",texCoords[2].x,texCoords[2].y);
|
||||
// ALOGD("layer-djw:texCoords[3]=[%f,%f]",texCoords[3].x,texCoords[3].y);
|
||||
|
||||
/*********displayStereo==1***********/
|
||||
//fake-3d layer
|
||||
if((1==displayStereo && !alreadyStereo) && (1 == vrSwitch)){
|
||||
if((1==displayStereo && !alreadyStereo)){
|
||||
|
||||
position[0].x = position[0].x * 0.5;
|
||||
position[1].x = position[1].x * 0.5;
|
||||
@ -879,7 +877,7 @@ void setStereoDraw(const sp<const DisplayDevice>& hw, RenderEngine& engine,
|
||||
texCoords[3] = vec2(1, 1);
|
||||
|
||||
engine.drawLeftFBO(mMesh);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//real-3d layer
|
||||
@ -914,11 +912,11 @@ void setStereoDraw(const sp<const DisplayDevice>& hw, RenderEngine& engine,
|
||||
texCoords[3] = vec2(1, 1);
|
||||
|
||||
engine.drawLeftFBO(mMesh);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//fake-3d layer which come with real-3D layer,we have set 2 to alreadyStereo before
|
||||
if((1==displayStereo && 2 == alreadyStereo) && (1 == vrSwitch)) {
|
||||
if((1==displayStereo && 2 == alreadyStereo)) {
|
||||
engine.enableRightFBO(true);
|
||||
|
||||
position[0].x = position[0].x * 0.5;
|
||||
@ -943,12 +941,13 @@ void setStereoDraw(const sp<const DisplayDevice>& hw, RenderEngine& engine,
|
||||
|
||||
engine.drawLeftFBO(mMesh);
|
||||
engine.drawRightFBO(mMesh);
|
||||
return;
|
||||
}
|
||||
/*********displayStereo==1 ends***********/
|
||||
|
||||
/*********displayStereo==2***********/
|
||||
//fake-3d layer
|
||||
if((2==displayStereo && !alreadyStereo) && (1 == vrSwitch)) {
|
||||
if((2==displayStereo && !alreadyStereo)) {
|
||||
position[0].y = position[0].y * 0.5;
|
||||
position[1].y = position[1].y * 0.5;
|
||||
position[2].y = position[2].y * 0.5;
|
||||
@ -970,11 +969,11 @@ void setStereoDraw(const sp<const DisplayDevice>& hw, RenderEngine& engine,
|
||||
texCoords[3] = vec2(1, 1);
|
||||
|
||||
engine.drawLeftFBO(mMesh);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//real-3d layer
|
||||
if((2==displayStereo && 1 == alreadyStereo) || (0 == vrSwitch)){
|
||||
if((2==displayStereo && 1 == alreadyStereo)){
|
||||
engine.enableRightFBO(true);
|
||||
|
||||
position[0].y = position[0].y * 0.5;
|
||||
@ -1005,11 +1004,11 @@ void setStereoDraw(const sp<const DisplayDevice>& hw, RenderEngine& engine,
|
||||
texCoords[3] = vec2(1, 1);
|
||||
|
||||
engine.drawLeftFBO(mMesh);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//fake-3d layer which come with real-3D layer,we have set 2 to alreadyStereo before
|
||||
if((2==displayStereo && 2 == alreadyStereo) && (1 == vrSwitch)) {
|
||||
if((2==displayStereo && 2 == alreadyStereo)) {
|
||||
|
||||
engine.enableRightFBO(true);
|
||||
|
||||
@ -1035,9 +1034,10 @@ void setStereoDraw(const sp<const DisplayDevice>& hw, RenderEngine& engine,
|
||||
|
||||
engine.drawLeftFBO(mMesh);
|
||||
engine.drawRightFBO(mMesh);
|
||||
|
||||
return;
|
||||
}
|
||||
/*********displayStereo==2 ends***********/
|
||||
|
||||
/*
|
||||
if(8 == displayStereo){
|
||||
position[0].y /= 2;
|
||||
@ -1140,8 +1140,8 @@ void Layer::drawWithOpenGL(const sp<const DisplayDevice>& hw,
|
||||
int draw_flow = atoi(value);
|
||||
if(draw_flow == 1){
|
||||
setStereoDraw(hw, engine, mMesh,
|
||||
/*mSurfaceFlingerConsumer->getAlreadyStereo()*/getStereoModeToDraw(), displayStereo);
|
||||
mStereoMode = 0;
|
||||
/*getAlreadyStereo(hw,*cur)*/getStereoModeToDraw(),displayStereo);
|
||||
// mStereoMode = 0;
|
||||
}
|
||||
else{
|
||||
engine.drawMesh(mMesh);
|
||||
|
||||
@ -81,11 +81,11 @@ public:
|
||||
// have a stable sort order when their layer stack and Z-order are
|
||||
// the same.
|
||||
int32_t sequence;
|
||||
|
||||
|
||||
int32_t displayStereo;
|
||||
|
||||
mutable int mStereoMode;
|
||||
|
||||
|
||||
enum { // flags for doTransaction()
|
||||
eDontUpdateGeometryState = 0x00000001,
|
||||
eVisibleRegion = 0x00000002,
|
||||
@ -214,7 +214,7 @@ public:
|
||||
HWComposer::HWCLayerInterface& layer);
|
||||
int getStereoModeToDraw()const;
|
||||
void setAlreadyStereo(const sp<const DisplayDevice>& hw,
|
||||
HWComposer::HWCLayerInterface& layer,int flag);
|
||||
HWComposer::HWCLayerInterface& layer,int flag);
|
||||
Rect getPosition(const sp<const DisplayDevice>& hw);
|
||||
|
||||
/*
|
||||
@ -244,6 +244,12 @@ public:
|
||||
void draw(const sp<const DisplayDevice>& hw, bool useIdentityTransform) const;
|
||||
void draw(const sp<const DisplayDevice>& hw) const;
|
||||
|
||||
#ifdef ENABLE_VR
|
||||
bool detect3dVideo() const;
|
||||
void print3dLog(int alreadyStereo, int displayStereo) const;
|
||||
void setStereoDraw(const sp<const DisplayDevice>& hw, RenderEngine& engine,
|
||||
Mesh& mMesh, int alreadyStereo, int displayStereo) const;
|
||||
#endif
|
||||
/*
|
||||
* doTransaction - process the transaction. This is a good place to figure
|
||||
* out which attributes of the surface have changed.
|
||||
|
||||
@ -286,13 +286,19 @@ void GLES11RenderEngine::beginGroup(const mat4& ,int mode) {
|
||||
void GLES11RenderEngine::endGroup(int mode) {
|
||||
// doesn't do anything in GLES 1.1
|
||||
}
|
||||
void GLES11RenderEngine::isVideo3dFormat(int mode){
|
||||
// doesn't do anything in GLES 1.1
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void GLES11RenderEngine::beginGroup(const mat4& /*colorTransform*/) {
|
||||
// doesn't do anything in GLES 1.1
|
||||
}
|
||||
void GLES11RenderEngine::endGroup() {
|
||||
// doesn't do anything in GLES 1.1
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void GLES11RenderEngine::dump(String8& result) {
|
||||
|
||||
@ -69,6 +69,7 @@ protected:
|
||||
virtual void beginGroup(const mat4& colorTransform,int mode);
|
||||
virtual void setTargetDpyXY(int x, int y, int dpyId);
|
||||
virtual void endGroup(int mode);
|
||||
virtual void isVideo3dFormat(int mode);
|
||||
#else
|
||||
virtual void beginGroup(const mat4& colorTransform);
|
||||
virtual void endGroup();
|
||||
|
||||
@ -23,6 +23,11 @@ typedef unsigned char uint8_t;
|
||||
#define Screen_X 1000.0f
|
||||
#define Screen_Y 1000.0f
|
||||
|
||||
//_test_Similarity
|
||||
#define Check_Width 1024/2
|
||||
#define Check_Height 768
|
||||
#define Check_Len 8
|
||||
|
||||
#include <GLES2/gl2.h>
|
||||
#include <GLES2/gl2ext.h>
|
||||
|
||||
@ -53,10 +58,15 @@ GLES20RenderEngine::GLES20RenderEngine() :
|
||||
tname(0),
|
||||
name(0),
|
||||
useRightFBO(false),
|
||||
leftCheck(NULL),
|
||||
rightCheck(NULL),
|
||||
context(NULL)
|
||||
{
|
||||
#ifdef ENABLE_VR
|
||||
initVRInfoTable();
|
||||
//test similarity
|
||||
leftCheck = new uint32_t[Check_Width*Check_Height];
|
||||
rightCheck = new uint32_t[Check_Width*Check_Height];
|
||||
#endif
|
||||
|
||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
|
||||
@ -280,6 +290,8 @@ void GLES20RenderEngine::initVRInfoTable(){
|
||||
|
||||
mVR.fboWidth[dpy]=0;
|
||||
mVR.fboHeight[dpy]=0;
|
||||
|
||||
testCount=0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -737,6 +749,7 @@ void GLES20RenderEngine::beginGroup(const mat4& colorTransform,int mode) {
|
||||
for(int dpyId=0;dpyId<DISPLAY_NUM;dpyId++){
|
||||
createFBO(dpyId);
|
||||
}
|
||||
_test_CreateCheckFBO();
|
||||
}
|
||||
|
||||
if(checkVRPropertyChanged()){
|
||||
@ -866,8 +879,395 @@ void GLES20RenderEngine::endGroup(int mode) {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
char value[PROPERTY_VALUE_MAX];
|
||||
property_get("sys.3d.3dvideo", value, "0");
|
||||
int temp = atoi(value);
|
||||
ALOGD("322-djw:sys.3d.3dvideo=%d",temp);
|
||||
}
|
||||
|
||||
void GLES20RenderEngine::isVideo3dFormat(int mode){
|
||||
bool skip = false;
|
||||
float total = 0.0;
|
||||
|
||||
if(mVR.dpyId==1){
|
||||
ALOGD("322-djw:1come here!");
|
||||
return;
|
||||
}
|
||||
|
||||
if(mode==-1){
|
||||
testCount=0;
|
||||
for(int i=0;i<10;i++){
|
||||
score_list[i]=0.0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if(testCount%DETECT_3D_RATE==0){
|
||||
score_list[testCount/DETECT_3D_RATE] = _test_Similarity();
|
||||
if(score_list[testCount/DETECT_3D_RATE]==-1){
|
||||
ALOGD("score-djw: skip!!!");
|
||||
testCount=0;
|
||||
for(int i=0;i<10;i++){
|
||||
score_list[i]=0.0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
testCount++;
|
||||
|
||||
if(testCount>=10*DETECT_3D_RATE){
|
||||
testCount=0;
|
||||
for(int i=0;i<10;i++){
|
||||
total += score_list[i];
|
||||
}
|
||||
score=total/10.0;
|
||||
ALOGD("score-djw:3d_score = %f",score);
|
||||
if(score>0.6){
|
||||
property_set("sys.3d.3dvideo","1");
|
||||
}else{
|
||||
property_set("sys.3d.3dvideo","0");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GLES20RenderEngine::_test_CreateCheckFBO(){
|
||||
int w = mVR.MeshData[0].last_x * 0.25;
|
||||
int h = mVR.MeshData[0].last_y * 0.5;
|
||||
|
||||
for(int i=0;i<=ZOOM_OUT_LEVEL;i++){
|
||||
if(i==ZOOM_OUT_LEVEL){
|
||||
w = 8;
|
||||
h = 8;
|
||||
}
|
||||
ALOGD("fbo-djw: w=%d, h=%d",w,h);
|
||||
|
||||
_test_simi.fboWidth[i] = w;
|
||||
_test_simi.fboHeight[i] = h;
|
||||
|
||||
glGenTextures(1, &_test_simi.checkLeftTex[i]);
|
||||
glBindTexture(GL_TEXTURE_2D, _test_simi.checkLeftTex[i]);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE,0);
|
||||
glGenFramebuffers(1, &_test_simi.checkLeftFBO[i]);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _test_simi.checkLeftFBO[i]);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _test_simi.checkLeftTex[i], 0);
|
||||
|
||||
glGenTextures(1, &_test_simi.checkRightTex[i]);
|
||||
glBindTexture(GL_TEXTURE_2D, _test_simi.checkRightTex[i]);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE,0);
|
||||
glGenFramebuffers(1, &_test_simi.checkRightFBO[i]);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _test_simi.checkRightFBO[i]);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _test_simi.checkRightTex[i], 0);
|
||||
|
||||
w = w/2;
|
||||
h = h/2;
|
||||
}
|
||||
}
|
||||
|
||||
float GLES20RenderEngine::_test_Similarity(){
|
||||
Mesh mesh(Mesh::TRIANGLE_FAN, 4, 2, 2);
|
||||
Mesh::VertexArray<vec2> position(mesh.getPositionArray<vec2>());
|
||||
Mesh::VertexArray<vec2> texCoord(mesh.getTexCoordArray<vec2>());
|
||||
|
||||
char value[PROPERTY_VALUE_MAX];
|
||||
property_get("sys.3d.3dvideo", value, "0");
|
||||
int temp = atoi(value);
|
||||
|
||||
if(temp){
|
||||
position[0] = vec2(0, 0);
|
||||
position[1] = vec2(Check_Width, 0);
|
||||
position[2] = vec2(Check_Width, Check_Height);
|
||||
position[3] = vec2(0, Check_Height);
|
||||
texCoord[0] = vec2(0, 0);
|
||||
texCoord[1] = vec2(1, 0);
|
||||
texCoord[2] = vec2(1, 1);
|
||||
texCoord[3] = vec2(0, 1);
|
||||
_test_drawMeshLeftCheckFBO(mesh,0,1);
|
||||
_test_drawMeshRightCheckFBO(mesh,0,1);
|
||||
}else{
|
||||
position[0] = vec2(0, 0);
|
||||
position[1] = vec2(Check_Width, 0);
|
||||
position[2] = vec2(Check_Width, Check_Height);
|
||||
position[3] = vec2(0, Check_Height);
|
||||
texCoord[0] = vec2(0, 0);
|
||||
texCoord[1] = vec2(1, 0);
|
||||
texCoord[2] = vec2(1, 0.5);
|
||||
texCoord[3] = vec2(0, 0.5);
|
||||
_test_drawMeshLeftCheckFBO(mesh,0,0);
|
||||
texCoord[0] = vec2(0, 0.5);
|
||||
texCoord[1] = vec2(1, 0.5);
|
||||
texCoord[2] = vec2(1, 1);
|
||||
texCoord[3] = vec2(0, 1);
|
||||
_test_drawMeshRightCheckFBO(mesh,0,0);
|
||||
}
|
||||
|
||||
for(int i=1;i<=ZOOM_OUT_LEVEL;i++){
|
||||
position[0] = vec2(0, 0);
|
||||
position[1] = vec2(_test_simi.fboWidth[i], 0);
|
||||
position[2] = vec2(_test_simi.fboWidth[i], _test_simi.fboHeight[i]);
|
||||
position[3] = vec2(0, _test_simi.fboHeight[i]);
|
||||
texCoord[0] = vec2(0, 0);
|
||||
texCoord[1] = vec2(1, 0);
|
||||
texCoord[2] = vec2(1, 1);
|
||||
texCoord[3] = vec2(0, 1);
|
||||
_test_drawMeshLeftCheckFBO(mesh,i,0);
|
||||
_test_drawMeshRightCheckFBO(mesh,i,0);
|
||||
}
|
||||
|
||||
return _test_isSimilaryImages(leftCheck,rightCheck);
|
||||
|
||||
}
|
||||
|
||||
|
||||
float GLES20RenderEngine::_test_isSimilaryImages(const uint32_t* frame1, const uint32_t * frame2){
|
||||
float temp = 0;
|
||||
uint8_t greyValue = 0;
|
||||
uint8_t *p1 = (uint8_t *)frame1;
|
||||
uint8_t *p2 = (uint8_t *)frame2;
|
||||
uint8_t *grey1 = new uint8_t[Check_Len*Check_Len];
|
||||
uint8_t *grey2 = new uint8_t[Check_Len*Check_Len];
|
||||
bool *fingerPrint1 = new bool[(Check_Len-1)*Check_Len];
|
||||
bool *fingerPrint2 = new bool[(Check_Len-1)*Check_Len];
|
||||
bool *resultMap = new bool[(Check_Len-1)*Check_Len];
|
||||
int resultNum = 0;
|
||||
uint8_t greyTotal = 0;
|
||||
|
||||
//transform image to grep scale
|
||||
for(int i=0;i<(Check_Len*Check_Len);i++){
|
||||
temp = 0.2989*(*p1) + 0.5870*(*(p1+1)) + 0.1140*(*(p1+2));
|
||||
greyValue = (int8_t)temp;
|
||||
*(grey1+i) = greyValue;
|
||||
|
||||
temp = 0.2989*(*p2) + 0.5870*(*(p2+1)) + 0.1140*(*(p2+2));
|
||||
greyValue = (int8_t)temp;
|
||||
*(grey2+i) = greyValue;
|
||||
|
||||
ALOGD("simi:greyValue =%d",greyValue);
|
||||
ALOGD("simi:%d,%d,%d",*p2,*(p2+1),*(p2+2));
|
||||
|
||||
p1 = p1 + 4;
|
||||
p2 = p2 + 4;
|
||||
greyTotal += *(grey1+i);
|
||||
}
|
||||
|
||||
//skip black or white frame
|
||||
float greyAverage = (float)greyTotal/(Check_Len*Check_Len);
|
||||
float greyVariance = 0;
|
||||
for(int i=0;i<(Check_Len*Check_Len);i++){
|
||||
greyVariance += ((float)*(grey1+i)-greyAverage);
|
||||
}
|
||||
if(greyVariance < 20.0)
|
||||
return -1.0;
|
||||
|
||||
//draw fingerPrint map
|
||||
for(int i=0;i<Check_Len;i++)
|
||||
for(int j=1;j<Check_Len;j++){
|
||||
if ((*(grey1+i*Check_Len+j)) > (*(grey1+i*Check_Len+j-1)))
|
||||
*(fingerPrint1+i*(Check_Len-1)+j-1) = true;
|
||||
else
|
||||
*(fingerPrint1+i*(Check_Len-1)+j-1) = false;
|
||||
|
||||
if ((*(grey2+i*Check_Len+j)) > (*(grey2+i*Check_Len+j-1)))
|
||||
*(fingerPrint2+i*(Check_Len-1)+j-1) = true;
|
||||
else
|
||||
*(fingerPrint2+i*(Check_Len-1)+j-1) = false;
|
||||
}
|
||||
|
||||
//compare two fingerPrint
|
||||
for(int i=0;i<((Check_Len-1)*Check_Len);i++){
|
||||
if((*(fingerPrint1+i)) != (*(fingerPrint2+i))){
|
||||
*(resultMap+i) = true;
|
||||
}else{
|
||||
*(resultMap+i) = false;
|
||||
}
|
||||
}
|
||||
|
||||
//add weight value when "true zone" is connected
|
||||
for(int i=0;i<((Check_Len-1)*Check_Len);i++){
|
||||
int weight = 0;
|
||||
if((*(resultMap+i))==true){
|
||||
weight=1;
|
||||
bool toleft=false,toright=false,toup=false,todown=false;
|
||||
if(i%(Check_Len-1) - 1 >= 0) toleft = *(resultMap+i-1);
|
||||
if(i%(Check_Len-1) + 1 <= (Check_Len-1)) toright = *(resultMap+i+1);
|
||||
if((i+1)/Check_Len - 1 >= 0) toup = *(resultMap+i-(Check_Len-1));
|
||||
if((i+1)/Check_Len + 1 <= Check_Len) todown = *(resultMap+i+(Check_Len-1));
|
||||
|
||||
if((toleft==true)||(toright==true)||(toup==true)||(todown==true))
|
||||
weight = 3;
|
||||
}
|
||||
resultNum = resultNum + weight;
|
||||
}
|
||||
|
||||
float similarRatio = 1.0-((float)resultNum/(float)(Check_Len*Check_Len));
|
||||
if(similarRatio < 0)
|
||||
similarRatio = 0;
|
||||
|
||||
ALOGD("result-djw: diff dot =%d",(int)resultNum);
|
||||
ALOGD("result-djw: simi ratio =%f",similarRatio);
|
||||
|
||||
// if(similarRatio>0.8){
|
||||
// return true;
|
||||
// }else{
|
||||
// return false;
|
||||
// }
|
||||
return similarRatio;
|
||||
}
|
||||
|
||||
void GLES20RenderEngine::_test_drawMeshLeftCheckFBO(const Mesh& mesh, int fboId, int mode) {
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _test_simi.checkLeftFBO[fboId]);
|
||||
|
||||
GLuint texId;
|
||||
if(fboId==0){
|
||||
texId = mVR.leftTex[mVR.dpyId];
|
||||
}else{
|
||||
texId = _test_simi.checkLeftTex[fboId-1];
|
||||
}
|
||||
|
||||
// Texture LeftTexture(Texture::TEXTURE_2D, mVR.leftTex[0]);
|
||||
Texture LeftTexture(Texture::TEXTURE_2D, texId);
|
||||
// LeftTexture.setDimensions(_test_simi.fboWidth, _test_simi.fboHeight);
|
||||
|
||||
// glBindTexture(GL_TEXTURE_2D, mVR.leftTex[0]);
|
||||
glBindTexture(GL_TEXTURE_2D, texId);
|
||||
|
||||
mState.setTexture(LeftTexture);
|
||||
|
||||
ProgramCache::getInstance().useProgram(mState);
|
||||
|
||||
if (mesh.getTexCoordsSize()) {
|
||||
glEnableVertexAttribArray(Program::texCoords);
|
||||
glVertexAttribPointer(Program::texCoords,
|
||||
mesh.getTexCoordsSize(),
|
||||
GL_FLOAT, GL_FALSE,
|
||||
mesh.getByteStride(),
|
||||
mesh.getTexCoords());
|
||||
}
|
||||
|
||||
glVertexAttribPointer(Program::position,
|
||||
mesh.getVertexSize(),
|
||||
GL_FLOAT, GL_FALSE,
|
||||
mesh.getByteStride(),
|
||||
mesh.getPositions());
|
||||
|
||||
glDrawArrays(mesh.getPrimitive(), 0, mesh.getVertexCount());
|
||||
|
||||
if (mesh.getTexCoordsSize()) {
|
||||
glDisableVertexAttribArray(Program::texCoords);
|
||||
}
|
||||
glFinish();
|
||||
glFlush();
|
||||
|
||||
//glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
//glBindFramebuffer(GL_FRAMEBUFFER, _test_simi.leftFbo);
|
||||
//glBindTexture(GL_TEXTURE_2D, _test_simi.checkLeftTex);
|
||||
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 384,512, 0, GL_RGBA, GL_UNSIGNED_BYTE,0);
|
||||
//glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, _test_simi.fboWidth, _test_simi.fboHeight/2, 0);
|
||||
|
||||
#if 1
|
||||
char value[PROPERTY_VALUE_MAX];
|
||||
property_get("sys.3d.dump", value, "4");
|
||||
float dumpId = atoi(value);
|
||||
if(fboId==dumpId){
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _test_simi.checkLeftFBO[fboId]);
|
||||
glReadPixels(0, 0, _test_simi.fboWidth[fboId], _test_simi.fboHeight[fboId], GL_RGBA, GL_UNSIGNED_BYTE, leftCheck);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
// int n = _test_simi.fboWidth[fboId] * _test_simi.fboHeight[fboId] * 4;
|
||||
// FILE *fp1;
|
||||
// if ((fp1 = fopen("data/1.bin", "w+")) == NULL)
|
||||
// {
|
||||
// ALOGD("haha: can't open 1.bin!!!!!");
|
||||
// //return 1;
|
||||
// }
|
||||
// fwrite(leftCheck, n, 1, fp1);
|
||||
// fclose(fp1);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void GLES20RenderEngine::_test_drawMeshRightCheckFBO(const Mesh& mesh, int fboId, int mode) {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _test_simi.checkRightFBO[fboId]);
|
||||
|
||||
GLuint texId;
|
||||
if(fboId==0 && mode==0){
|
||||
texId = mVR.leftTex[mVR.dpyId];
|
||||
}else if(fboId==0 && mode==1){
|
||||
texId = mVR.rightTex[mVR.dpyId];
|
||||
}else{
|
||||
texId = _test_simi.checkRightTex[fboId-1];
|
||||
}
|
||||
|
||||
// Texture LeftTexture(Texture::TEXTURE_2D, mVR.leftTex[0]);
|
||||
Texture LeftTexture(Texture::TEXTURE_2D, texId);
|
||||
// LeftTexture.setDimensions(_test_simi.fboWidth, _test_simi.fboHeight);
|
||||
|
||||
// glBindTexture(GL_TEXTURE_2D, mVR.leftTex[0]);
|
||||
glBindTexture(GL_TEXTURE_2D, texId);
|
||||
|
||||
mState.setTexture(LeftTexture);
|
||||
|
||||
ProgramCache::getInstance().useProgram(mState);
|
||||
|
||||
if (mesh.getTexCoordsSize()) {
|
||||
glEnableVertexAttribArray(Program::texCoords);
|
||||
glVertexAttribPointer(Program::texCoords,
|
||||
mesh.getTexCoordsSize(),
|
||||
GL_FLOAT, GL_FALSE,
|
||||
mesh.getByteStride(),
|
||||
mesh.getTexCoords());
|
||||
}
|
||||
|
||||
glVertexAttribPointer(Program::position,
|
||||
mesh.getVertexSize(),
|
||||
GL_FLOAT, GL_FALSE,
|
||||
mesh.getByteStride(),
|
||||
mesh.getPositions());
|
||||
|
||||
glDrawArrays(mesh.getPrimitive(), 0, mesh.getVertexCount());
|
||||
|
||||
if (mesh.getTexCoordsSize()) {
|
||||
glDisableVertexAttribArray(Program::texCoords);
|
||||
}
|
||||
|
||||
glFinish();
|
||||
glFlush();
|
||||
|
||||
#if 1
|
||||
char value[PROPERTY_VALUE_MAX];
|
||||
property_get("sys.3d.dump", value, "4");
|
||||
float dumpId = atoi(value);
|
||||
if(fboId==dumpId){
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _test_simi.checkRightFBO[fboId]);
|
||||
glReadPixels(0, 0, _test_simi.fboWidth[fboId], _test_simi.fboHeight[fboId], GL_RGBA, GL_UNSIGNED_BYTE, rightCheck);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
// int n = _test_simi.fboWidth[fboId] * _test_simi.fboHeight[fboId] * 4;
|
||||
// FILE *fp1;
|
||||
// if ((fp1 = fopen("data/2.bin", "w+")) == NULL)
|
||||
// {
|
||||
// ALOGD("haha: can't open 2.bin!!!!!");
|
||||
// //return 1;
|
||||
// }
|
||||
// fwrite(rightCheck, n, 1, fp1);
|
||||
// fclose(fp1);
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
void GLES20RenderEngine::beginGroup(const mat4& colorTransform) {
|
||||
|
||||
@ -32,9 +32,13 @@ typedef unsigned int uint32_t;
|
||||
#include "ProgramCache.h"
|
||||
#include "Description.h"
|
||||
|
||||
#include <ctime>
|
||||
|
||||
#define LEFT 1
|
||||
#define RIGHT 2
|
||||
#define DISPLAY_NUM 2
|
||||
#define ZOOM_OUT_LEVEL 4
|
||||
#define DETECT_3D_RATE 10
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
namespace android {
|
||||
@ -78,9 +82,26 @@ class GLES20RenderEngine : public RenderEngine {
|
||||
|
||||
GLuint fboWidth[DISPLAY_NUM];
|
||||
GLuint fboHeight[DISPLAY_NUM];
|
||||
|
||||
} mVR;
|
||||
|
||||
//add for similarity check
|
||||
struct VRSimilarity{
|
||||
GLuint checkLeftFBO[ZOOM_OUT_LEVEL+1];
|
||||
GLuint checkRightFBO[ZOOM_OUT_LEVEL+1];
|
||||
GLuint checkLeftTex[ZOOM_OUT_LEVEL+1];
|
||||
GLuint checkRightTex[ZOOM_OUT_LEVEL+1];
|
||||
GLuint fboWidth[ZOOM_OUT_LEVEL+1];
|
||||
GLuint fboHeight[ZOOM_OUT_LEVEL+1];
|
||||
} _test_simi;
|
||||
|
||||
float score_list[10];
|
||||
float score;
|
||||
uint32_t testCount;
|
||||
clock_t start,stop,diff;
|
||||
uint32_t * leftCheck;
|
||||
uint32_t * rightCheck;
|
||||
//add end
|
||||
|
||||
struct Group {
|
||||
GLuint texture;
|
||||
GLuint fbo;
|
||||
@ -133,7 +154,12 @@ protected:
|
||||
virtual void updateFBOSize(int dpyId);
|
||||
virtual void beginGroup(const mat4& colorTransform,int mode);
|
||||
virtual void endGroup(int mode);
|
||||
|
||||
virtual void isVideo3dFormat(int mode);
|
||||
virtual void _test_CreateCheckFBO();
|
||||
virtual float _test_Similarity();
|
||||
virtual float _test_isSimilaryImages(const uint32_t* frame1,const uint32_t * frame2);
|
||||
virtual void _test_drawMeshLeftCheckFBO(const Mesh& mesh, int fboId, int mode);
|
||||
virtual void _test_drawMeshRightCheckFBO(const Mesh& mesh, int fboId, int mode);
|
||||
#else
|
||||
virtual void beginGroup(const mat4& colorTransform);
|
||||
virtual void endGroup();
|
||||
|
||||
@ -114,6 +114,7 @@ public:
|
||||
virtual void setTargetDpyXY(int x, int y, int dpyId) = 0;
|
||||
virtual void beginGroup(const mat4& colorTransform,int mode) = 0;
|
||||
virtual void endGroup(int mode) = 0;
|
||||
virtual void isVideo3dFormat(int mode) = 0;
|
||||
#else
|
||||
virtual void beginGroup(const mat4& colorTransform) = 0;
|
||||
virtual void endGroup() = 0;
|
||||
|
||||
@ -212,6 +212,7 @@ SurfaceFlinger::SurfaceFlinger()
|
||||
property_set("sys.ggsurflgr.version", RK_SURFLGR_VERSION);
|
||||
#ifdef ENABLE_VR
|
||||
m3dEnabled = false;
|
||||
hasVideoLayer = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -1248,10 +1249,16 @@ void SurfaceFlinger::setUpHWComposer() {
|
||||
|
||||
#ifdef ENABLE_VR
|
||||
//djw:add for 3d functions
|
||||
char value[PROPERTY_VALUE_MAX];
|
||||
property_get("sys.3d.autodetect", value, "1");
|
||||
int autodetect = atoi(value);
|
||||
bool has3dVideoLayer = false;
|
||||
bool hasStereoLayer = false;
|
||||
hasVideoLayer = false;
|
||||
for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
|
||||
sp<const DisplayDevice> hw(mDisplays[0]);
|
||||
sp<const DisplayDevice> hw(mDisplays[dpy]);
|
||||
const int32_t id = hw->getHwcDisplayId();
|
||||
ALOGD("323-djw: id =%d",id);
|
||||
if (id >= 0) {
|
||||
const Vector< sp<Layer> >& currentLayers(
|
||||
hw->getVisibleLayersSortedByZ());
|
||||
@ -1260,17 +1267,59 @@ void SurfaceFlinger::setUpHWComposer() {
|
||||
const HWComposer::LayerListIterator end = hwc.end(id);
|
||||
for (size_t i=0 ; cur!=end && i<count ; ++i, ++cur) {
|
||||
const sp<Layer>& layer(currentLayers[i]);
|
||||
//add for auto detect 3d video
|
||||
if(autodetect){
|
||||
int32_t format = -1;
|
||||
const sp<GraphicBuffer>& buffer(layer->getActiveBuffer());
|
||||
if (buffer != NULL) {
|
||||
format = buffer->getPixelFormat();
|
||||
}
|
||||
switch(format){
|
||||
case 0x10: //HAL_PIXEL_FORMAT_YCbCr_422_SP NV16
|
||||
case 0x11: //HAL_PIXEL_FORMAT_YCrCb_420_SP NV21
|
||||
case 0x14: //HAL_PIXEL_FORMAT_YCbCr_422_I YUY2
|
||||
case 0x15: //HAL_PIXEL_FORMAT_YCrCb_NV12 YUY2
|
||||
case 0x16: //HAL_PIXEL_FORMAT_YCrCb_NV12_VIDEO
|
||||
case 0x17: //HAL_PIXEL_FORMAT_YCrCb_NV12_10 YUY2_1obit
|
||||
case 0x18: //HAL_PIXEL_FORMAT_YCbCr_422_SP_10
|
||||
case 0x19: //HAL_PIXEL_FORMAT_YCrCb_420_SP_10
|
||||
{
|
||||
hasVideoLayer = true;
|
||||
char value[PROPERTY_VALUE_MAX];
|
||||
property_get("sys.3d.3dvideo", value, "0");
|
||||
int temp = atoi(value);
|
||||
if(temp){
|
||||
// ALOGD("322-djw:0come here!");
|
||||
layer->setAlreadyStereo(hw, *cur,1);
|
||||
has3dVideoLayer = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (layer->getAlreadyStereo(hw, *cur)) {
|
||||
hasStereoLayer = true;
|
||||
ALOGD("djw1:layer alreadyStereo is = %d",layer->getAlreadyStereo(hw, *cur));
|
||||
break;
|
||||
// ALOGD("djw1:layer alreadyStereo is = %d",layer->getAlreadyStereo(hw, *cur));
|
||||
// break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(!hasVideoLayer){
|
||||
property_set("sys.3d.3dvideo","0");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if(hasStereoLayer){
|
||||
|
||||
if(hasStereoLayer || has3dVideoLayer){
|
||||
for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
|
||||
sp<const DisplayDevice> hw(mDisplays[0]);
|
||||
sp<const DisplayDevice> hw(mDisplays[dpy]);
|
||||
const int32_t id = hw->getHwcDisplayId();
|
||||
if (id >= 0) {
|
||||
const Vector< sp<Layer> >& currentLayers(
|
||||
@ -1280,14 +1329,33 @@ void SurfaceFlinger::setUpHWComposer() {
|
||||
const HWComposer::LayerListIterator end = hwc.end(id);
|
||||
for (size_t i=0 ; cur!=end && i<count ; ++i, ++cur) {
|
||||
const sp<Layer>& layer(currentLayers[i]);
|
||||
//layer->setAlreadyStereo(1);
|
||||
if(1 != layer->getAlreadyStereo(hw, *cur)){
|
||||
// ALOGD("324-djw: how many times this place can be run?");
|
||||
layer->setAlreadyStereo(hw, *cur,2);
|
||||
ALOGD("djw2:layer alreadyStereo is = %d",layer->getAlreadyStereo(hw, *cur));
|
||||
// ALOGD("djw2:layer alreadyStereo is = %d",layer->getAlreadyStereo(hw, *cur));
|
||||
}else{
|
||||
layer->setAlreadyStereo(hw, *cur,1);
|
||||
}
|
||||
}
|
||||
ALOGD("400-djw:%d",layer->getAlreadyStereo(hw, *cur));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
|
||||
sp<const DisplayDevice> hw(mDisplays[dpy]);
|
||||
const int32_t id = hw->getHwcDisplayId();
|
||||
if (id >= 0) {
|
||||
const Vector< sp<Layer> >& currentLayers(
|
||||
hw->getVisibleLayersSortedByZ());
|
||||
const size_t count = currentLayers.size();
|
||||
HWComposer::LayerListIterator cur = hwc.begin(id);
|
||||
const HWComposer::LayerListIterator end = hwc.end(id);
|
||||
for (size_t i=0 ; cur!=end && i<count ; ++i, ++cur) {
|
||||
const sp<Layer>& layer(currentLayers[i]);
|
||||
layer->setAlreadyStereo(hw, *cur,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2068,6 +2136,7 @@ void SurfaceFlinger::doDisplayComposition(const sp<const DisplayDevice>& hw,
|
||||
property_set("sys.hwc.compose_policy","6");
|
||||
property_set("sys.game.3d","0");
|
||||
}
|
||||
|
||||
if (CC_LIKELY(!mDaltonize && !mHasColorMatrix)) {
|
||||
if(m3dEnabled)
|
||||
{
|
||||
@ -2097,12 +2166,14 @@ void SurfaceFlinger::doDisplayComposition(const sp<const DisplayDevice>& hw,
|
||||
}
|
||||
engine.setTargetDpyXY(hw_w, hw_h, dpyType);
|
||||
engine.beginGroup(colorMatrix,ShadeMode);
|
||||
//engine.beginGroup(colorMatrix);
|
||||
//if (!doComposeSurfaces(hw, dirtyRegion))
|
||||
// return;
|
||||
doComposeSurfaces(hw, dirtyRegion);
|
||||
//engine.endGroup();
|
||||
engine.endGroup(ShadeMode);
|
||||
if(hasVideoLayer){
|
||||
engine.isVideo3dFormat(0);
|
||||
}else{
|
||||
//clear out the score_list
|
||||
engine.isVideo3dFormat(-1);
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (CC_LIKELY(!mDaltonize && !mHasColorMatrix)) {
|
||||
|
||||
@ -540,6 +540,7 @@ private:
|
||||
bool mDaltonize;
|
||||
#ifdef ENABLE_VR
|
||||
bool m3dEnabled;
|
||||
bool hasVideoLayer;
|
||||
#endif
|
||||
int mDebugFPS;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user