text_detection_impl_win.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef SERVICES_SHAPE_DETECTION_TEXT_DETECTION_IMPL_WIN_H_
  5. #define SERVICES_SHAPE_DETECTION_TEXT_DETECTION_IMPL_WIN_H_
  6. #include <windows.graphics.imaging.h>
  7. #include <windows.media.ocr.h>
  8. #include <wrl/client.h>
  9. #include <memory>
  10. #include <utility>
  11. #include <vector>
  12. #include "base/memory/weak_ptr.h"
  13. #include "mojo/public/cpp/bindings/self_owned_receiver.h"
  14. #include "services/shape_detection/public/mojom/textdetection.mojom.h"
  15. class SkBitmap;
  16. namespace shape_detection {
  17. class TextDetectionImplWin : public mojom::TextDetection {
  18. public:
  19. TextDetectionImplWin(
  20. Microsoft::WRL::ComPtr<ABI::Windows::Media::Ocr::IOcrEngine> ocr_engine,
  21. Microsoft::WRL::ComPtr<
  22. ABI::Windows::Graphics::Imaging::ISoftwareBitmapStatics>
  23. bitmap_factory);
  24. TextDetectionImplWin(const TextDetectionImplWin&) = delete;
  25. TextDetectionImplWin& operator=(const TextDetectionImplWin&) = delete;
  26. ~TextDetectionImplWin() override;
  27. // mojom::TextDetection implementation.
  28. void Detect(const SkBitmap& bitmap,
  29. mojom::TextDetection::DetectCallback callback) override;
  30. void SetReceiver(mojo::SelfOwnedReceiverRef<mojom::TextDetection> receiver) {
  31. receiver_ = std::move(receiver);
  32. }
  33. private:
  34. Microsoft::WRL::ComPtr<ABI::Windows::Media::Ocr::IOcrEngine> ocr_engine_;
  35. Microsoft::WRL::ComPtr<
  36. ABI::Windows::Graphics::Imaging::ISoftwareBitmapStatics>
  37. bitmap_factory_;
  38. DetectCallback recognize_text_callback_;
  39. mojo::SelfOwnedReceiverRef<mojom::TextDetection> receiver_;
  40. HRESULT BeginDetect(const SkBitmap& bitmap);
  41. std::vector<mojom::TextDetectionResultPtr> BuildTextDetectionResult(
  42. Microsoft::WRL::ComPtr<ABI::Windows::Media::Ocr::IOcrResult> ocr_result);
  43. void OnTextDetected(
  44. Microsoft::WRL::ComPtr<ABI::Windows::Graphics::Imaging::ISoftwareBitmap>
  45. win_bitmap,
  46. Microsoft::WRL::ComPtr<ABI::Windows::Media::Ocr::IOcrResult> ocr_result);
  47. base::WeakPtrFactory<TextDetectionImplWin> weak_factory_{this};
  48. };
  49. } // namespace shape_detection
  50. #endif // SERVICES_SHAPE_DETECTION_TEXT_DETECTION_IMPL_WIN_H_