SharedDIBSurface.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_gfx_SharedDIBSurface_h
  6. #define mozilla_gfx_SharedDIBSurface_h
  7. #include "gfxImageSurface.h"
  8. #include "SharedDIBWin.h"
  9. #include <windows.h>
  10. namespace mozilla {
  11. namespace gfx {
  12. /**
  13. * A SharedDIBSurface owns an underlying SharedDIBWin.
  14. */
  15. class SharedDIBSurface : public gfxImageSurface
  16. {
  17. public:
  18. typedef base::SharedMemoryHandle Handle;
  19. SharedDIBSurface() { }
  20. ~SharedDIBSurface() { }
  21. /**
  22. * Create this image surface backed by shared memory.
  23. */
  24. bool Create(HDC adc, uint32_t aWidth, uint32_t aHeight, bool aTransparent);
  25. /**
  26. * Attach this surface to shared memory from another process.
  27. */
  28. bool Attach(Handle aHandle, uint32_t aWidth, uint32_t aHeight,
  29. bool aTransparent);
  30. /**
  31. * After drawing to a surface via GDI, GDI must be flushed before the bitmap
  32. * is valid.
  33. */
  34. void Flush() { ::GdiFlush(); }
  35. HDC GetHDC() { return mSharedDIB.GetHDC(); }
  36. nsresult ShareToProcess(base::ProcessId aTargetPid, Handle* aNewHandle) {
  37. return mSharedDIB.ShareToProcess(aTargetPid, aNewHandle);
  38. }
  39. static bool IsSharedDIBSurface(gfxASurface* aSurface);
  40. private:
  41. SharedDIBWin mSharedDIB;
  42. void InitSurface(uint32_t aWidth, uint32_t aHeight, bool aTransparent);
  43. };
  44. } // namespace gfx
  45. } // namespace mozilla
  46. #endif // mozilla_gfx_SharedDIBSurface_h