当前位置: 首页>>代码示例>>C++>>正文


C++ IDirect3DSurface9::AddRef方法代码示例

本文整理汇总了C++中IDirect3DSurface9::AddRef方法的典型用法代码示例。如果您正苦于以下问题:C++ IDirect3DSurface9::AddRef方法的具体用法?C++ IDirect3DSurface9::AddRef怎么用?C++ IDirect3DSurface9::AddRef使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDirect3DSurface9的用法示例。


在下文中一共展示了IDirect3DSurface9::AddRef方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: if

HRESULT D3DPresentEngine::PresentSample(IMFSample* pSample, LONGLONG llTarget)
{
    HRESULT hr = S_OK;

    IMFMediaBuffer* pBuffer = NULL;
    IDirect3DSurface9* pSurface = NULL;
    IDirect3DSwapChain9* pSwapChain = NULL;

    if (pSample)
    {
        // Get the buffer from the sample.
        CHECK_HR(hr = pSample->GetBufferByIndex(0, &pBuffer));

        // Get the surface from the buffer.
        CHECK_HR(hr = MFGetService(pBuffer, MR_BUFFER_SERVICE, __uuidof(IDirect3DSurface9), (void**)&pSurface));
    }
    else if (m_pSurfaceRepaint)
    {
        // Redraw from the last surface.
        pSurface = m_pSurfaceRepaint;
        pSurface->AddRef();
    }

    if (pSurface)
    {
        // Get the swap chain from the surface.
        CHECK_HR(hr = pSurface->GetContainer(__uuidof(IDirect3DSwapChain9), (LPVOID*)&pSwapChain));

        // Present the swap chain.
        CHECK_HR(hr = PresentSwapChain(pSwapChain, pSurface));

        // Store this pointer in case we need to repaint the surface.
        CopyComPointer(m_pSurfaceRepaint, pSurface);
    }

done:
    SAFE_RELEASE(pSwapChain);
    SAFE_RELEASE(pSurface);
    SAFE_RELEASE(pBuffer);

    if (FAILED(hr))
    {
        if (hr == D3DERR_DEVICELOST || hr == D3DERR_DEVICENOTRESET || hr == D3DERR_DEVICEHUNG)
        {
            // Ignore. We need to reset or re-create the device, but this method
            // is probably being called from the scheduler thread, which is not the
            // same thread that created the device. The Reset(Ex) method must be
            // called from the thread that created the device.

            // The presenter will detect the state when it calls CheckDeviceState() 
            // on the next sample.
            hr = S_OK;
        }
    }
    return hr;
}
开发者ID:FerozAhmed,项目名称:WPFMediaKit,代码行数:56,代码来源:PresentEngine.cpp

示例2:

HRESULT STDMETHODCALLTYPE CTexture9::GetSurfaceLevel(UINT Level, IDirect3DSurface9** ppSurfaceLevel)
{
	IDirect3DSurface9* surface = (IDirect3DSurface9*)this->mSurfaces[Level];

	/*
	https://msdn.microsoft.com/en-us/library/windows/desktop/bb205912(v=vs.85).aspx
	"Calling this method will increase the internal reference count on the IDirect3DSurface9 interface."
	*/
	surface->AddRef();

	(*ppSurfaceLevel) = surface;

	return D3D_OK;
}
开发者ID:disks86,项目名称:SchaeferGL,代码行数:14,代码来源:CTexture9.cpp

示例3: if

