亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來(lái)到蟲(chóng)蟲(chóng)下載站! | ?? 資源下載 ?? 資源專(zhuān)輯 ?? 關(guān)于我們
? 蟲(chóng)蟲(chóng)下載站

?? allocator.pas

?? 為Delphi2005做了改動(dòng) DSPack 2.3.3 (Sep 2004). DSPack is a set of Components and class to write Multimedia
?? PAS
字號(hào):
//------------------------------------------------------------------------------
// File: Allocator.h & Allocator.cpp
//
// Desc: DirectShow sample code - interface for the TAllocator class
//
//  Portions created by Microsoft are
//  Copyright (C) 2002 Microsoft Corporation.
//  All Rights Reserved.
//
//  The initial developer of the Pascal code is Henri GOURVEST
//    Email    : hgourvest@progdigy.com
//    WebSite  : http://www.progdigy.com
//------------------------------------------------------------------------------

unit Allocator;

interface
uses Windows, DirectShow9, Direct3D9, SyncObjs, PlaneScene, DSPack;

type
  TAllocator = class(TAbstractAllocator, IVMRSurfaceAllocator9, IVMRImagePresenter9)
  private
    // needed to make this a thread safe object
    FObjectLock            : TCriticalSection;
    Fwindow                : HWND;
    FD3D                   : IDirect3D9;
    FD3DDev                : IDirect3DDevice9;
    FlpIVMRSurfAllocNotify : IVMRSurfaceAllocatorNotify9;
    Fsurfaces              : array of IDirect3DSurface9;
    FrenderTarget          : IDirect3DSurface9;
    FprivateTexture        : IDirect3DTexture9;
    Fscene                 : TPlaneScene;
  protected
    function CreateDevice: HResult;
    // a helper function to erase every surface in the vector
    procedure DeleteSurfaces;
    function NeedToHandleDisplayChange: bool;
    // This function is here so we can catch the loss of surfaces.
    // All the functions are using the FAIL_RET macro so that they exit
    // with the last error code.  When this returns with the surface lost
    // error code we can restore the surfaces.
    function PresentHelper(lpPresInfo: PVMR9PresentationInfo): HRESULT;
  public
    constructor Create(out hr: HResult; wnd: THandle; d3d: IDirect3D9 = nil; d3dd: IDirect3DDevice9 = nil); override;
    destructor Destroy; override;

    // IVMRSurfaceAllocator9
    function InitializeDevice(dwUserID: DWORD; lpAllocInfo: PVMR9AllocationInfo;
      var lpNumBuffers: DWORD): HResult; stdcall;
    function TerminateDevice(dwID: DWORD): HResult; stdcall;
    function GetSurface(dwUserID: DWORD; SurfaceIndex: DWORD; SurfaceFlags: DWORD;
      out lplpSurface: IDirect3DSurface9): HResult; stdcall;
    function AdviseNotify(lpIVMRSurfAllocNotify: IVMRSurfaceAllocatorNotify9): HResult; stdcall;

    // IVMRImagePresenter9
    function StartPresenting(dwUserID: DWORD): HResult; stdcall;
    function StopPresenting(dwUserID: DWORD): HResult; stdcall;
    function PresentImage(dwUserID: DWORD; lpPresInfo: PVMR9PresentationInfo): HResult; stdcall;
  end;

implementation

{ TAllocator }

function TAllocator.AdviseNotify(
  lpIVMRSurfAllocNotify: IVMRSurfaceAllocatorNotify9): HResult;
var
  hr: HResult;
  AMonitor: HMONITOR;
  function FailRet(hr: HResult): boolean;
  begin
    AdviseNotify := hr;
    Result := Failed(hr);
  end;
begin
  FObjectLock.Enter;
  try
    FlpIVMRSurfAllocNotify := lpIVMRSurfAllocNotify;
    AMonitor := FD3D.GetAdapterMonitor(D3DADAPTER_DEFAULT);
    hr := FlpIVMRSurfAllocNotify.SetD3DDevice(FD3DDev, AMonitor);
    result := hr;
  finally
    FObjectLock.Leave;
  end;
end;

