Пример #1
0
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);
}
STDMETHODIMP CVWRenderRoot::Init(HWND hWnd, LPDIRECTDRAW pdd, LPDIRECT3DRM pd3drm, LPDIRECT2DRM pd2drm)
{
	EnterCriticalSection(&m_CS);

	CLSID				clsidVWRender3D;
	CLSID				clsidVWRender2D;
	DDPIXELFORMAT		ddpf;
	HRESULT hr = S_OK;

	m_pDD = pdd;
	m_pDD->AddRef();
	m_pD2DRM = pd2drm;
	m_pD2DRM->AddRef();

	m_hWnd = hWnd;

	//
	// create front buffer (primary surface shared with GDI)
	//
	if (FAILED(hr = CreateFrontBuffer(pdd, pd2drm, &m_pddsFrontBuffer)))
		goto e_Init;
	memset(&ddpf,0,sizeof(DDPIXELFORMAT));
	ddpf.dwSize = sizeof(DDPIXELFORMAT);
	m_pddsFrontBuffer->GetPixelFormat(&ddpf);
	if (ddpf.dwRGBBitCount <= 8)
		m_pddsFrontBuffer->GetPalette(&m_pPalette);

	//
	// create clipper
	//
	if (FAILED(hr = CreateClipper(pdd, m_hWnd, &m_lpDDClipper)))
		goto e_Init;

	//
	// create the 2d renderer
	//
	if (FAILED(hr = CLSIDFromProgID(CComBSTR("VWSYSTEM.Render2D.1"), &clsidVWRender2D)) ||
		FAILED(hr = CoCreateInstance(clsidVWRender2D, 
								NULL,
								CLSCTX_INPROC_SERVER,
								IID_IVWRender2D,
								(void **)&m_pVWRender2D)) ||
		FAILED(hr = m_pVWRender2D->Init(hWnd, pd2drm)))
	{
		ASSERT(FALSE);
		goto e_Init;
	}

	//
	// create the 3d renderer
	//
	if (FAILED(hr = CLSIDFromProgID(CComBSTR("VWSYSTEM.Render3D.1"), &clsidVWRender3D)) ||
		FAILED(hr = CoCreateInstance(clsidVWRender3D, 
								NULL,
								CLSCTX_INPROC_SERVER,
								IID_IVWRender3D,
								(void **)&m_pVWRender3D)))
	{
		ASSERT(FALSE);
		goto e_Init;
	}

	// Pass in the color model if already received.
	if (m_d3dColorModel)
		m_pVWRender3D->put_ColorModel(m_d3dColorModel);

	//
	// initialize the 3d renderer
	//
	if (FAILED(hr = m_pVWRender3D->Init(hWnd, pdd, pd3drm)))
	{
		ASSERT(FALSE);
		goto e_Init;
	}

	// Note: The backbuffer will get created on the first OnSize message

	LeaveCriticalSection(&m_CS);
	return hr;

e_Init:
	ReleaseAll();
	LeaveCriticalSection(&m_CS);
	return hr;
}