fResult f2dRenderDeviceImpl::SaveTexture(f2dStream* pStream, f2dTexture2D* pTex)
{
    if(m_bDevLost)
        return FCYERR_ILLEGAL;

    if(!pStream || !pTex || !pStream->CanWrite() || !pStream->CanResize())
        return FCYERR_INVAILDPARAM;

    IDirect3DSurface9* pSurface = NULL;
    if(pTex->IsDynamic())
        ((IDirect3DTexture9*)((f2dTexture2DDynamic*)pTex)->GetHandle())->GetSurfaceLevel(0, &pSurface);
    else if(pTex->IsRenderTarget())
    {
        pSurface = ((f2dTexture2DRenderTarget*)pTex)->GetSurface();
        pSurface->AddRef();
    }
    else
        ((IDirect3DTexture9*)((f2dTexture2DStatic*)pTex)->GetHandle())->GetSurfaceLevel(0, &pSurface);

    if(!pSurface)
        return FCYERR_INTERNALERR;

    ID3DXBuffer* pDataBuffer = NULL;
    HRESULT tHR = m_API.DLLEntry_D3DXSaveSurfaceToFileInMemory(&pDataBuffer, D3DXIFF_PNG, pSurface, NULL, NULL);
    FCYSAFEKILL(pSurface);
    if(FAILED(tHR))
    {
        m_pEngine->ThrowException(fcyWin32COMException("f2dRenderDeviceImpl::SaveTexture", "D3DXSaveSurfaceToFileInMemory Failed.", tHR));
        return FCYERR_INTERNALERR;
    }

    // 保存到流
    if(FCYFAILED(pStream->WriteBytes((fcData)pDataBuffer->GetBufferPointer(), pDataBuffer->GetBufferSize(), NULL)))
    {
        FCYSAFEKILL(pDataBuffer);
        return FCYERR_INTERNALERR;
    }

    FCYSAFEKILL(pDataBuffer);

    return FCYERR_OK;
}
开发者ID:pascalkk,项目名称:fancy2d,代码行数:42,代码来源:f2dRenderDeviceImpl.cpp

示例4: GetSurface

 HRESULT _stdcall GetSurface(DWORD_PTR dwUserID, DWORD SurfaceIndex, DWORD SurfaceFlags, IDirect3DSurface9 **lplpSurface) {
     if(SurfaceIndex!=0) return E_FAIL;
     *lplpSurface=surface;
     surface->AddRef();
     return S_OK;
 }
开发者ID:angeld29,项目名称:morrgraphext,代码行数:6,代码来源:VidTex.cpp

示例5: Add

