Commit bd00d297 authored by Adam Raine's avatar Adam Raine Committed by Commit Bot

Add color specific CrossThreadStyleValue

To use color values, the compositor must have a CrossThreadStyleValue
specific to color values so it can use the proper functionality for
color values.  The new class CrossThreadColorValue was created for this
purpose.  CrossThreadColorValue is intiended to be used alongside
CSSUnsupportedColorValue.

Follow up to:
https://chromium-review.googlesource.com/c/chromium/src/+/1713747

Bug: 883721
Change-Id: If296bf492ceb20380f82bcc80225094cd3d72a87
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1716962Reviewed-by: default avatarXida Chen <xidachen@chromium.org>
Reviewed-by: default avatarAnders Hartvoll Ruud <andruud@chromium.org>
Commit-Queue: Adam Raine <asraine@google.com>
Cr-Commit-Position: refs/heads/master@{#681799}
parent 33cff2fc
...@@ -213,6 +213,8 @@ blink_core_sources("css") { ...@@ -213,6 +213,8 @@ blink_core_sources("css") {
"css_viewport_rule.h", "css_viewport_rule.h",
"cssom/computed_style_property_map.cc", "cssom/computed_style_property_map.cc",
"cssom/computed_style_property_map.h", "cssom/computed_style_property_map.h",
"cssom/cross_thread_color_value.cc",
"cssom/cross_thread_color_value.h",
"cssom/cross_thread_keyword_value.cc", "cssom/cross_thread_keyword_value.cc",
"cssom/cross_thread_keyword_value.h", "cssom/cross_thread_keyword_value.h",
"cssom/cross_thread_style_value.h", "cssom/cross_thread_style_value.h",
......
// Copyright 2019 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 "third_party/blink/renderer/core/css/cssom/cross_thread_color_value.h"
#include "third_party/blink/renderer/core/css/cssom/css_unsupported_color_value.h"
namespace blink {
CSSStyleValue* CrossThreadColorValue::ToCSSStyleValue() {
return CSSUnsupportedColorValue::Create(value_);
}
bool CrossThreadColorValue::operator==(
const CrossThreadStyleValue& other) const {
if (auto* o = DynamicTo<CrossThreadColorValue>(other))
return value_ == o->value_;
return false;
}
std::unique_ptr<CrossThreadStyleValue> CrossThreadColorValue::IsolatedCopy()
const {
return std::make_unique<CrossThreadColorValue>(value_);
}
} // namespace blink
// Copyright 2019 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.
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSSOM_CROSS_THREAD_COLOR_VALUE_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSSOM_CROSS_THREAD_COLOR_VALUE_H_
#include "base/macros.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/css/css_primitive_value.h"
#include "third_party/blink/renderer/core/css/cssom/cross_thread_style_value.h"
#include "third_party/blink/renderer/platform/graphics/color.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
namespace blink {
class CSSStyleValue;
class CORE_EXPORT CrossThreadColorValue final : public CrossThreadStyleValue {
public:
explicit CrossThreadColorValue(Color value) : value_(value) {}
~CrossThreadColorValue() override = default;
StyleValueType GetType() const override { return StyleValueType::kColorType; }
CSSStyleValue* ToCSSStyleValue() override;
std::unique_ptr<CrossThreadStyleValue> IsolatedCopy() const override;
bool operator==(const CrossThreadStyleValue&) const override;
private:
friend class CrossThreadStyleValueTest;
Color value_;
DISALLOW_COPY_AND_ASSIGN(CrossThreadColorValue);
};
template <>
struct DowncastTraits<CrossThreadColorValue> {
static bool AllowFrom(const CrossThreadStyleValue& color_value) {
return color_value.GetType() ==
CrossThreadStyleValue::StyleValueType::kColorType;
}
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSSOM_CROSS_THREAD_COLOR_VALUE_H_
...@@ -22,6 +22,7 @@ class CORE_EXPORT CrossThreadStyleValue { ...@@ -22,6 +22,7 @@ class CORE_EXPORT CrossThreadStyleValue {
kUnknownType, kUnknownType,
kKeywordType, kKeywordType,
kUnitType, kUnitType,
kColorType,
}; };
virtual ~CrossThreadStyleValue() = default; virtual ~CrossThreadStyleValue() = default;
......
...@@ -8,12 +8,14 @@ ...@@ -8,12 +8,14 @@
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/core/css/cssom/cross_thread_color_value.h"
#include "third_party/blink/renderer/core/css/cssom/cross_thread_keyword_value.h" #include "third_party/blink/renderer/core/css/cssom/cross_thread_keyword_value.h"
#include "third_party/blink/renderer/core/css/cssom/cross_thread_unit_value.h" #include "third_party/blink/renderer/core/css/cssom/cross_thread_unit_value.h"
#include "third_party/blink/renderer/core/css/cssom/cross_thread_unsupported_value.h" #include "third_party/blink/renderer/core/css/cssom/cross_thread_unsupported_value.h"
#include "third_party/blink/renderer/core/css/cssom/css_keyword_value.h" #include "third_party/blink/renderer/core/css/cssom/css_keyword_value.h"
#include "third_party/blink/renderer/core/css/cssom/css_style_value.h" #include "third_party/blink/renderer/core/css/cssom/css_style_value.h"
#include "third_party/blink/renderer/core/css/cssom/css_unit_value.h" #include "third_party/blink/renderer/core/css/cssom/css_unit_value.h"
#include "third_party/blink/renderer/core/css/cssom/css_unsupported_color_value.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h" #include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread.h" #include "third_party/blink/renderer/platform/scheduler/public/thread.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h" #include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
...@@ -63,6 +65,14 @@ class CrossThreadStyleValueTest : public testing::Test { ...@@ -63,6 +65,14 @@ class CrossThreadStyleValueTest : public testing::Test {
waitable_event->Signal(); waitable_event->Signal();
} }
void CheckColorValue(base::WaitableEvent* waitable_event,
std::unique_ptr<CrossThreadColorValue> value) {
DCHECK(!IsMainThread());
EXPECT_EQ(value->value_, Color(0, 255, 0));
waitable_event->Signal();
}
protected: protected:
std::unique_ptr<blink::Thread> thread_; std::unique_ptr<blink::Thread> thread_;
}; };
...@@ -164,6 +174,38 @@ TEST_F(CrossThreadStyleValueTest, CrossThreadUnitValueToCSSStyleValue) { ...@@ -164,6 +174,38 @@ TEST_F(CrossThreadStyleValueTest, CrossThreadUnitValueToCSSStyleValue) {
EXPECT_EQ(static_cast<CSSUnitValue*>(style_value)->unit(), "deg"); EXPECT_EQ(static_cast<CSSUnitValue*>(style_value)->unit(), "deg");
} }
TEST_F(CrossThreadStyleValueTest, PassColorValueCrossThread) {
std::unique_ptr<CrossThreadColorValue> value =
std::make_unique<CrossThreadColorValue>(Color(0, 255, 0));
DCHECK(value);
// Use a Thread to emulate worklet thread.
thread_ = blink::Thread::CreateThread(
ThreadCreationParams(WebThreadType::kTestThread).SetSupportsGC(true));
base::WaitableEvent waitable_event;
PostCrossThreadTask(
*thread_->GetTaskRunner(), FROM_HERE,
CrossThreadBindOnce(&CrossThreadStyleValueTest::CheckColorValue,
CrossThreadUnretained(this),
CrossThreadUnretained(&waitable_event),
WTF::Passed(std::move(value))));
waitable_event.Wait();
ShutDownThread();
}
TEST_F(CrossThreadStyleValueTest, CrossThreadColorValueToCSSStyleValue) {
std::unique_ptr<CrossThreadColorValue> value =
std::make_unique<CrossThreadColorValue>(Color(0, 255, 0));
DCHECK(value);
CSSStyleValue* style_value = value->ToCSSStyleValue();
EXPECT_EQ(style_value->GetType(),
CSSStyleValue::StyleValueType::kUnsupportedColorType);
EXPECT_EQ(static_cast<CSSUnsupportedColorValue*>(style_value)->Value(),
Color(0, 255, 0));
}
TEST_F(CrossThreadStyleValueTest, ComparingNullValues) { TEST_F(CrossThreadStyleValueTest, ComparingNullValues) {
// Two null values are equal to each other. // Two null values are equal to each other.
std::unique_ptr<CrossThreadStyleValue> null_value1(nullptr); std::unique_ptr<CrossThreadStyleValue> null_value1(nullptr);
...@@ -239,6 +281,20 @@ TEST_F(CrossThreadStyleValueTest, ComparingCrossThreadUnitValue) { ...@@ -239,6 +281,20 @@ TEST_F(CrossThreadStyleValueTest, ComparingCrossThreadUnitValue) {
EXPECT_FALSE(DataEquivalent(unit_value_1, unit_value_4)); EXPECT_FALSE(DataEquivalent(unit_value_1, unit_value_4));
} }
TEST_F(CrossThreadStyleValueTest, ComparingCrossThreadColorValue) {
// CrossThreadColorValues are compared on their color channel values; all
// channels must match.
std::unique_ptr<CrossThreadStyleValue> color_value_1(
new CrossThreadColorValue(Color(0, 0, 0)));
std::unique_ptr<CrossThreadStyleValue> color_value_2(
new CrossThreadColorValue(Color(0, 0, 0)));
std::unique_ptr<CrossThreadStyleValue> color_value_3(
new CrossThreadColorValue(Color(0, 255, 0)));
EXPECT_TRUE(DataEquivalent(color_value_1, color_value_2));
EXPECT_FALSE(DataEquivalent(color_value_1, color_value_3));
}
TEST_F(CrossThreadStyleValueTest, ComparingCrossThreadUnsupportedValue) { TEST_F(CrossThreadStyleValueTest, ComparingCrossThreadUnsupportedValue) {
// CrossThreadUnsupportedValues are compared on their value; if it is equal // CrossThreadUnsupportedValues are compared on their value; if it is equal
// then so are they. // then so are they.
......
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