constructor TAllocator.Create(out hr: HResult; wnd: THandle; d3d: IDirect3D9 = nil; d3dd: IDirect3DDevice9 = nil);
begin
  FD3D    := d3d;
  FD3DDev := d3dd;
  Fwindow := wnd;
  Fscene := TPlaneScene.Create;
  FObjectLock := TCriticalSection.Create;
  FObjectLock.Enter;
  try
    hr := E_FAIL;
    if not IsWindow(wnd) then
    begin
      hr := E_INVALIDARG;
      exit;
    end;

    if (FD3D = nil) then
    begin
      ASSERT(d3dd =  nil);
      FD3D := Direct3DCreate9(D3D_SDK_VERSION);
      if (FD3D = nil) then
      begin
        hr := E_FAIL;
        exit;
      end;
    end;

    if (FD3DDev = nil) then
      hr := CreateDevice;
  finally
    FObjectLock.Leave;
  end;
end;

function TAllocator.CreateDevice: HResult;
var
  dm: TD3DDisplayMode;
  pp: TD3DPresentParameters;

  function FailRet(hr: HResult): boolean;
  begin
    CreateDevice := hr;
    Result := Failed(hr);
  end;
begin
//    HRESULT hr;
  FD3DDev := nil;

  result := FD3D.GetAdapterDisplayMode(D3DADAPTER_DEFAULT, dm);
  ZeroMemory(@pp, sizeof(pp));
  pp.Windowed := TRUE;
  pp.hDeviceWindow := Fwindow;
  pp.SwapEffect := D3DSWAPEFFECT_COPY;
  pp.BackBufferFormat := dm.Format;

  if FailRet(FD3D.CreateDevice(D3DADAPTER_DEFAULT,
                               D3DDEVTYPE_HAL,
                               Fwindow,
                               D3DCREATE_SOFTWARE_VERTEXPROCESSING or
                               D3DCREATE_MULTITHREADED,
                               @pp,
                               FD3DDev)) then exit;

  FrenderTarget := nil;
  Result := FD3DDev.GetRenderTarget(0, FrenderTarget);
end;

procedure TAllocator.DeleteSurfaces;
var i: integer;
begin
  FObjectLock.Enter;
  try
    // clear out the private texture
    FprivateTexture := nil;
    for i := 0 to Length(FSurfaces) - 1 do
      FSurfaces[i] := nil;
  finally
    FObjectLock.Leave;
  end;
end;

destructor TAllocator.Destroy;
begin
  DeleteSurfaces;
  Fscene.Free;
  FObjectLock.Destroy;
  inherited;
end;

function TAllocator.GetSurface(dwUserID, SurfaceIndex, SurfaceFlags: DWORD;
  out lplpSurface: IDirect3DSurface9): HResult;
begin
  if (@lplpSurface = nil) then
  begin
    result := E_POINTER;
    Exit;
  end;

  if (SurfaceIndex >= Cardinal(Length(Fsurfaces))) then
  begin
    result := E_FAIL;
    Exit;
  end;

  FObjectLock.Enter;
  try
    try
      lplpSurface := Fsurfaces[SurfaceIndex];
      result := S_OK;
    except
      result := E_FAIL;
    end;
  finally
    FObjectLock.Leave;
  end;
end;

function TAllocator.InitializeDevice(dwUserID: DWORD;
  lpAllocInfo: PVMR9AllocationInfo; var lpNumBuffers: DWORD): HResult;
var
  d3dcaps: TD3DCaps9;
  dwWidth: DWORD;
  dwHeight: DWORD;
  fTU: Single;
  fTV: Single;
  hr: HRESULT;
  dm: TD3DDisplayMode;
  function FailRet(hr: HResult): boolean;
  begin
    InitializeDevice := hr;
    Result := Failed(hr);
  end;
