コード例 #1
0
 @Override
 public void clear() {
   if (!isViewReady()) {
     return;
   }
   if (!mDanmakuVisible || Thread.currentThread().getId() == mUiThreadId) {
     mClearFlag = true;
     postInvalidateCompat();
   } else {
     lockCanvasAndClear();
   }
 }
コード例 #2
0
  private void lockCanvas() {
    if (mDanmakuVisible == false) {
      return;
    }
    postInvalidateCompat(); //        设置 mRequestRender = true;
                            // --->invalidate触发onDraw(画完后mRequestRender = false; //复位
                            // 并unlockCanvasAndPost();)
    //                                                                   --->unlockCanvasAndPost中
    // mDrawFinished = true; 标志画完

    /*      synchronized(obj) {
        while(!condition) {
            obj.wait();
        }
        obj.doSomething();
    }
    当线程A获得了obj锁后,发现条件condition不满足,无法继续下一处理,于是线程A就wait() , 放弃对象锁.
            之后在另一线程B中,如果B更改了某些条件,使得线程A的condition条件满足了,就可以唤醒线程A:
    synchronized(obj) {
        condition = true;
        obj.notify();
    }*/
    synchronized (mDrawMonitor) {
      while ((!mDrawFinished) && (handler != null)) {
        try {
          mDrawMonitor.wait(200);
        } catch (InterruptedException e) {
          if (mDanmakuVisible == false || handler == null || handler.isStop()) {
            break;
          } else {
            Thread.currentThread().interrupt();
          }
        }
      }
      mDrawFinished = false; // 复位
    }
  }