desktop_frame_cgimage.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef MODULES_DESKTOP_CAPTURE_MAC_DESKTOP_FRAME_CGIMAGE_H_
  11. #define MODULES_DESKTOP_CAPTURE_MAC_DESKTOP_FRAME_CGIMAGE_H_
  12. #include <CoreGraphics/CoreGraphics.h>
  13. #include <memory>
  14. #include "modules/desktop_capture/desktop_frame.h"
  15. #include "sdk/objc/helpers/scoped_cftyperef.h"
  16. namespace webrtc {
  17. class DesktopFrameCGImage final : public DesktopFrame {
  18. public:
  19. // Create an image containing a snapshot of the display at the time this is
  20. // being called.
  21. static std::unique_ptr<DesktopFrameCGImage> CreateForDisplay(
  22. CGDirectDisplayID display_id);
  23. // Create an image containing a snaphot of the given window at the time this
  24. // is being called. This also works when the window is overlapped or in
  25. // another workspace.
  26. static std::unique_ptr<DesktopFrameCGImage> CreateForWindow(
  27. CGWindowID window_id);
  28. ~DesktopFrameCGImage() override;
  29. private:
  30. static std::unique_ptr<DesktopFrameCGImage> CreateFromCGImage(
  31. rtc::ScopedCFTypeRef<CGImageRef> cg_image);
  32. // This constructor expects |cg_image| to hold a non-null CGImageRef.
  33. DesktopFrameCGImage(DesktopSize size,
  34. int stride,
  35. uint8_t* data,
  36. rtc::ScopedCFTypeRef<CGImageRef> cg_image,
  37. rtc::ScopedCFTypeRef<CFDataRef> cg_data);
  38. const rtc::ScopedCFTypeRef<CGImageRef> cg_image_;
  39. const rtc::ScopedCFTypeRef<CFDataRef> cg_data_;
  40. RTC_DISALLOW_COPY_AND_ASSIGN(DesktopFrameCGImage);
  41. };
  42. } // namespace webrtc
  43. #endif // MODULES_DESKTOP_CAPTURE_MAC_DESKTOP_FRAME_CGIMAGE_H_