begin
  dwWidth  := 1;
  dwHeight := 1;

  if (lpNumBuffers = 0) then
  begin
    Result := E_POINTER;
    Exit;
  end;

  if (FlpIVMRSurfAllocNotify = nil) then
  begin
    result := E_FAIL;
    Exit;
  end;

  FD3DDev.GetDeviceCaps(d3dcaps);
  if LongBool(d3dcaps.TextureCaps and D3DPTEXTURECAPS_POW2) then
  begin
    while (dwWidth < lpAllocInfo.dwWidth) do
      dwWidth := dwWidth shl 1;
    while (dwHeight < lpAllocInfo.dwHeight) do
      dwHeight := dwHeight shl 1;
    fTU := (lpAllocInfo.dwWidth) / (dwWidth);
    fTV := (lpAllocInfo.dwHeight) / (dwHeight);
    Fscene.SetSrcRect(fTU, fTV);
    lpAllocInfo.dwWidth := dwWidth;
    lpAllocInfo.dwHeight := dwHeight;
  end;

  // NOTE:
  // we need to make sure that we create textures because
  // surfaces can not be textured onto a primitive.
  lpAllocInfo.dwFlags := lpAllocInfo.dwFlags or VMR9AllocFlag_TextureSurface;

  DeleteSurfaces;
  SetLength(Fsurfaces, lpNumBuffers);
  hr := FlpIVMRSurfAllocNotify.AllocateSurfaceHelper(lpAllocInfo, lpNumBuffers, Fsurfaces[0]);

  // If we couldn't create a texture surface and
  // the format is not an alpha format,
  // then we probably cannot create a texture.
  // So what we need to do is create a private texture
  // and copy the decoded images onto it.
  if (FAILED(hr) and not LongBool(lpAllocInfo.dwFlags and VMR9AllocFlag_3DRenderTarget)) then
  begin
      DeleteSurfaces;

      // is surface YUV ?
      if (lpAllocInfo.Format > D3DFMT_UNKNOWN) then
      begin
          if FailRet(FD3DDev.GetDisplayMode(0, dm)) then exit;

          // create the private texture
          if FailRet(FD3DDev.CreateTexture(lpAllocInfo.dwWidth, lpAllocInfo.dwHeight,
                                  1,
                                  D3DUSAGE_RENDERTARGET,
                                  dm.Format,
                                  D3DPOOL_DEFAULT, // default pool - usually video memory
                                  FprivateTexture, nil)) then exit;
      end;


      lpAllocInfo.dwFlags := lpAllocInfo.dwFlags and not VMR9AllocFlag_TextureSurface;
      lpAllocInfo.dwFlags := lpAllocInfo.dwFlags or VMR9AllocFlag_OffscreenSurface;

      if FailRet(FlpIVMRSurfAllocNotify.AllocateSurfaceHelper(lpAllocInfo, lpNumBuffers, Fsurfaces[0])) then exit;
  end;

  Result := Fscene.Init(FD3DDev);
end;

function TAllocator.NeedToHandleDisplayChange: bool;
var
  Parameters: TD3DDeviceCreationParameters;
  currentMonitor, AMonitor: HMONITOR;
begin
  if (FlpIVMRSurfAllocNotify <> nil) then
  begin
    result := false;
    exit;
  end;

  if (Failed(FD3DDev.GetCreationParameters(Parameters))) then
  begin
    Assert(false);
    result := false;
    exit;
  end;

  currentMonitor := FD3D.GetAdapterMonitor(Parameters.AdapterOrdinal);
  AMonitor := FD3D.GetAdapterMonitor(D3DADAPTER_DEFAULT);
  result := AMonitor <> currentMonitor;
end;

function TAllocator.PresentHelper(
  lpPresInfo: PVMR9PresentationInfo): HRESULT;
var
  surface: IDirect3DSurface9;
  texture: IDirect3DTexture9;
  function FailRet(hr: HResult): boolean;
  begin
    PresentHelper := hr;
    Result := Failed(hr);
  end;
begin
  // parameter validation
  if (lpPresInfo = nil) then
  begin
    result := E_POINTER;
    exit;
  end else
  if (lpPresInfo.lpSurf = nil) then
  begin
    result := E_POINTER;
    exit;
  end;

  FObjectLock.Enter;
  try
    FD3DDev.SetRenderTarget(0, FrenderTarget);
    // if we created a  private texture
    // blt the decoded image onto the texture.
    if(FprivateTexture <> nil) then
    begin
      if FailRet(FprivateTexture.GetSurfaceLevel(0 , surface)) then exit;

      // copy the full surface onto the texture's surface
      if FailRet(FD3DDev.StretchRect(lpPresInfo.lpSurf, nil,
                           surface, nil,
                           D3DTEXF_NONE)) then exit;

      if FailRet(Fscene.DrawScene(FD3DDev, FprivateTexture)) then exit;
    end
    else // this is the case where we have got the textures allocated by VMR
         // all we need to do is to get them from the surface
    begin
      if FailRet(lpPresInfo.lpSurf.GetContainer(IID_IDirect3DTexture9, Pointer(texture))) then exit;
      if FailRet(Fscene.DrawScene(FD3DDev, texture)) then exit;
    end;
    if FailRet(FD3DDev.Present(nil, nil, 0, nil)) then exit;
