videoCaptureD3D9.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _VIDEOCAPTURE_H_
  23. #include "gfx/video/videoCapture.h"
  24. #endif
  25. #ifndef _GFXDEVICE_H_
  26. #include "gfx/gfxDevice.h"
  27. #endif
  28. class VideoFrameGrabberD3D9 : public VideoFrameGrabber
  29. {
  30. protected:
  31. enum CaptureStage {
  32. eReadyToCapture,
  33. eInVideoMemory,
  34. eInSystemMemory,
  35. eNumStages
  36. };
  37. // Contains all elements involved in single frame capture and
  38. // is used to spread the multiple "stages" needed to capture a bitmap
  39. // over various frames to keep GPU resources from locking the CPU.
  40. struct CaptureResource {
  41. GFXTexHandle vidMemTex; //Video memory texture
  42. GFXTexHandle sysMemTex; //System memory texture
  43. CaptureStage stage; //This resource's capture stage
  44. CaptureResource() : stage(eReadyToCapture) {};
  45. ~CaptureResource()
  46. {
  47. vidMemTex.free();
  48. sysMemTex.free();
  49. }
  50. };
  51. // Capture resource array. One item for each capture pipeline stage
  52. CaptureResource mCapture[eNumStages];
  53. // Current capture index
  54. S32 mCurrentCapture;
  55. // Copies a capture's video memory content to system memory
  56. void copyToSystemMemory(CaptureResource &capture);
  57. // Copies a capture's syste memory content to a new bitmap
  58. void copyToBitmap(CaptureResource &capture);
  59. bool _handleGFXEvent(GFXDevice::GFXDeviceEventType event);
  60. //------------------------------------------------
  61. // Overloaded from VideoFrameGrabber
  62. //------------------------------------------------
  63. void captureBackBuffer();
  64. void makeBitmap();
  65. void releaseTextures();
  66. public:
  67. VideoFrameGrabberD3D9();
  68. ~VideoFrameGrabberD3D9();
  69. };