delegated_ink_point.cc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2020 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. #include "ui/gfx/delegated_ink_point.h"
  5. #include <inttypes.h>
  6. #include "base/strings/stringprintf.h"
  7. #include "ui/gfx/delegated_ink_metadata.h"
  8. namespace gfx {
  9. bool DelegatedInkPoint::MatchesDelegatedInkMetadata(
  10. const DelegatedInkMetadata* metadata) const {
  11. // The maximum difference allowed when comparing a DelegatedInkPoint |point_|
  12. // to the |point_| on a DelegatedInkMetadata. Some precision loss can occur
  13. // when moving between coordinate spaces in the browser and renderer,
  14. // particularly when the device scale factor is not a whole number. This can
  15. // result in a DelegatedInkMetadata and DelegatedInkPoint having been created
  16. // from the same point, but having a very small difference. When this occurs,
  17. // we can safely ignore that they are slightly different and use the point for
  18. // a delegated ink trail anyway, since it is a very small difference and will
  19. // only be visible for a single frame.
  20. constexpr float kEpsilon = 0.05f;
  21. return metadata && timestamp_ == metadata->timestamp() &&
  22. point_.IsWithinDistance(metadata->point(), kEpsilon);
  23. }
  24. std::string DelegatedInkPoint::ToString() const {
  25. return base::StringPrintf("point: %s, timestamp: %" PRId64 ", pointer_id: %d",
  26. point_.ToString().c_str(),
  27. timestamp_.since_origin().InMicroseconds(),
  28. pointer_id_);
  29. }
  30. } // namespace gfx