//    result := hr;
  finally
    Pointer(texture) := nil;
    FObjectLock.leave;
  end;
end;

function TAllocator.PresentImage(dwUserID: DWORD;
  lpPresInfo: PVMR9PresentationInfo): HResult;
var
  hr: HRESULT;
  AMonitor: HMONITOR;
  function FailRet(hr: HResult): boolean;
  begin
    PresentImage := hr;
    Result := Failed(hr);
  end;
begin
  FObjectLock.Enter;
  try
    // if we are in the middle of the display change
    if NeedToHandleDisplayChange then
    begin
        // NOTE: this piece of code is left as a user exercise.
        // The D3DDevice here needs to be switched
        // to the device that is using another adapter
    end;

    hr := PresentHelper(lpPresInfo);

    // IMPORTANT: device can be lost when user changes the resolution
    // or when (s)he presses Ctrl + Alt + Delete.
    // We need to restore our video memory after that
    if (hr = D3DERR_DEVICELOST) then
    begin
      if (FD3DDev.TestCooperativeLevel = D3DERR_DEVICENOTRESET) then
      begin
        DeleteSurfaces;
        if FailRet(CreateDevice) then exit;
        AMonitor := FD3D.GetAdapterMonitor(D3DADAPTER_DEFAULT);
        if FailRet(FlpIVMRSurfAllocNotify.ChangeD3DDevice(FD3DDev, AMonitor)) then exit;
      end;
      hr := S_OK;
    end;
    result := hr;
  finally
    FObjectLock.Leave;
  end;
end;

function TAllocator.StartPresenting(dwUserID: DWORD): HResult;
begin
  FObjectLock.Enter;
  try
    ASSERT(assigned(FD3DDev));
    if (FD3DDev = nil) then
    begin
      result := E_FAIL;
      exit;
    end;
    result := S_OK;
  finally
    FObjectLock.Leave;
  end;
end;

function TAllocator.StopPresenting(dwUserID: DWORD): HResult;
begin
  result := S_OK;
end;

function TAllocator.TerminateDevice(dwID: DWORD): HResult;
begin
  DeleteSurfaces;
  result := S_OK;
end;

