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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? allocator.pas

?? 一套及時通訊的原碼
?? PAS
字號:
//------------------------------------------------------------------------------
// 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.

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲精品一线二线三线| 在线不卡免费av| 国产一区二区三区久久悠悠色av| 中文字幕综合网| 国产婷婷色一区二区三区在线| 欧美日韩一区二区三区不卡| 91丨九色porny丨蝌蚪| 成人免费视频视频在线观看免费| 久久99久久久久久久久久久| 视频在线观看一区| 日韩制服丝袜av| 婷婷国产v国产偷v亚洲高清| 亚洲国产精品久久一线不卡| 亚洲成人www| 日韩激情一二三区| 久久机这里只有精品| 麻豆成人在线观看| 国产精品中文字幕一区二区三区| 韩国三级在线一区| 国产精品一区二区久激情瑜伽 | 丁香婷婷深情五月亚洲| 成人高清视频在线| 91社区在线播放| 欧美电视剧在线观看完整版| 欧美精品三级日韩久久| xfplay精品久久| 中文字幕制服丝袜成人av| 一区二区成人在线| 免费人成黄页网站在线一区二区| 国产精品资源网站| 在线精品视频小说1| 欧美成人艳星乳罩| 中文字幕一区不卡| 欧美aⅴ一区二区三区视频| 狠狠色丁香久久婷婷综| 一本到三区不卡视频| 精品福利一区二区三区| 在线观看不卡一区| 99视频在线精品| 日韩一区二区在线观看视频播放| 亚洲一区二区视频| 国产成人8x视频一区二区| 欧美三级三级三级| 中文字幕在线观看一区| 日韩精品电影在线观看| 丰满亚洲少妇av| 欧美一二区视频| 久久久美女艺术照精彩视频福利播放 | 在线观看网站黄不卡| 2023国产精华国产精品| 夜夜嗨av一区二区三区中文字幕| 国产在线一区二区| 欧美精三区欧美精三区| 亚洲欧美在线另类| 国模冰冰炮一区二区| 在线观看日韩毛片| 欧美高清在线视频| 国产成人精品一区二区三区四区| 欧美日高清视频| 亚洲午夜私人影院| 欧美一区二区免费观在线| 午夜影视日本亚洲欧洲精品| 欧美精品18+| 午夜欧美电影在线观看| 欧美三级电影网站| 日韩专区一卡二卡| 在线不卡免费av| 男女激情视频一区| 亚洲精品一区二区三区四区高清| 日本特黄久久久高潮| 日韩欧美国产综合| 国产成人在线视频免费播放| 久久久91精品国产一区二区精品| 国产白丝精品91爽爽久久| 国产日韩视频一区二区三区| 成人中文字幕电影| 亚洲色图视频网站| 亚洲天天做日日做天天谢日日欢| 91在线porny国产在线看| 亚洲一区在线电影| 日韩一级在线观看| 丁香婷婷综合色啪| 亚洲国产欧美一区二区三区丁香婷| 91久久精品日日躁夜夜躁欧美| 亚洲国产va精品久久久不卡综合| 日韩视频在线你懂得| 丰满少妇在线播放bd日韩电影| 亚洲激情图片qvod| 日韩欧美三级在线| 色哟哟一区二区在线观看| 免费三级欧美电影| 洋洋成人永久网站入口| 精品成人私密视频| 欧美午夜影院一区| 国产成人综合在线观看| 亚洲一区二区三区四区的| 久久久亚洲精品石原莉奈| 欧美午夜精品一区| 99久久精品情趣| 国产精品一区二区视频| 日日噜噜夜夜狠狠视频欧美人| 欧美激情综合网| 久久众筹精品私拍模特| 宅男在线国产精品| 一本色道a无线码一区v| 成人免费视频一区| 国产91丝袜在线播放0| 美女视频免费一区| 亚洲成人免费电影| 性欧美疯狂xxxxbbbb| 一区二区三区精品视频| 国产精品三级视频| 国产欧美一区二区精品性色超碰| 欧美一级精品在线| 日韩欧美在线影院| 日韩丝袜美女视频| 日韩免费性生活视频播放| 欧美一区二区三区在线观看视频 | 亚洲人成小说网站色在线| www日韩大片| 2023国产精品视频| 国产午夜精品一区二区三区四区| 久久精品视频一区二区三区| 精品国产成人系列| 国产三级欧美三级| 亚洲国产精品v| 一区二区三区在线视频免费| 国产精品美女久久久久久久网站| 欧美激情一区二区三区在线| 久久精品亚洲乱码伦伦中文| 国产清纯美女被跳蛋高潮一区二区久久w | 国产69精品久久99不卡| 国产成人综合在线观看| 99re热视频这里只精品| 色婷婷综合中文久久一本| 欧美日韩卡一卡二| 精品国产免费人成电影在线观看四季| 在线成人av网站| 精品国产髙清在线看国产毛片| 精品毛片乱码1区2区3区| 国产精品久久久久久一区二区三区| 国产精品久久国产精麻豆99网站| 亚洲五码中文字幕| 狠狠色狠狠色综合系列| 国产91精品一区二区| 欧美天天综合网| 欧美一区二区三区公司| 亚洲欧洲无码一区二区三区| 日韩电影网1区2区| 91丨国产丨九色丨pron| 久久日韩粉嫩一区二区三区| 亚洲欧美另类图片小说| 国内精品免费**视频| 欧美二区在线观看| 亚洲三级在线观看| 国产电影一区在线| 日韩欧美国产高清| 日日夜夜精品免费视频| 色妹子一区二区| 亚洲欧洲三级电影| 国产69精品一区二区亚洲孕妇| 日韩一区二区三区精品视频| 亚洲午夜在线电影| 91香蕉国产在线观看软件| 中文天堂在线一区| 国产福利91精品一区二区三区| 91精品国产麻豆| 精品99999| 看国产成人h片视频| 欧美一区三区四区| 亚洲成人手机在线| 日韩免费高清视频| 免费成人在线观看| 日韩免费高清视频| 九色综合国产一区二区三区| 5858s免费视频成人| 美女任你摸久久| 久久先锋资源网| 成av人片一区二区| 亚洲最快最全在线视频| 欧美色成人综合| 国产一区二区在线观看免费| 国产三区在线成人av| 成人教育av在线| 亚洲一区视频在线观看视频| 6080日韩午夜伦伦午夜伦| 久久国产剧场电影| 国产精品美女www爽爽爽| 在线观看精品一区| 精品写真视频在线观看| 中文字幕一区二区三区在线观看 | 老司机午夜精品| 久久这里只精品最新地址| av中文字幕亚洲| 久久精品久久久精品美女| 国产精品色一区二区三区| 91精品国产综合久久久久| 国产精品资源站在线| 天天做天天摸天天爽国产一区 | 欧美性受xxxx黑人xyx性爽|