Commit 1490393e authored by akaba's avatar akaba Committed by Commit Bot

Allow SurfaceId to be checked against a SurfaceRange

This CL add a method to SurfaceId that allows for checking if the surfaceId is
Inside some SurfaceRange.

Bug: 857575
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel
Change-Id: I7b083c82f84e47dc08b9dd2f2ddf8179889ba26e
Reviewed-on: https://chromium-review.googlesource.com/1145628
Commit-Queue: Andre Kaba <akaba@google.com>
Reviewed-by: default avatarSaman Sami <samans@chromium.org>
Reviewed-by: default avatarFady Samuel <fsamuel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577259}
parent 69c35228
......@@ -215,6 +215,7 @@ viz_source_set("unit_tests") {
"surfaces/local_surface_id_unittest.cc",
"surfaces/parent_local_surface_id_allocator_unittest.cc",
"surfaces/scoped_surface_id_allocator_unittest.cc",
"surfaces/surface_range_unittest.cc",
"yuv_readback_unittest.cc",
]
......
......@@ -23,10 +23,6 @@ std::ostream& operator<<(std::ostream& out,
return out << local_surface_id.ToString();
}
bool LocalSurfaceId::IsSameOrNewerThan(const LocalSurfaceId& other) const {
return IsNewerThan(other) || *this == other;
}
bool LocalSurfaceId::IsNewerThan(const LocalSurfaceId& other) const {
// Sequence numbers can wrap around so look at their difference instead of
// their absolute values.
......@@ -38,4 +34,8 @@ bool LocalSurfaceId::IsNewerThan(const LocalSurfaceId& other) const {
parent_sequence_number_ != other.parent_sequence_number_);
}
bool LocalSurfaceId::IsSameOrNewerThan(const LocalSurfaceId& other) const {
return IsNewerThan(other) || *this == other;
}
} // namespace viz
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "components/viz/common/surfaces/surface_id.h"
#include "components/viz/common/surfaces/surface_range.h"
#include "base/strings/stringprintf.h"
......@@ -18,4 +19,10 @@ std::ostream& operator<<(std::ostream& out, const SurfaceId& surface_id) {
return out << surface_id.ToString();
}
bool SurfaceId::IsNewerThan(const SurfaceId& other) const {
if (frame_sink_id_ != other.frame_sink_id())
return false;
return local_surface_id_.IsNewerThan(other.local_surface_id());
}
} // namespace viz
......@@ -59,6 +59,9 @@ class VIZ_COMMON_EXPORT SurfaceId {
std::string ToString() const;
// Returns whether this SurfaceId was generated after |other|.
bool IsNewerThan(const SurfaceId& other) const;
bool operator==(const SurfaceId& other) const {
return frame_sink_id_ == other.frame_sink_id_ &&
local_surface_id_ == other.local_surface_id_;
......
......@@ -31,6 +31,12 @@ bool SurfaceRange::operator<(const SurfaceRange& other) const {
return std::tie(end_, start_) < std::tie(other.end(), other.start());
}
bool SurfaceRange::IsInRangeExclusive(const SurfaceId& surface_id) const {
if (!start_)
return end_.IsNewerThan(surface_id);
return surface_id.IsNewerThan(*start_) && end_.IsNewerThan(surface_id);
}
bool SurfaceRange::IsValid() const {
if (!end_.is_valid())
return false;
......
......@@ -35,6 +35,10 @@ class VIZ_COMMON_EXPORT SurfaceRange {
bool operator<(const SurfaceRange& other) const;
// Check if |surface_id| is in the surface range and match the frame sink id
// of start and end.
bool IsInRangeExclusive(const SurfaceId& surface_id) const;
bool IsValid() const;
const base::Optional<SurfaceId>& start() const { return start_; }
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/viz/common/surfaces/surface_range.h"
#include "components/viz/common/surfaces/surface_id.h"
#include "base/logging.h"
#include "testing/gtest/include/gtest/gtest.h"
// Verifying that SurfaceId::IsInRangeExclusive works properly.
TEST(SurfaceRangeTest, VerifyInRange) {
viz::FrameSinkId FrameSink1(65564, 0);
viz::FrameSinkId FrameSink2(65565, 0);
const base::UnguessableToken token1 = base::UnguessableToken::Create();
const base::UnguessableToken token2 = base::UnguessableToken::Create();
const viz::SurfaceId start(FrameSink1, viz::LocalSurfaceId(1, 1, token1));
const viz::SurfaceId end(FrameSink1, viz::LocalSurfaceId(2, 2, token1));
const viz::SurfaceRange surface_range1(start, end);
const viz::SurfaceRange surface_range2(base::nullopt, end);
const viz::SurfaceId surface_id1(FrameSink1,
viz::LocalSurfaceId(1, 2, token1));
const viz::SurfaceId surface_id2(FrameSink2,
viz::LocalSurfaceId(1, 2, token2));
const viz::SurfaceId surface_id3(FrameSink1,
viz::LocalSurfaceId(2, 2, token1));
const viz::SurfaceId surface_id4(FrameSink1,
viz::LocalSurfaceId(3, 3, token1));
// |surface_id1| has the right embed token and is inside the range
// (Start,end).
EXPECT_TRUE(surface_range1.IsInRangeExclusive(surface_id1));
// |surface_id1| has the right embed token and inside the range
// (base::nullopt,end).
EXPECT_TRUE(surface_range2.IsInRangeExclusive(surface_id1));
// |surface_id2| has the wrong embed token/FrameSinkId so should be refused.
EXPECT_FALSE(surface_range1.IsInRangeExclusive(surface_id2));
EXPECT_FALSE(surface_range2.IsInRangeExclusive(surface_id2));
// |surface_id3| is not included in the range exclusively.
EXPECT_FALSE(surface_range1.IsInRangeExclusive(surface_id3));
EXPECT_FALSE(surface_range2.IsInRangeExclusive(surface_id3));
// |surface_id4| is not included in the range.
EXPECT_FALSE(surface_range1.IsInRangeExclusive(surface_id4));
EXPECT_FALSE(surface_range2.IsInRangeExclusive(surface_id4));
}
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