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

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

?? allocator.pas

?? DSPack is a set of Components and class to write Multimedia Applications using MS Direct Show and Di
?? 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一区二区三区免费野_久草精品视频
蜜桃一区二区三区在线| 99精品在线观看视频| 国产成人aaa| 欧美图区在线视频| 日本一区二区免费在线| 日本视频一区二区三区| 成人激情小说乱人伦| 日韩欧美国产综合在线一区二区三区| 亚洲视频在线一区观看| 国产精品一区二区视频| 欧美一区二区网站| 一区二区久久久| 91影视在线播放| 国产精品久久看| 国产激情一区二区三区四区 | 亚洲欧美色图小说| 91女神在线视频| 久久久久久久精| 精品在线观看视频| 777xxx欧美| 丝袜美腿高跟呻吟高潮一区| 色天天综合色天天久久| 亚洲欧美日韩国产综合| 成人三级伦理片| 国产欧美综合在线观看第十页 | 尤物av一区二区| 不卡av在线免费观看| 日本一区二区免费在线| 国产成人高清在线| 精品国产一区二区亚洲人成毛片| 美女视频一区在线观看| 日韩一区二区在线看片| 人禽交欧美网站| 欧美不卡一区二区| 日本va欧美va精品| www激情久久| 国产精品资源网站| 欧美国产综合色视频| 99久久久国产精品免费蜜臀| 亚洲欧美区自拍先锋| 91小视频在线观看| 亚洲成人资源在线| 欧美一区二区三区免费| 精品一区二区在线播放| 久久综合狠狠综合久久综合88| 国产乱码一区二区三区| 国产精品免费aⅴ片在线观看| av日韩在线网站| 亚洲欧美日韩国产综合在线| 欧美日韩三级一区二区| 蜜臀av在线播放一区二区三区| 欧美大片在线观看| 国产.精品.日韩.另类.中文.在线.播放| 中文字幕不卡在线观看| 欧美自拍丝袜亚洲| 久久99久久久久久久久久久| 国产亚洲欧美在线| 欧美中文字幕亚洲一区二区va在线 | 亚洲欧美日韩一区二区三区在线观看| 97成人超碰视| 日韩中文字幕亚洲一区二区va在线 | 欧美v国产在线一区二区三区| 韩国视频一区二区| 中文字幕一区二区在线观看| 欧美色综合网站| 精品亚洲成a人| 亚洲精品视频免费观看| 中文字幕中文在线不卡住| 欧美日韩另类国产亚洲欧美一级| 精品一区二区三区久久| 亚洲精品精品亚洲| 精品国产乱码久久久久久图片 | 蜜桃视频第一区免费观看| 久久久99精品免费观看| 欧美性一二三区| 国产精品一级在线| 视频一区中文字幕国产| 国产精品国产自产拍在线| 欧美一卡二卡在线观看| 99v久久综合狠狠综合久久| 日本欧美肥老太交大片| 亚洲视频在线一区二区| www久久精品| 欧美电影一区二区| 色婷婷综合视频在线观看| 激情文学综合网| 亚洲综合自拍偷拍| 国产精品美女久久久久久久久久久| 欧美精品在线观看一区二区| 不卡av免费在线观看| 国产一区二区三区在线观看免费视频| 亚洲综合丁香婷婷六月香| 国产精品欧美精品| 久久久www成人免费毛片麻豆 | 99re热这里只有精品免费视频| 秋霞电影一区二区| 亚洲一卡二卡三卡四卡| 国产精品福利一区二区| 久久精品欧美一区二区三区麻豆| 91精品国产综合久久香蕉麻豆| 色8久久人人97超碰香蕉987| 不卡欧美aaaaa| 高清久久久久久| 国产精品一区免费在线观看| 久久成人av少妇免费| 日韩激情一二三区| 日韩专区中文字幕一区二区| 亚洲午夜视频在线观看| 亚洲一区日韩精品中文字幕| 综合久久久久久| 综合欧美一区二区三区| 综合激情网...| 亚洲伦理在线精品| 亚洲日本韩国一区| 玉足女爽爽91| 亚洲香蕉伊在人在线观| 亚洲国产精品久久艾草纯爱| 亚洲午夜在线观看视频在线| 亚洲成人av电影| 午夜不卡av在线| 七七婷婷婷婷精品国产| 久久精品国产99| 国产一区二区三区不卡在线观看| 欧美精品久久99久久在免费线| 欧美日韩高清一区二区| 3d动漫精品啪啪一区二区竹菊| 日韩一级片在线播放| 欧美电影免费观看高清完整版在线| 日韩欧美国产高清| 国产视频一区二区在线| 一区二区中文视频| 午夜影院久久久| 老汉av免费一区二区三区 | 成人h动漫精品一区二| 9i看片成人免费高清| 色88888久久久久久影院按摩| 欧美性猛片aaaaaaa做受| 欧美一级在线免费| 国产午夜精品久久久久久免费视| 1区2区3区精品视频| 性感美女久久精品| 国产一本一道久久香蕉| 99re热视频这里只精品| 3d成人动漫网站| 国产欧美日韩久久| 亚洲国产aⅴ天堂久久| 国内精品在线播放| 色综合久久综合网欧美综合网| 欧美乱妇15p| 国产欧美日韩综合精品一区二区| 亚洲欧美偷拍三级| 精品亚洲aⅴ乱码一区二区三区| 99久久免费精品高清特色大片| 欧美日韩国产小视频| 国产日韩成人精品| 日日欢夜夜爽一区| 99视频超级精品| 日韩一级大片在线| 一区二区在线看| 国产精品一品二品| 91精品国产综合久久福利| 国产精品情趣视频| 久久99精品国产麻豆婷婷洗澡| 色综合久久66| 久久精品无码一区二区三区| 婷婷国产在线综合| 99热精品一区二区| 26uuu精品一区二区在线观看| 樱花草国产18久久久久| 国产一区在线看| 日韩三级.com| 亚洲一区二区五区| 91性感美女视频| 国产午夜精品理论片a级大结局| 首页亚洲欧美制服丝腿| 日本精品视频一区二区| 国产精品免费网站在线观看| 美女在线观看视频一区二区| 欧美性三三影院| 亚洲少妇屁股交4| 成人动漫在线一区| 国产片一区二区| 国产一区啦啦啦在线观看| 日韩三级精品电影久久久| 亚洲成人综合视频| 欧美日韩一区三区四区| 亚洲精品菠萝久久久久久久| 成人午夜电影久久影院| 久久人人97超碰com| 麻豆久久久久久久| 欧美电影免费观看高清完整版在 | 日产欧产美韩系列久久99| 欧洲精品一区二区三区在线观看| 中文字幕在线不卡一区二区三区 | 中文av字幕一区| 国产成人免费在线观看| 久久久亚洲精华液精华液精华液| 久久99国产精品久久99| 精品国产电影一区二区| 久久99国产精品免费网站|