REFERENCE_TIME CProcessor::Add(DVDVideoPicture* picture)
{
  CSingleLock lock(m_section);

  IDirect3DSurface9* surface = NULL;
  CSurfaceContext* context = NULL;

  if (picture->iFlags & DVP_FLAG_DROPPED)
    return 0;

  switch (picture->format)
  {
    case DVDVideoPicture::FMT_DXVA:
    {
      surface = (IDirect3DSurface9*)picture->data[3];
      context = picture->context;
      break;
    }

    case DVDVideoPicture::FMT_YUV420P:
    {
      surface = m_surfaces[m_index];
      m_index = (m_index + 1) % m_size;

      context = m_context;
  
      D3DLOCKED_RECT rectangle;
      if (FAILED(surface->LockRect(&rectangle, NULL, 0)))
        return 0;

      // Convert to NV12 - Luma
      // TODO: Optimize this later using shaders/swscale/etc.
      uint8_t *s = picture->data[0];
      uint8_t* bits = (uint8_t*)(rectangle.pBits);
      for (unsigned y = 0; y < picture->iHeight; y++)
      {
        memcpy(bits, s, picture->iWidth);
        s += picture->iLineSize[0];
        bits += rectangle.Pitch;
      }

      D3DSURFACE_DESC desc;
      if (FAILED(surface->GetDesc(&desc)))
        return 0;

      // Convert to NV12 - Chroma
      uint8_t *s_u, *s_v, *d_uv;
      for (unsigned y = 0; y < picture->iHeight/2; y++)
      {
        s_u = picture->data[1] + (y * picture->iLineSize[1]);
        s_v = picture->data[2] + (y * picture->iLineSize[2]);
        d_uv = ((uint8_t*)(rectangle.pBits)) + (desc.Height + y) * rectangle.Pitch;
        for (unsigned x = 0; x < picture->iWidth/2; x++)
        {
          *d_uv++ = *s_u++;
          *d_uv++ = *s_v++;
        }
      }
  
      if (FAILED(surface->UnlockRect()))
        return 0;

      break;
    }
    
    default:
    {
      CLog::Log(LOGWARNING, "DXVA - colorspace not supported by processor, skipping frame");
      return 0;
    }
  }

  if (!surface || !context)
    return 0;

  m_time += 2;

  surface->AddRef();
  context->Acquire();

  SVideoSample vs = {};
  vs.sample.Start          = m_time;
  vs.sample.End            = 0; 
  vs.sample.SampleFormat   = m_desc.SampleFormat;

  if (picture->iFlags & DVP_FLAG_INTERLACED)
  {
    if (picture->iFlags & DVP_FLAG_TOP_FIELD_FIRST)
      vs.sample.SampleFormat.SampleFormat = DXVA2_SampleFieldInterleavedEvenFirst;
    else
      vs.sample.SampleFormat.SampleFormat = DXVA2_SampleFieldInterleavedOddFirst;
  }
  else
  {
    vs.sample.SampleFormat.SampleFormat = DXVA2_SampleProgressiveFrame;
  }

  vs.sample.PlanarAlpha    = DXVA2_Fixed32OpaqueAlpha();
  vs.sample.SampleData     = 0;
  vs.sample.SrcSurface     = surface;
//.........这里部分代码省略.........
开发者ID:0wing,项目名称:xbmc,代码行数:101,代码来源:DXVA.cpp

示例6: if

HRESULT D3DPresentEngine::PresentSample(IMFSample* pSample, LONGLONG llTarget)
{
    HRESULT hr = S_OK;

    IMFMediaBuffer* pBuffer = NULL;
    IDirect3DSurface9* pSurface = NULL;
//     IDirect3DSwapChain9* pSwapChain = NULL;
	IDirect3DSurface9 * back_buffer = NULL;

    if (pSample)
    {
        // Get the buffer from the sample.
        CHECK_HR(hr = pSample->GetBufferByIndex(0, &pBuffer));

        // Get the surface from the buffer.
        CHECK_HR(hr = MFGetService(pBuffer, MR_BUFFER_SERVICE, __uuidof(IDirect3DSurface9), (void**)&pSurface));
    }
    else if (m_pSurfaceRepaint)
    {
        // Redraw from the last surface.
        pSurface = m_pSurfaceRepaint;
        pSurface->AddRef();
    }

    if (pSurface)
    {
        // Get the swap chain from the surface.
//         CHECK_HR(hr = pSurface->GetContainer(__uuidof(IDirect3DSwapChain9), (LPVOID*)&pSwapChain));

        // Present the swap chain.
//          CHECK_HR(hr = PresentSwapChain(pSwapChain, pSurface));

		CHECK_HR(hr = m_pDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &back_buffer));

		CHECK_HR(hr = m_pDevice->StretchRect(pSurface, NULL, back_buffer, NULL, D3DTEXF_LINEAR));

		CHECK_HR(hr = m_pDevice->Present(NULL, NULL, NULL, NULL));

        // Store this pointer in case we need to repaint the surface.
        CopyComPointer(m_pSurfaceRepaint, pSurface);
    }
    else
    {
        // No surface. All we can do is paint a black rectangle.
        PaintFrameWithGDI();
    }

done:
//     SAFE_RELEASE(pSwapChain);
    SAFE_RELEASE(pSurface);
    SAFE_RELEASE(pBuffer);
	SAFE_RELEASE(back_buffer);

    if (FAILED(hr))
    {
        if (hr == D3DERR_DEVICELOST || hr == D3DERR_DEVICENOTRESET || hr == D3DERR_DEVICEHUNG)
        {
            // We failed because the device was lost. Fill the destination rectangle.
            PaintFrameWithGDI();

            // Ignore. We need to reset or re-create the device, but this method
            // is probably being called from the scheduler thread, which is not the
            // same thread that created the device. The Reset(Ex) method must be
            // called from the thread that created the device.

            // The presenter will detect the state when it calls CheckDeviceState() 
            // on the next sample.
            hr = S_OK;
        }
    }
    return hr;
}
开发者ID:my12doom,项目名称:personalProjects,代码行数:72,代码来源:PresentEngine.cpp

示例7: lock

