Пример #1
0
  public void switchRenderer() {
    synchronized (this) {
      mCache = true;

      Bitmap bp = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);

      Canvas d = new Canvas(bp);

      if (mHome) homeRenderer.drawFrame(d);
      else anotherRenderer.drawFrame(d);

      mHome = !mHome;

      // Bitmap bp = view.getDrawingCache();
      // Bitmap bp = screen.cacheImage;

      /*
      for(int i=0;i<bp.getWidth();i++){
      	for(int j=0;j<bp.getHeight();j++){
      		bp.setPixel(i, j, Color.GREEN);
      	}
      }*/
      // bp.copyPixelsToBuffer(dst)

      screen.setCacheBitmap(bp);
    }
  }
Пример #2
0
  @Override
  public void run() {

    /*
     * This is our main activity thread's loop, we go until
     * asked to quit.
     */
    while (!mDone) {

      synchronized (this) {
        if (mPause == true) {
          // Log.e("trend",this.getName() + " is Paused");
          // continue;
          try {
            wait();
          } catch (InterruptedException e) {
          }
        }

        if (!hasSurface) {
          while (!hasSurface) {
            try {
              wait();
            } catch (InterruptedException e) {
            }
          }
        }

        if (mDone) {
          break;
        }

        // Log.e(this.getName(), "Thread is running");

      }

      if (mEvent != null) {
        mEvent.run();
      }

      synchronized (mSurfaceHolder) {
        canvas = mSurfaceHolder.lockCanvas();

        if (canvas != null) {

          if (mCache) {
            if (screen.update()) {
              mCache = false;
            } else {
              screen.draw(canvas);
            }
          } else {
            view.onUpdate();
            view.onStartDrawing(canvas);

            if (mHome) homeRenderer.drawFrame(canvas);
            else anotherRenderer.drawFrame(canvas);

            view.onStopDrawing(canvas);
          }

          mSurfaceHolder.unlockCanvasAndPost(canvas);

          // canvas.dr
        } else {
          // Log.e(Constants.LOGTAG, "Canvas are null");
        }
      }
    }

    // Log.e(Constants.LOGTAG, "Thread finish");
  }