Commit ac488bf5 authored by junweifu's avatar junweifu Committed by Commit Bot

ShapeDetection: Simplify the usage of AsyncOperation on windows 10

Since this operation is not cancellable, it's better to guarantee that
|AsyncCallbackInternal| will be called instead of canceling, but |callback_|
still need to take weak reference count so that it will not be run if its object
has been already destroyed. This would simplify callers since they would not need
to own the result returned by Create.

BUG=790843

Cq-Include-Trybots: master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win10_chromium_x64_rel_ng
Change-Id: I640cbe769c999ef20d6b9310038023c4fd3d7714
Reviewed-on: https://chromium-review.googlesource.com/968121Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarMiguel Casas <mcasas@chromium.org>
Commit-Queue: Junwei Fu <junwei.fu@intel.com>
Cr-Commit-Position: refs/heads/master@{#545688}
parent 3e18a7bb
...@@ -9,17 +9,12 @@ ...@@ -9,17 +9,12 @@
#include <wrl/client.h> #include <wrl/client.h>
#include <wrl/event.h> #include <wrl/event.h>
#include <wrl/implements.h> #include <wrl/implements.h>
#include <memory>
#include <utility> #include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/location.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/sequenced_task_runner.h" #include "base/sequenced_task_runner.h"
class SkBitmap; class SkBitmap;
...@@ -35,10 +30,8 @@ using ABI::Windows::Graphics::Imaging::ISoftwareBitmap; ...@@ -35,10 +30,8 @@ using ABI::Windows::Graphics::Imaging::ISoftwareBitmap;
using ABI::Windows::Graphics::Imaging::BitmapPixelFormat; using ABI::Windows::Graphics::Imaging::BitmapPixelFormat;
// This template represents an asynchronous operation which returns a result // This template represents an asynchronous operation which returns a result
// upon completion, internal async callback will be not called if the instance // upon completion, |callback_| will not be run if its object has been already
// is deleted. RuntimeType is Windows Runtime APIs that has a result. // destroyed.
// TODO(junwei.fu): https://crbug.com/791371 consider moving the implementation
// of AsyncOperation to .cc file.
template <typename RuntimeType> template <typename RuntimeType>
class AsyncOperation { class AsyncOperation {
public: public:
...@@ -52,14 +45,11 @@ class AsyncOperation { ...@@ -52,14 +45,11 @@ class AsyncOperation {
// Creates an AsyncOperation instance which sets |callback| to be called when // Creates an AsyncOperation instance which sets |callback| to be called when
// the asynchronous action completes. // the asynchronous action completes.
static std::unique_ptr<AsyncOperation<RuntimeType>> Create( static HRESULT BeginAsyncOperation(Callback callback,
Callback callback, IAsyncOperationPtr async_op_ptr) {
IAsyncOperationPtr async_op_ptr) { auto instance =
auto instance = base::WrapUnique( new AsyncOperation<RuntimeType>(std::move(callback), async_op_ptr);
new AsyncOperation<RuntimeType>(std::move(callback), async_op_ptr));
base::WeakPtr<AsyncOperation> weak_ptr =
instance->weak_factory_.GetWeakPtr();
scoped_refptr<base::SequencedTaskRunner> task_runner = scoped_refptr<base::SequencedTaskRunner> task_runner =
base::SequencedTaskRunnerHandle::Get(); base::SequencedTaskRunnerHandle::Get();
...@@ -68,33 +58,25 @@ class AsyncOperation { ...@@ -68,33 +58,25 @@ class AsyncOperation {
WRL::FtmBase> WRL::FtmBase>
AsyncCallback; AsyncCallback;
auto async_callback = WRL::Callback<AsyncCallback>( auto async_callback = WRL::Callback<AsyncCallback>(
[weak_ptr, task_runner](IAsyncOperation<RuntimeType*>* async_op, [instance, task_runner](IAsyncOperation<RuntimeType*>* async_op,
AsyncStatus status) { AsyncStatus status) {
// A reference to |async_op| is kept in |async_op_ptr_|, safe to pass // A reference to |async_op| is kept in |async_op_ptr_|, safe to pass
// outside. This is happening on an OS thread. // outside. This is happening on an OS thread.
task_runner->PostTask( task_runner->PostTask(
FROM_HERE, base::BindOnce(&AsyncOperation::AsyncCallbackInternal, FROM_HERE, base::BindOnce(&AsyncOperation::AsyncCallbackInternal,
std::move(weak_ptr), base::Owned(instance),
base::Unretained(async_op), status)); base::Unretained(async_op), status));
return S_OK; return S_OK;
}); });
const HRESULT hr = async_op_ptr->put_Completed(async_callback.Get()); return async_op_ptr->put_Completed(async_callback.Get());
if (FAILED(hr)) {
DLOG(ERROR) << "Async put completed failed: "
<< logging::SystemErrorCodeToString(hr);
return nullptr;
}
return instance;
} }
private: private:
AsyncOperation(Callback callback, IAsyncOperationPtr async_op_ptr) AsyncOperation(Callback callback, IAsyncOperationPtr async_op_ptr)
: async_op_ptr_(std::move(async_op_ptr)), : async_op_ptr_(std::move(async_op_ptr)),
callback_(std::move(callback)), callback_(std::move(callback)) {}
weak_factory_(this) {}
void AsyncCallbackInternal(IAsyncOperation<RuntimeType*>* async_op, void AsyncCallbackInternal(IAsyncOperation<RuntimeType*>* async_op,
AsyncStatus status) { AsyncStatus status) {
...@@ -107,9 +89,6 @@ class AsyncOperation { ...@@ -107,9 +89,6 @@ class AsyncOperation {
IAsyncOperationPtr async_op_ptr_; IAsyncOperationPtr async_op_ptr_;
Callback callback_; Callback callback_;
// TODO(junwei.fu): https://crbug.com/790843 guarantee |callback_| will be
// called instead of canceling the callback if this object is freed.
base::WeakPtrFactory<AsyncOperation<RuntimeType>> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(AsyncOperation); DISALLOW_COPY_AND_ASSIGN(AsyncOperation);
}; };
......
...@@ -23,7 +23,8 @@ FaceDetectionImplWin::FaceDetectionImplWin( ...@@ -23,7 +23,8 @@ FaceDetectionImplWin::FaceDetectionImplWin(
BitmapPixelFormat pixel_format) BitmapPixelFormat pixel_format)
: face_detector_(std::move(face_detector)), : face_detector_(std::move(face_detector)),
bitmap_factory_(std::move(bitmap_factory)), bitmap_factory_(std::move(bitmap_factory)),
pixel_format_(pixel_format) { pixel_format_(pixel_format),
weak_factory_(this) {
DCHECK(face_detector_); DCHECK(face_detector_);
DCHECK(bitmap_factory_); DCHECK(bitmap_factory_);
} }
...@@ -31,25 +32,24 @@ FaceDetectionImplWin::~FaceDetectionImplWin() = default; ...@@ -31,25 +32,24 @@ FaceDetectionImplWin::~FaceDetectionImplWin() = default;
void FaceDetectionImplWin::Detect(const SkBitmap& bitmap, void FaceDetectionImplWin::Detect(const SkBitmap& bitmap,
DetectCallback callback) { DetectCallback callback) {
if ((async_detect_face_ops_ = BeginDetect(bitmap))) { if (FAILED(BeginDetect(bitmap))) {
// Hold on the callback until AsyncOperation completes.
detected_face_callback_ = std::move(callback);
// This prevents the Detect function from being called before the
// AsyncOperation completes.
binding_->PauseIncomingMethodCallProcessing();
} else {
// No detection taking place; run |callback| with an empty array of results. // No detection taking place; run |callback| with an empty array of results.
std::move(callback).Run(std::vector<mojom::FaceDetectionResultPtr>()); std::move(callback).Run(std::vector<mojom::FaceDetectionResultPtr>());
return;
} }
// Hold on the callback until AsyncOperation completes.
detected_face_callback_ = std::move(callback);
// This prevents the Detect function from being called before the
// AsyncOperation completes.
binding_->PauseIncomingMethodCallProcessing();
} }
std::unique_ptr<AsyncOperation<IVector<DetectedFace*>>> HRESULT FaceDetectionImplWin::BeginDetect(const SkBitmap& bitmap) {
FaceDetectionImplWin::BeginDetect(const SkBitmap& bitmap) {
Microsoft::WRL::ComPtr<ISoftwareBitmap> win_bitmap = Microsoft::WRL::ComPtr<ISoftwareBitmap> win_bitmap =
CreateWinBitmapWithPixelFormat(bitmap, bitmap_factory_.Get(), CreateWinBitmapWithPixelFormat(bitmap, bitmap_factory_.Get(),
pixel_format_); pixel_format_);
if (!win_bitmap) if (!win_bitmap)
return nullptr; return E_FAIL;
// Detect faces asynchronously. // Detect faces asynchronously.
AsyncOperation<IVector<DetectedFace*>>::IAsyncOperationPtr async_op; AsyncOperation<IVector<DetectedFace*>>::IAsyncOperationPtr async_op;
...@@ -58,15 +58,15 @@ FaceDetectionImplWin::BeginDetect(const SkBitmap& bitmap) { ...@@ -58,15 +58,15 @@ FaceDetectionImplWin::BeginDetect(const SkBitmap& bitmap) {
if (FAILED(hr)) { if (FAILED(hr)) {
DLOG(ERROR) << "Detect faces asynchronously failed: " DLOG(ERROR) << "Detect faces asynchronously failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
return nullptr; return hr;
} }
// The once callback will not be called if this object is deleted, so it's // Use WeakPtr to bind the callback so that the once callback will not be run
// fine to use Unretained to bind the callback. |win_bitmap| needs to be kept // if this object has been already destroyed. |win_bitmap| needs to be kept
// alive until OnFaceDetected(). // alive until OnFaceDetected().
return AsyncOperation<IVector<DetectedFace*>>::Create( return AsyncOperation<IVector<DetectedFace*>>::BeginAsyncOperation(
base::BindOnce(&FaceDetectionImplWin::OnFaceDetected, base::BindOnce(&FaceDetectionImplWin::OnFaceDetected,
base::Unretained(this), std::move(win_bitmap)), weak_factory_.GetWeakPtr(), std::move(win_bitmap)),
std::move(async_op)); std::move(async_op));
} }
...@@ -117,7 +117,6 @@ void FaceDetectionImplWin::OnFaceDetected( ...@@ -117,7 +117,6 @@ void FaceDetectionImplWin::OnFaceDetected(
AsyncOperation<IVector<DetectedFace*>>::IAsyncOperationPtr async_op) { AsyncOperation<IVector<DetectedFace*>>::IAsyncOperationPtr async_op) {
std::move(detected_face_callback_) std::move(detected_face_callback_)
.Run(BuildFaceDetectionResult(std::move(async_op))); .Run(BuildFaceDetectionResult(std::move(async_op)));
async_detect_face_ops_.reset();
binding_->ResumeIncomingMethodCallProcessing(); binding_->ResumeIncomingMethodCallProcessing();
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <vector> #include <vector>
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/strong_binding.h"
#include "services/shape_detection/detection_utils_win.h" #include "services/shape_detection/detection_utils_win.h"
#include "services/shape_detection/public/mojom/facedetection.mojom.h" #include "services/shape_detection/public/mojom/facedetection.mojom.h"
...@@ -49,8 +50,7 @@ class FaceDetectionImplWin : public mojom::FaceDetection { ...@@ -49,8 +50,7 @@ class FaceDetectionImplWin : public mojom::FaceDetection {
mojom::FaceDetection::DetectCallback callback) override; mojom::FaceDetection::DetectCallback callback) override;
private: private:
std::unique_ptr<AsyncOperation<IVector<DetectedFace*>>> BeginDetect( HRESULT BeginDetect(const SkBitmap& bitmap);
const SkBitmap& bitmap);
std::vector<mojom::FaceDetectionResultPtr> BuildFaceDetectionResult( std::vector<mojom::FaceDetectionResultPtr> BuildFaceDetectionResult(
AsyncOperation<IVector<DetectedFace*>>::IAsyncOperationPtr async_op); AsyncOperation<IVector<DetectedFace*>>::IAsyncOperationPtr async_op);
void OnFaceDetected( void OnFaceDetected(
...@@ -62,11 +62,11 @@ class FaceDetectionImplWin : public mojom::FaceDetection { ...@@ -62,11 +62,11 @@ class FaceDetectionImplWin : public mojom::FaceDetection {
Microsoft::WRL::ComPtr<ISoftwareBitmapStatics> bitmap_factory_; Microsoft::WRL::ComPtr<ISoftwareBitmapStatics> bitmap_factory_;
BitmapPixelFormat pixel_format_; BitmapPixelFormat pixel_format_;
std::unique_ptr<AsyncOperation<IVector<DetectedFace*>>>
async_detect_face_ops_;
DetectCallback detected_face_callback_; DetectCallback detected_face_callback_;
mojo::StrongBindingPtr<mojom::FaceDetection> binding_; mojo::StrongBindingPtr<mojom::FaceDetection> binding_;
base::WeakPtrFactory<FaceDetectionImplWin> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(FaceDetectionImplWin); DISALLOW_COPY_AND_ASSIGN(FaceDetectionImplWin);
}; };
......
...@@ -41,13 +41,6 @@ BitmapPixelFormat GetPreferredPixelFormat(IFaceDetectorStatics* factory) { ...@@ -41,13 +41,6 @@ BitmapPixelFormat GetPreferredPixelFormat(IFaceDetectorStatics* factory) {
void FaceDetectionProviderWin::CreateFaceDetection( void FaceDetectionProviderWin::CreateFaceDetection(
shape_detection::mojom::FaceDetectionRequest request, shape_detection::mojom::FaceDetectionRequest request,
shape_detection::mojom::FaceDetectorOptionsPtr options) { shape_detection::mojom::FaceDetectorOptionsPtr options) {
if (async_create_detector_ops_) {
mojo::ReportBadMessage(
"FaceDetectionProvider client may only create one FaceDetection at a "
"time.");
return;
}
// FaceDetector class is only available in Win 10 onwards (v10.0.10240.0). // FaceDetector class is only available in Win 10 onwards (v10.0.10240.0).
if (base::win::GetVersion() < base::win::VERSION_WIN10) { if (base::win::GetVersion() < base::win::VERSION_WIN10) {
DVLOG(1) << "FaceDetector not supported before Windows 10"; DVLOG(1) << "FaceDetector not supported before Windows 10";
...@@ -93,24 +86,28 @@ void FaceDetectionProviderWin::CreateFaceDetection( ...@@ -93,24 +86,28 @@ void FaceDetectionProviderWin::CreateFaceDetection(
return; return;
} }
// The once callback will not be called if this object is deleted, so it's // Use WeakPtr to bind the callback so that the once callback will not be run
// fine to use Unretained to bind the callback. // if this object has been already destroyed.
auto async_operation = AsyncOperation<FaceDetector>::Create( hr = AsyncOperation<FaceDetector>::BeginAsyncOperation(
base::BindOnce(&FaceDetectionProviderWin::OnFaceDetectorCreated, base::BindOnce(&FaceDetectionProviderWin::OnFaceDetectorCreated,
base::Unretained(this), std::move(request), pixel_format), weak_factory_.GetWeakPtr(), std::move(request),
pixel_format),
std::move(async_op)); std::move(async_op));
if (!async_operation) if (FAILED(hr)) {
DLOG(ERROR) << "Begin async operation failed: "
<< logging::SystemErrorCodeToString(hr);
return; return;
}
async_create_detector_ops_ = std::move(async_operation); // When |provider| goes out of scope it will immediately close its end of
// When |provider| goes out of scope it will immediately closes its end of // the message pipe, then the callback OnFaceDetectorCreated will be not
// the message pipe, then |async_create_detector_ops_| will be deleted and the // called. This prevents this object from being destroyed before the
// callback OnFaceDetectorCreated will be not called. This prevents this // AsyncOperation completes.
// object from being destroyed before the AsyncOperation completes.
binding_->PauseIncomingMethodCallProcessing(); binding_->PauseIncomingMethodCallProcessing();
} }
FaceDetectionProviderWin::FaceDetectionProviderWin() = default; FaceDetectionProviderWin::FaceDetectionProviderWin() : weak_factory_(this) {}
FaceDetectionProviderWin::~FaceDetectionProviderWin() = default; FaceDetectionProviderWin::~FaceDetectionProviderWin() = default;
void FaceDetectionProviderWin::OnFaceDetectorCreated( void FaceDetectionProviderWin::OnFaceDetectorCreated(
...@@ -118,7 +115,6 @@ void FaceDetectionProviderWin::OnFaceDetectorCreated( ...@@ -118,7 +115,6 @@ void FaceDetectionProviderWin::OnFaceDetectorCreated(
BitmapPixelFormat pixel_format, BitmapPixelFormat pixel_format,
AsyncOperation<FaceDetector>::IAsyncOperationPtr async_op) { AsyncOperation<FaceDetector>::IAsyncOperationPtr async_op) {
binding_->ResumeIncomingMethodCallProcessing(); binding_->ResumeIncomingMethodCallProcessing();
async_create_detector_ops_.reset();
Microsoft::WRL::ComPtr<IFaceDetector> face_detector; Microsoft::WRL::ComPtr<IFaceDetector> face_detector;
HRESULT hr = HRESULT hr =
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <utility> #include <utility>
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/strong_binding.h"
#include "services/shape_detection/detection_utils_win.h" #include "services/shape_detection/detection_utils_win.h"
#include "services/shape_detection/face_detection_impl_win.h" #include "services/shape_detection/face_detection_impl_win.h"
...@@ -48,7 +49,7 @@ class FaceDetectionProviderWin ...@@ -48,7 +49,7 @@ class FaceDetectionProviderWin
FRIEND_TEST_ALL_PREFIXES(FaceDetectionImplWinTest, ScanOneFace); FRIEND_TEST_ALL_PREFIXES(FaceDetectionImplWinTest, ScanOneFace);
mojo::StrongBindingPtr<mojom::FaceDetectionProvider> binding_; mojo::StrongBindingPtr<mojom::FaceDetectionProvider> binding_;
std::unique_ptr<AsyncOperation<FaceDetector>> async_create_detector_ops_; base::WeakPtrFactory<FaceDetectionProviderWin> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(FaceDetectionProviderWin); DISALLOW_COPY_AND_ASSIGN(FaceDetectionProviderWin);
}; };
......
...@@ -115,7 +115,8 @@ TextDetectionImplWin::TextDetectionImplWin( ...@@ -115,7 +115,8 @@ TextDetectionImplWin::TextDetectionImplWin(
Microsoft::WRL::ComPtr<IOcrEngine> ocr_engine, Microsoft::WRL::ComPtr<IOcrEngine> ocr_engine,
Microsoft::WRL::ComPtr<ISoftwareBitmapStatics> bitmap_factory) Microsoft::WRL::ComPtr<ISoftwareBitmapStatics> bitmap_factory)
: ocr_engine_(std::move(ocr_engine)), : ocr_engine_(std::move(ocr_engine)),
bitmap_factory_(std::move(bitmap_factory)) { bitmap_factory_(std::move(bitmap_factory)),
weak_factory_(this) {
DCHECK(ocr_engine_); DCHECK(ocr_engine_);
DCHECK(bitmap_factory_); DCHECK(bitmap_factory_);
} }
...@@ -124,24 +125,23 @@ TextDetectionImplWin::~TextDetectionImplWin() = default; ...@@ -124,24 +125,23 @@ TextDetectionImplWin::~TextDetectionImplWin() = default;
void TextDetectionImplWin::Detect(const SkBitmap& bitmap, void TextDetectionImplWin::Detect(const SkBitmap& bitmap,
DetectCallback callback) { DetectCallback callback) {
if ((async_recognize_ops_ = BeginDetect(bitmap))) { if (FAILED(BeginDetect(bitmap))) {
// Hold on the callback until AsyncOperation completes.
recognize_text_callback_ = std::move(callback);
// This prevents the Detect function from being called before the
// AsyncOperation completes.
binding_->PauseIncomingMethodCallProcessing();
} else {
// No detection taking place; run |callback| with an empty array of results. // No detection taking place; run |callback| with an empty array of results.
std::move(callback).Run(std::vector<mojom::TextDetectionResultPtr>()); std::move(callback).Run(std::vector<mojom::TextDetectionResultPtr>());
return;
} }
// Hold on the callback until AsyncOperation completes.
recognize_text_callback_ = std::move(callback);
// This prevents the Detect function from being called before the
// AsyncOperation completes.
binding_->PauseIncomingMethodCallProcessing();
} }
std::unique_ptr<AsyncOperation<OcrResult>> TextDetectionImplWin::BeginDetect( HRESULT TextDetectionImplWin::BeginDetect(const SkBitmap& bitmap) {
const SkBitmap& bitmap) {
Microsoft::WRL::ComPtr<ISoftwareBitmap> win_bitmap = Microsoft::WRL::ComPtr<ISoftwareBitmap> win_bitmap =
CreateWinBitmapFromSkBitmap(bitmap, bitmap_factory_.Get()); CreateWinBitmapFromSkBitmap(bitmap, bitmap_factory_.Get());
if (!win_bitmap) if (!win_bitmap)
return nullptr; return E_FAIL;
// Recognize text asynchronously. // Recognize text asynchronously.
AsyncOperation<OcrResult>::IAsyncOperationPtr async_op; AsyncOperation<OcrResult>::IAsyncOperationPtr async_op;
...@@ -149,15 +149,15 @@ std::unique_ptr<AsyncOperation<OcrResult>> TextDetectionImplWin::BeginDetect( ...@@ -149,15 +149,15 @@ std::unique_ptr<AsyncOperation<OcrResult>> TextDetectionImplWin::BeginDetect(
if (FAILED(hr)) { if (FAILED(hr)) {
DLOG(ERROR) << "Recognize text asynchronously failed: " DLOG(ERROR) << "Recognize text asynchronously failed: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
return nullptr; return hr;
} }
// The once callback will not be called if this object is deleted, so it's // Use WeakPtr to bind the callback so that the once callback will not be run
// fine to use Unretained to bind the callback. // if this object has been already destroyed. |win_bitmap| needs to be kept
// |win_bitmap| needs to be kept alive until OnTextDetected(). // alive until OnTextDetected().
return AsyncOperation<OcrResult>::Create( return AsyncOperation<OcrResult>::BeginAsyncOperation(
base::BindOnce(&TextDetectionImplWin::OnTextDetected, base::BindOnce(&TextDetectionImplWin::OnTextDetected,
base::Unretained(this), std::move(win_bitmap)), weak_factory_.GetWeakPtr(), std::move(win_bitmap)),
std::move(async_op)); std::move(async_op));
} }
...@@ -214,7 +214,6 @@ void TextDetectionImplWin::OnTextDetected( ...@@ -214,7 +214,6 @@ void TextDetectionImplWin::OnTextDetected(
AsyncOperation<OcrResult>::IAsyncOperationPtr async_op) { AsyncOperation<OcrResult>::IAsyncOperationPtr async_op) {
std::move(recognize_text_callback_) std::move(recognize_text_callback_)
.Run(BuildTextDetectionResult(std::move(async_op))); .Run(BuildTextDetectionResult(std::move(async_op)));
async_recognize_ops_.reset();
binding_->ResumeIncomingMethodCallProcessing(); binding_->ResumeIncomingMethodCallProcessing();
} }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <vector> #include <vector>
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/strong_binding.h"
#include "services/shape_detection/detection_utils_win.h" #include "services/shape_detection/detection_utils_win.h"
#include "services/shape_detection/public/mojom/textdetection.mojom.h" #include "services/shape_detection/public/mojom/textdetection.mojom.h"
...@@ -44,17 +45,17 @@ class TextDetectionImplWin : public mojom::TextDetection { ...@@ -44,17 +45,17 @@ class TextDetectionImplWin : public mojom::TextDetection {
private: private:
Microsoft::WRL::ComPtr<IOcrEngine> ocr_engine_; Microsoft::WRL::ComPtr<IOcrEngine> ocr_engine_;
Microsoft::WRL::ComPtr<ISoftwareBitmapStatics> bitmap_factory_; Microsoft::WRL::ComPtr<ISoftwareBitmapStatics> bitmap_factory_;
std::unique_ptr<AsyncOperation<OcrResult>> async_recognize_ops_;
DetectCallback recognize_text_callback_; DetectCallback recognize_text_callback_;
mojo::StrongBindingPtr<mojom::TextDetection> binding_; mojo::StrongBindingPtr<mojom::TextDetection> binding_;
std::unique_ptr<AsyncOperation<OcrResult>> BeginDetect( HRESULT BeginDetect(const SkBitmap& bitmap);
const SkBitmap& bitmap);
std::vector<mojom::TextDetectionResultPtr> BuildTextDetectionResult( std::vector<mojom::TextDetectionResultPtr> BuildTextDetectionResult(
AsyncOperation<OcrResult>::IAsyncOperationPtr async_op); AsyncOperation<OcrResult>::IAsyncOperationPtr async_op);
void OnTextDetected(Microsoft::WRL::ComPtr<ISoftwareBitmap> win_bitmap, void OnTextDetected(Microsoft::WRL::ComPtr<ISoftwareBitmap> win_bitmap,
AsyncOperation<OcrResult>::IAsyncOperationPtr async_op); AsyncOperation<OcrResult>::IAsyncOperationPtr async_op);
base::WeakPtrFactory<TextDetectionImplWin> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(TextDetectionImplWin); DISALLOW_COPY_AND_ASSIGN(TextDetectionImplWin);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment