void
ContentClientRemoteBuffer::CreateBackBuffer(const IntRect& aBufferRect)
{
  // gfx::BackendType::NONE means fallback to the content backend
  mTextureClient = CreateTextureClientForDrawing(
    mSurfaceFormat, mSize, gfx::BackendType::NONE,
    mTextureFlags | ExtraTextureFlags(),
    TextureAllocationFlags::ALLOC_CLEAR_BUFFER
  );
  if (!mTextureClient || !AddTextureClient(mTextureClient)) {
    AbortTextureClientCreation();
    return;
  }

  if (mTextureFlags & TextureFlags::COMPONENT_ALPHA) {
    mTextureClientOnWhite = mTextureClient->CreateSimilar(
      mTextureFlags | ExtraTextureFlags(),
      TextureAllocationFlags::ALLOC_CLEAR_BUFFER_WHITE
    );
    if (!mTextureClientOnWhite || !AddTextureClient(mTextureClientOnWhite)) {
      AbortTextureClientCreation();
      return;
    }
  }
}
void
ContentClientDoubleBuffered::CreateFrontBuffer(const nsIntRect& aBufferRect)
{
    if (!CreateAndAllocateTextureClient(mFrontClient, TEXTURE_ON_BLACK) ||
            !AddTextureClient(mFrontClient)) {
        AbortTextureClientCreation();
        return;
    }
    if (mTextureInfo.mTextureFlags & TEXTURE_COMPONENT_ALPHA) {
        if (!CreateAndAllocateTextureClient(mFrontClientOnWhite, TEXTURE_ON_WHITE) ||
                !AddTextureClient(mFrontClientOnWhite)) {
            AbortTextureClientCreation();
            return;
        }
    }

    mFrontBufferRect = aBufferRect;
    mFrontBufferRotation = nsIntPoint();
}
void
ContentClientRemoteBuffer::BuildTextureClients(SurfaceFormat aFormat,
        const nsIntRect& aRect,
        uint32_t aFlags)
{
    // If we hit this assertion, then it might be due to an empty transaction
    // followed by a real transaction. Our buffers should be created (but not
    // painted in the empty transaction) and then painted (but not created) in the
    // real transaction. That is kind of fragile, and this assert will catch
    // circumstances where we screw that up, e.g., by unnecessarily recreating our
    // buffers.
    NS_ABORT_IF_FALSE(!mIsNewBuffer,
                      "Bad! Did we create a buffer twice without painting?");

    mIsNewBuffer = true;

    DestroyBuffers();

    mSurfaceFormat = aFormat;
    mSize = gfx::IntSize(aRect.width, aRect.height);
    mTextureInfo.mTextureFlags = TextureFlagsForRotatedContentBufferFlags(aFlags);

    if (!CreateAndAllocateTextureClient(mTextureClient, TEXTURE_ON_BLACK) ||
            !AddTextureClient(mTextureClient)) {
        AbortTextureClientCreation();
        return;
    }

    if (aFlags & BUFFER_COMPONENT_ALPHA) {
        if (!CreateAndAllocateTextureClient(mTextureClientOnWhite, TEXTURE_ON_WHITE) ||
                !AddTextureClient(mTextureClientOnWhite)) {
            AbortTextureClientCreation();
            return;
        }
        mTextureInfo.mTextureFlags |= TEXTURE_COMPONENT_ALPHA;
    }

    CreateFrontBuffer(aRect);
}