Pixel diff logic for frame rate improvment now working.
authorsl
Fri, 30 May 2014 10:56:20 +0200
changeset 20cd6d76b9b47e
parent 19 be04ffbb561c
child 21 434d6b8a406d
Pixel diff logic for frame rate improvment now working.
It's still working on a per pixels bases so too slow with full screen update.
Thus it's still disabled.
MiniDisplay/FutabaVfd.cpp
MiniDisplay/FutabaVfd.h
     1.1 --- a/MiniDisplay/FutabaVfd.cpp	Thu May 29 21:42:07 2014 +0200
     1.2 +++ b/MiniDisplay/FutabaVfd.cpp	Fri May 30 10:56:20 2014 +0200
     1.3 @@ -74,11 +74,13 @@
     1.4  GP1212A01A::GP1212A01A():
     1.5  	iDisplayPositionX(0),iDisplayPositionY(0),
     1.6      iOffScreenMode(true),
     1.7 +    iFrameNext(NULL),
     1.8 +    iFrameCurrent(NULL),
     1.9 +    iFramePrevious(NULL),
    1.10      iFrameAlpha(NULL),
    1.11      iFrameBeta(NULL),
    1.12 -    iCurrentFrame(NULL),
    1.13 -    iNextFrame(NULL),
    1.14 -    iNeedFullFrameUpdate(true),
    1.15 +    iFrameGamma(NULL),
    1.16 +    iNeedFullFrameUpdate(0),
    1.17      iRequest(ERequestNone),iPowerOn(false)
    1.18  	{
    1.19  	//ResetBuffers();
    1.20 @@ -94,10 +96,14 @@
    1.21      delete iFrameBeta;
    1.22      iFrameBeta=NULL;
    1.23      //
    1.24 -    iNextFrame=NULL;
    1.25 -    iCurrentFrame=NULL;
    1.26 +    delete iFrameGamma;
    1.27 +    iFrameGamma=NULL;
    1.28      //
    1.29 -    iNeedFullFrameUpdate=true;
    1.30 +    iFrameNext=NULL;
    1.31 +    iFrameCurrent=NULL;
    1.32 +    iFramePrevious=NULL;
    1.33 +    //
    1.34 +    iNeedFullFrameUpdate=0;
    1.35  	}
    1.36  
    1.37  /**
    1.38 @@ -116,10 +122,17 @@
    1.39          iFrameBeta=NULL;
    1.40          iFrameBeta=new BitArray(KGP12xFrameBufferPixelCount);
    1.41          //
    1.42 -        iCurrentFrame=iFrameAlpha;
    1.43 -        iNextFrame=iFrameBeta;
    1.44 +        delete iFrameGamma;
    1.45 +        iFrameGamma=NULL;
    1.46 +        iFrameGamma=new BitArray(KGP12xFrameBufferPixelCount);
    1.47 +        //
    1.48 +        iFrameNext=iFrameAlpha;
    1.49 +        iFrameCurrent=iFrameBeta;
    1.50 +        iFramePrevious=iFrameGamma;
    1.51 +
    1.52 +
    1.53          //To make sure it is synced properly
    1.54 -        iNeedFullFrameUpdate=true;
    1.55 +        iNeedFullFrameUpdate=0;
    1.56          //
    1.57  		SetNonBlocking(1);
    1.58          //Since we can't get our display position we force it to our default
    1.59 @@ -143,11 +156,11 @@
    1.60          {
    1.61          if (aOn)
    1.62              {
    1.63 -            iNextFrame->SetBit(aX*HeightInPixels()+aY);
    1.64 +            iFrameNext->SetBit(aX*HeightInPixels()+aY);
    1.65              }
    1.66          else
    1.67              {
    1.68 -            iNextFrame->ClearBit(aX*HeightInPixels()+aY);
    1.69 +            iFrameNext->ClearBit(aX*HeightInPixels()+aY);
    1.70              }
    1.71          }
    1.72      else
    1.73 @@ -166,12 +179,29 @@
    1.74  		{
    1.75  		for (int j=0;j<aSrcHeight;j++)
    1.76  			{
    1.77 -            iNextFrame->SetBitValue((aTargetX+i)*HeightInPixels()+aTargetY+j,aBitmap[+i*aSrcHeight+j]);
    1.78 +            iFrameNext->SetBitValue((aTargetX+i)*HeightInPixels()+aTargetY+j,aBitmap[+i*aSrcHeight+j]);
    1.79  			}
    1.80  		}
    1.81  	}
    1.82  
    1.83  /**
    1.84 +Clear our client side back buffer.
    1.85 +Call to SwapBuffers must follow to actually clear the display.
    1.86 +*/
    1.87 +void GP1212A01A::Clear()
    1.88 +    {
    1.89 +    //memset(iNextFrame->Ptr(),0x00,FrameBufferSizeInBytes());
    1.90 +    if (iOffScreenMode)
    1.91 +        {
    1.92 +        iFrameNext->ClearAll();
    1.93 +        }
    1.94 +    else
    1.95 +        {
    1.96 +        SendClearCommand();
    1.97 +        }
    1.98 +    }
    1.99 +
   1.100 +/**
   1.101  Set all pixels on our screen to the desired value.
   1.102  This operation is performed off screen to avoid tearing.
   1.103  @param 8 pixels pattern
   1.104 @@ -186,7 +216,7 @@
   1.105  
   1.106      if (iOffScreenMode)
   1.107          {
   1.108 -        memset(iNextFrame->Ptr(),aPattern,FrameBufferSizeInBytes());
   1.109 +        memset(iFrameNext->Ptr(),aPattern,FrameBufferSizeInBytes());
   1.110          }
   1.111      else
   1.112          {
   1.113 @@ -277,24 +307,6 @@
   1.114          }
   1.115      }
   1.116  
   1.117 -
   1.118 -/**
   1.119 -Clear our client side back buffer.
   1.120 -Call to SwapBuffers must follow to actually clear the display.
   1.121 -*/
   1.122 -void GP1212A01A::Clear()
   1.123 -	{
   1.124 -    //memset(iNextFrame->Ptr(),0x00,FrameBufferSizeInBytes());
   1.125 -    if (iOffScreenMode)
   1.126 -        {
   1.127 -        iNextFrame->ClearAll();
   1.128 -        }
   1.129 -    else
   1.130 -        {
   1.131 -        SendClearCommand();
   1.132 -        }
   1.133 -	}
   1.134 -
   1.135  /**
   1.136  Using this function is advised against as is causes tearing.
   1.137  Use Clear instead.
   1.138 @@ -363,11 +375,11 @@
   1.139  	if (OffScreenMode())
   1.140  		{
   1.141  		//Send host back buffer to device back buffer
   1.142 -        if (iNeedFullFrameUpdate)
   1.143 +        if (iNeedFullFrameUpdate<3)
   1.144              {
   1.145              //TODO: enable this once SendModifiedPixelBlocks works
   1.146 -            //iNeedFullFrameUpdate=false;
   1.147 -            SetPixelBlock(0,0,63,FrameBufferSizeInBytes(),iNextFrame->Ptr());
   1.148 +            //iNeedFullFrameUpdate++;
   1.149 +            SetPixelBlock(0,0,63,FrameBufferSizeInBytes(),iFrameNext->Ptr());
   1.150              }
   1.151          else
   1.152              {
   1.153 @@ -376,9 +388,14 @@
   1.154  		//Swap device front and back buffer
   1.155  		SetDisplayPosition(iDisplayPositionX,OffScreenY());
   1.156  		//Swap host buffers
   1.157 -        BitArray* nextFrame=iCurrentFrame;
   1.158 -        iCurrentFrame = iNextFrame;
   1.159 -        iNextFrame = nextFrame;
   1.160 +        //BitArray* nextFrame=iFrameNext;
   1.161 +        //iFrameCurrent = iFramePrevious;
   1.162 +        //iFrameNext = iFramePrevious;
   1.163 +
   1.164 +        BitArray* previousFrame=iFramePrevious;
   1.165 +        iFramePrevious = iFrameCurrent;
   1.166 +        iFrameCurrent = iFrameNext;
   1.167 +        iFrameNext = previousFrame;
   1.168  		}
   1.169  	}
   1.170  
   1.171 @@ -398,14 +415,34 @@
   1.172      int h=HeightInPixels();
   1.173  
   1.174      BitArray block(16*16);
   1.175 +
   1.176 +
   1.177      //TODO: optimize with memcmp and 16 inc
   1.178 +    for (int i=0;i<w;i++)
   1.179 +        {
   1.180 +        for (int j=0;j<h;j++)
   1.181 +            {
   1.182 +            //aX*HeightInPixels()+aY
   1.183 +            if ((*iFrameNext)[i*h+j]!=(*iFramePrevious)[i*h+j])
   1.184 +                {
   1.185 +                //We need to update that pixel
   1.186 +                SetPixelBlock(i,j,0,1,((*iFrameNext)[i*h+j]?0x01:0x00));
   1.187 +                //SetDisplayPosition(iDisplayPositionX,OffScreenY());
   1.188 +                //SetDisplayPosition(iDisplayPositionX,OffScreenY());
   1.189 +
   1.190 +                //SetPixelBlock(i,j,15,32,iNextFrame->Ptr()+offset);
   1.191 +                }
   1.192 +            }
   1.193 +        }
   1.194 +
   1.195 +    /*
   1.196      for (int i=0;i<w;i+=16)
   1.197          {
   1.198          for (int j=0;j<h;j+=16)
   1.199              {
   1.200              //aX*HeightInPixels()+aY
   1.201              int offset=(i*w/8)+(j/8);
   1.202 -            if (memcmp(iNextFrame->Ptr()+offset,iCurrentFrame->Ptr()+offset,32 /*(16*16/8)*/))
   1.203 +            if (memcmp(iNextFrame->Ptr()+offset,iCurrentFrame->Ptr()+offset,32 )) //32=(16*16/8)
   1.204                  {
   1.205                  //We need to update that block
   1.206  
   1.207 @@ -424,6 +461,7 @@
   1.208                  }
   1.209              }
   1.210          }
   1.211 +    */
   1.212  
   1.213      }
   1.214  
   1.215 @@ -533,12 +571,7 @@
   1.216  */
   1.217  void GP1212A01A::ToggleOffScreenMode()
   1.218  	{
   1.219 -	iOffScreenMode=!iOffScreenMode;
   1.220 -	//Clean up our buffers upon switching modes	
   1.221 -	SetDisplayPosition(0,0);
   1.222 -	Clear();
   1.223 -	SwapBuffers();
   1.224 -	Clear();
   1.225 +    SetOffScreenMode(!iOffScreenMode);
   1.226  	}
   1.227  
   1.228  /**
     2.1 --- a/MiniDisplay/FutabaVfd.h	Thu May 29 21:42:07 2014 +0200
     2.2 +++ b/MiniDisplay/FutabaVfd.h	Fri May 30 10:56:20 2014 +0200
     2.3 @@ -191,13 +191,15 @@
     2.4  	//FutabaVfdReport iReport;
     2.5  	///
     2.6  	//unsigned char iFrameBuffer[256*64];
     2.7 -    BitArray* iNextFrame;
     2.8 -    BitArray* iCurrentFrame;
     2.9 +    BitArray* iFrameNext;
    2.10 +    BitArray* iFrameCurrent;
    2.11 +    BitArray* iFramePrevious;
    2.12      //
    2.13      BitArray* iFrameAlpha;
    2.14      BitArray* iFrameBeta;
    2.15 +    BitArray* iFrameGamma;
    2.16      //
    2.17 -    bool iNeedFullFrameUpdate;
    2.18 +    int iNeedFullFrameUpdate;
    2.19  	//unsigned char iFrameBeta[256*64];
    2.20  	//unsigned char *iFrontBuffer;
    2.21  	//unsigned char *iBackBuffer;