end.

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
av在线免费不卡| 欧美妇女性影城| 国产精品一区二区三区四区| 久久精品二区亚洲w码| 日本成人在线视频网站| 亚洲444eee在线观看| 天天影视涩香欲综合网 | 日韩av网站免费在线| 亚洲444eee在线观看| 视频一区视频二区中文| 日日摸夜夜添夜夜添亚洲女人| 亚洲成人精品一区二区| 午夜精品久久久久| 久久精品国产精品青草| 国产精品自在欧美一区| 成人精品国产一区二区4080| 97久久精品人人做人人爽| 欧洲国内综合视频| 欧美妇女性影城| 欧美日韩在线播放三区四区| 3d动漫精品啪啪| 精品国产凹凸成av人网站| 久久久国产精品麻豆| 中文字幕二三区不卡| 一区二区三区精品久久久| 天天综合网 天天综合色| 国内久久精品视频| 成人一区二区三区在线观看| 91一区二区三区在线观看| 欧美日韩一区二区在线观看视频 | 欧美精品一区二区三区高清aⅴ | 欧美国产精品中文字幕| 亚洲色图视频网站| 午夜免费久久看| 国产精品一品二品| 国产精华液一区二区三区| 色综合久久天天| 欧美一区二区三区在线视频| 国产调教视频一区| 一区二区三区四区精品在线视频| 日韩和欧美一区二区| 国产成人午夜精品影院观看视频| 色婷婷av一区二区三区gif| 欧美一区二区网站| 中文字幕亚洲综合久久菠萝蜜| 亚洲不卡av一区二区三区| 国产真实乱偷精品视频免| 99国产欧美久久久精品| 欧美一区二区啪啪| 亚洲视频一区二区在线| 免费看日韩a级影片| va亚洲va日韩不卡在线观看| 日韩一区二区影院| 亚洲欧美韩国综合色| 极品美女销魂一区二区三区| 91国产成人在线| 久久人人爽爽爽人久久久| 一区二区高清视频在线观看| 国产乱一区二区| 欧美日韩一区二区在线视频| 中日韩av电影| 久久国产精品第一页| 在线一区二区观看| 欧美激情一二三区| 久久精品99国产精品日本| 欧美性猛片aaaaaaa做受| 国产亚洲精品免费| 日本伊人色综合网| 91成人免费网站| 中文字幕国产一区| 国产在线精品免费| 在线成人免费观看| 一区二区三区四区在线免费观看| 国产成人av一区二区三区在线观看| 欧美日本乱大交xxxxx| 亚洲男人电影天堂| 成人av午夜影院| 久久蜜臀中文字幕| 蜜桃在线一区二区三区| 欧美日韩日日摸| 自拍偷在线精品自拍偷无码专区| 国产精品99久久久久久久女警 | 日韩一级免费观看| 亚洲在线视频免费观看| 不卡高清视频专区| 国产午夜精品一区二区三区视频 | 91视频在线观看| 国产亚洲精品免费| 国产美女av一区二区三区| 91精品婷婷国产综合久久竹菊| 亚洲精品视频免费看| 91在线免费看| 亚洲欧洲精品一区二区精品久久久 | 首页国产欧美久久| 欧美日韩成人在线一区| 亚洲激情成人在线| 91麻豆国产精品久久| 中文字幕在线不卡一区二区三区| 国产.欧美.日韩| 国产亚洲精品超碰| 国产999精品久久久久久绿帽| 欧美成人a视频| 老司机精品视频在线| 日韩一区二区三区视频| 青青草视频一区| 日韩欧美一二三四区| 精品在线视频一区| 久久综合狠狠综合久久综合88 | 喷水一区二区三区| 欧美一级日韩免费不卡| 免费一级欧美片在线观看| 日韩一区二区免费在线电影| 老司机午夜精品| 久久久精品一品道一区| 成人永久看片免费视频天堂| 中文字幕亚洲成人| 色婷婷av久久久久久久| 亚洲成av人片一区二区| 91精品国产色综合久久久蜜香臀| 麻豆免费精品视频| 久久精品人人做人人爽97| 成人v精品蜜桃久久一区| 亚洲图片激情小说| 欧美色爱综合网| 美女在线视频一区| 久久九九久精品国产免费直播| 成人理论电影网| 亚洲精品久久嫩草网站秘色| 欧美裸体一区二区三区| 精品一区二区影视| 国产精品美女久久久久av爽李琼| 色香蕉成人二区免费| 日韩综合一区二区| 久久久久久免费网| 91浏览器入口在线观看| 三级不卡在线观看| 久久久久久久免费视频了| 99久久精品免费看| 首页综合国产亚洲丝袜| 欧美激情在线看| 欧美视频自拍偷拍| 激情五月婷婷综合网| 国产精品大尺度| 91精品一区二区三区在线观看| 国产福利一区在线| 一区二区三区精品久久久| 精品国产第一区二区三区观看体验 | a美女胸又www黄视频久久| 亚洲成人手机在线| 久久在线观看免费| 91久久精品日日躁夜夜躁欧美| 久久精品免费观看| 亚洲欧美日本在线| 2欧美一区二区三区在线观看视频| heyzo一本久久综合| 美女视频黄 久久| 亚洲欧美aⅴ...| 久久久久国产精品麻豆ai换脸 | 久久综合狠狠综合久久综合88| 91片在线免费观看| 精品在线你懂的| 亚洲一区二区综合| 亚洲国产岛国毛片在线| 宅男噜噜噜66一区二区66| www.激情成人| 久久成人免费电影| 亚洲午夜免费电影| 国产精品久久久久久一区二区三区| 7777精品伊人久久久大香线蕉最新版 | 国产经典欧美精品| 喷白浆一区二区| 一区二区三区在线不卡| 国产校园另类小说区| 91麻豆精品国产91久久久使用方法 | 国产福利一区二区三区视频在线| 午夜精品免费在线| 综合在线观看色| 精品久久人人做人人爽| 欧美挠脚心视频网站| 91免费看视频| 成人妖精视频yjsp地址| 久久er99精品| 日韩不卡在线观看日韩不卡视频| 亚洲女子a中天字幕| 国产清纯美女被跳蛋高潮一区二区久久w| 欧美精品国产精品| 在线精品观看国产| 99riav一区二区三区| 国产成人久久精品77777最新版本| 免费观看久久久4p| 日韩精品乱码免费| 亚洲国产婷婷综合在线精品| 亚洲免费观看视频| 国产精品黄色在线观看| 国产丝袜欧美中文另类| 久久久精品欧美丰满| 国产欧美日韩麻豆91| 精品福利一二区| 欧美视频一区二区三区| 色综合久久久网|