HRESULT D3DPresentEngine::CreateVideoSamples(
    IMFMediaType *pFormat, 
    VideoSampleList& videoSampleQueue
    )
{
    if (m_hwnd == NULL)
    {
        return MF_E_INVALIDREQUEST;
    }

    if (pFormat == NULL)
    {
        return MF_E_UNEXPECTED;
    }

    HRESULT hr = S_OK;
    D3DPRESENT_PARAMETERS pp;

    IDirect3DSurface9 *pSurface = NULL;    // Swap chain
    IMFSample *pVideoSample = NULL;            // Sampl
    
    AutoLock lock(m_ObjectLock);

    ReleaseResources();

    // Get the swap chain parameters from the media type.
    CHECK_HR(hr = GetSwapChainPresentParameters(pFormat, &pp));

    UpdateDestRect();

    // Create the video samples.
    for (int i = 0; i < PRESENTER_BUFFER_COUNT; i++)
    {
        // Create a new swap chain.
        CHECK_HR(hr = m_pDevice->CreateRenderTarget(1920, 1080, pp.BackBufferFormat, D3DMULTISAMPLE_NONE, 0, FALSE, &pSurface, NULL));
        
        // Create the video sample from the swap chain.
        CHECK_HR(hr = CreateD3DSample(pSurface, &pVideoSample));

        // Add it to the list.
        CHECK_HR(hr = videoSampleQueue.InsertBack(pVideoSample));

        // Set the swap chain pointer as a custom attribute on the sample. This keeps
        // a reference count on the swap chain, so that the swap chain is kept alive
        // for the duration of the sample's lifetime.
        CHECK_HR(hr = pVideoSample->SetUnknown(MFSamplePresenter_SampleSwapChain, pSurface));
		pSurface->AddRef();

        SAFE_RELEASE(pVideoSample);
        SAFE_RELEASE(pSurface);
    }

    // Let the derived class create any additional D3D resources that it needs.
    CHECK_HR(hr = OnCreateVideoSamples(pp));

done:
    if (FAILED(hr))
    {
        ReleaseResources();
    }
        
    SAFE_RELEASE(pSurface);
    SAFE_RELEASE(pVideoSample);
    return hr;
}
开发者ID:my12doom,项目名称:personalProjects,代码行数:65,代码来源:PresentEngine.cpp

示例8: swap

bool Surface::swap()
{
    if (mSwapChain)
    {
        IDirect3DTexture9 *flipTexture = mFlipTexture;
        flipTexture->AddRef();

        IDirect3DSurface9 *renderTarget = mRenderTarget;
        renderTarget->AddRef();

        EGLint oldWidth = mWidth;
        EGLint oldHeight = mHeight;

        checkForWindowResize();

        IDirect3DDevice9 *device = mDisplay->getDevice();

        IDirect3DSurface9 *textureSurface;
        flipTexture->GetSurfaceLevel(0, &textureSurface);

        mDisplay->endScene();
        device->StretchRect(renderTarget, NULL, textureSurface, NULL, D3DTEXF_NONE);
        renderTarget->Release();

        applyFlipState(device);
        device->SetTexture(0, flipTexture);

        float xscale = (float)mWidth / oldWidth;
        float yscale = (float)mHeight / oldHeight;

        // Render the texture upside down into the back buffer
        // Texcoords are chosen to pin a potentially resized image into the upper-left corner without scaling.
        float quad[4][6] = {{     0 - 0.5f,       0 - 0.5f, 0.0f, 1.0f, 0.0f,   1.0f       },
                            {mWidth - 0.5f,       0 - 0.5f, 0.0f, 1.0f, xscale, 1.0f       },
                            {mWidth - 0.5f, mHeight - 0.5f, 0.0f, 1.0f, xscale, 1.0f-yscale},
                            {     0 - 0.5f, mHeight - 0.5f, 0.0f, 1.0f, 0.0f,   1.0f-yscale}};   // x, y, z, rhw, u, v

        mDisplay->startScene();
        device->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, quad, 6 * sizeof(float));

        flipTexture->Release();
        textureSurface->Release();

        restoreState(device);

        mDisplay->endScene();
        HRESULT result = mSwapChain->Present(NULL, NULL, NULL, NULL, mDisplay->getPresentInterval());

        if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY || result == D3DERR_DRIVERINTERNALERROR)
        {
            return error(EGL_BAD_ALLOC, false);
        }

        if (result == D3DERR_DEVICELOST)
        {
            return error(EGL_CONTEXT_LOST, false);
        }

        ASSERT(SUCCEEDED(result));

    }

    return true;
}
开发者ID:achellies,项目名称:WinCEWebKit,代码行数:64,代码来源:Surface.cpp


注:本文中的IDirect3DSurface9::AddRef方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。