Commit 4f75e35a authored by Fernando Serboncini's avatar Fernando Serboncini Committed by Commit Bot

Make CSSParser multi threaded, adds OffscreenCanvas filters thread tests

- CSS Parser now is ThreadSpecific and not only static local.
- Multi threaded tests for all code that OffscreenCanvas filters
currently use:
  - CSSToLengthConversionData
  - CreateOffscreenFilterOperations

Bug: 724565
Change-Id: I7fdc7f2ff0246709211740d8f708f65513aa2a4f
Reviewed-on: https://chromium-review.googlesource.com/517969
Commit-Queue: Fernando Serboncini <fserb@chromium.org>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Reviewed-by: default avatarJustin Novosad <junov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#476446}
parent a840c6a2
...@@ -1184,6 +1184,8 @@ source_set("unit_tests") { ...@@ -1184,6 +1184,8 @@ source_set("unit_tests") {
"css/resolver/MatchResultTest.cpp", "css/resolver/MatchResultTest.cpp",
"css/resolver/ScopedStyleResolverTest.cpp", "css/resolver/ScopedStyleResolverTest.cpp",
"css/resolver/SharedStyleFinderTest.cpp", "css/resolver/SharedStyleFinderTest.cpp",
"css/threaded/CSSToLengthConversionDataThreadedTest.cpp",
"css/threaded/FilterOperationResolverThreadedTest.cpp",
"dom/AttrTest.cpp", "dom/AttrTest.cpp",
"dom/CSSSelectorWatchTest.cpp", "dom/CSSSelectorWatchTest.cpp",
"dom/DOMImplementationTest.cpp", "dom/DOMImplementationTest.cpp",
......
...@@ -49,7 +49,7 @@ class CORE_EXPORT CSSToLengthConversionData { ...@@ -49,7 +49,7 @@ class CORE_EXPORT CSSToLengthConversionData {
DISALLOW_NEW(); DISALLOW_NEW();
public: public:
class FontSizes { class CORE_EXPORT FontSizes {
DISALLOW_NEW(); DISALLOW_NEW();
public: public:
...@@ -68,7 +68,7 @@ class CORE_EXPORT CSSToLengthConversionData { ...@@ -68,7 +68,7 @@ class CORE_EXPORT CSSToLengthConversionData {
const Font* font_; const Font* font_;
}; };
class ViewportSize { class CORE_EXPORT ViewportSize {
DISALLOW_NEW(); DISALLOW_NEW();
public: public:
......
...@@ -146,9 +146,15 @@ bool CSSParserContext::operator==(const CSSParserContext& other) const { ...@@ -146,9 +146,15 @@ bool CSSParserContext::operator==(const CSSParserContext& other) const {
} }
const CSSParserContext* StrictCSSParserContext() { const CSSParserContext* StrictCSSParserContext() {
DEFINE_STATIC_LOCAL(CSSParserContext, strict_context, DEFINE_THREAD_SAFE_STATIC_LOCAL(ThreadSpecific<Persistent<CSSParserContext>>,
(CSSParserContext::Create(kHTMLStandardMode))); strict_context_pool, ());
return &strict_context; Persistent<CSSParserContext>& context = *strict_context_pool;
if (!context) {
context = CSSParserContext::Create(kHTMLStandardMode);
context.RegisterAsStaticReference();
}
return context;
} }
KURL CSSParserContext::CompleteURL(const String& url) const { KURL CSSParserContext::CompleteURL(const String& url) const {
......
// Copyright 2017 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 "core/css/CSSToLengthConversionData.h"
#include "core/css/threaded/MultiThreadedTestUtil.h"
#include "platform/Length.h"
#include "platform/fonts/Font.h"
#include "platform/fonts/FontDescription.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace blink {
TSAN_TEST(CSSToLengthConversionDataThreadedTest, Construction) {
RunOnThreads([]() {
FontDescription fontDescription;
Font font(fontDescription);
CSSToLengthConversionData::FontSizes fontSizes(16, 16, &font);
CSSToLengthConversionData::ViewportSize viewportSize(0, 0);
CSSToLengthConversionData conversionData(nullptr, fontSizes, viewportSize,
1);
});
}
TSAN_TEST(CSSToLengthConversionDataThreadedTest, ConversionEm) {
RunOnThreads([]() {
FontDescription fontDescription;
Font font(fontDescription);
CSSToLengthConversionData::FontSizes fontSizes(16, 16, &font);
CSSToLengthConversionData::ViewportSize viewportSize(0, 0);
CSSToLengthConversionData conversionData(nullptr, fontSizes, viewportSize,
1);
CSSPrimitiveValue& value =
*CSSPrimitiveValue::Create(3.14, CSSPrimitiveValue::UnitType::kEms);
Length length = value.ConvertToLength(conversionData);
EXPECT_EQ(length.Value(), 50.24f);
});
}
TSAN_TEST(CSSToLengthConversionDataThreadedTest, ConversionPixel) {
RunOnThreads([]() {
FontDescription fontDescription;
Font font(fontDescription);
CSSToLengthConversionData::FontSizes fontSizes(16, 16, &font);
CSSToLengthConversionData::ViewportSize viewportSize(0, 0);
CSSToLengthConversionData conversionData(nullptr, fontSizes, viewportSize,
1);
CSSPrimitiveValue& value =
*CSSPrimitiveValue::Create(44, CSSPrimitiveValue::UnitType::kPixels);
Length length = value.ConvertToLength(conversionData);
EXPECT_EQ(length.Value(), 44);
});
}
TSAN_TEST(CSSToLengthConversionDataThreadedTest, ConversionViewport) {
RunOnThreads([]() {
FontDescription fontDescription;
Font font(fontDescription);
CSSToLengthConversionData::FontSizes fontSizes(16, 16, &font);
CSSToLengthConversionData::ViewportSize viewportSize(0, 0);
CSSToLengthConversionData conversionData(nullptr, fontSizes, viewportSize,
1);
CSSPrimitiveValue& value = *CSSPrimitiveValue::Create(
1, CSSPrimitiveValue::UnitType::kViewportWidth);
Length length = value.ConvertToLength(conversionData);
EXPECT_EQ(length.Value(), 0);
});
}
TSAN_TEST(CSSToLengthConversionDataThreadedTest, ConversionRem) {
RunOnThreads([]() {
FontDescription fontDescription;
Font font(fontDescription);
CSSToLengthConversionData::FontSizes fontSizes(16, 16, &font);
CSSToLengthConversionData::ViewportSize viewportSize(0, 0);
CSSToLengthConversionData conversionData(nullptr, fontSizes, viewportSize,
1);
CSSPrimitiveValue& value =
*CSSPrimitiveValue::Create(1, CSSPrimitiveValue::UnitType::kRems);
Length length = value.ConvertToLength(conversionData);
EXPECT_EQ(length.Value(), 16);
});
}
} // namespace blink
// Copyright 2017 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 "core/css/resolver/FilterOperationResolver.h"
#include "core/css/parser/CSSParser.h"
#include "core/css/parser/CSSParserContext.h"
#include "core/css/threaded/MultiThreadedTestUtil.h"
#include "core/style/FilterOperation.h"
#include "platform/fonts/Font.h"
#include "platform/fonts/FontDescription.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace blink {
TSAN_TEST(FilterOperationResolverThreadedTest, SimpleMatrixFilter) {
RunOnThreads([]() {
const CSSValue* value =
CSSParser::ParseSingleValue(CSSPropertyFilter, "sepia(50%)");
ASSERT_TRUE(value);
FilterOperations fo =
FilterOperationResolver::CreateOffscreenFilterOperations(*value);
ASSERT_EQ(fo.size(), 1ul);
EXPECT_EQ(*fo.at(0), *BasicColorMatrixFilterOperation::Create(
0.5, FilterOperation::SEPIA));
});
}
TSAN_TEST(FilterOperationResolverThreadedTest, SimpleTransferFilter) {
RunOnThreads([]() {
const CSSValue* value =
CSSParser::ParseSingleValue(CSSPropertyFilter, "brightness(50%)");
ASSERT_TRUE(value);
FilterOperations fo =
FilterOperationResolver::CreateOffscreenFilterOperations(*value);
ASSERT_EQ(fo.size(), 1ul);
EXPECT_EQ(*fo.at(0), *BasicComponentTransferFilterOperation::Create(
0.5, FilterOperation::BRIGHTNESS));
});
}
TSAN_TEST(FilterOperationResolverThreadedTest, SimpleBlurFilter) {
RunOnThreads([]() {
const CSSValue* value =
CSSParser::ParseSingleValue(CSSPropertyFilter, "blur(10px)");
ASSERT_TRUE(value);
FilterOperations fo =
FilterOperationResolver::CreateOffscreenFilterOperations(*value);
ASSERT_EQ(fo.size(), 1ul);
EXPECT_EQ(*fo.at(0),
*BlurFilterOperation::Create(Length(10, LengthType::kFixed)));
});
}
TSAN_TEST(FilterOperationResolverThreadedTest, SimpleDropShadow) {
RunOnThreads([]() {
const CSSValue* value = CSSParser::ParseSingleValue(
CSSPropertyFilter, "drop-shadow(10px 5px 1px black)");
ASSERT_TRUE(value);
FilterOperations fo =
FilterOperationResolver::CreateOffscreenFilterOperations(*value);
ASSERT_EQ(fo.size(), 1ul);
EXPECT_EQ(*fo.at(0), *DropShadowFilterOperation::Create(ShadowData(
FloatPoint(10, 5), 1, 0, ShadowStyle::kNormal,
StyleColor(Color::kBlack))));
});
}
TSAN_TEST(FilterOperationResolverThreadedTest, CompoundFilter) {
RunOnThreads([]() {
const CSSValue* value = CSSParser::ParseSingleValue(
CSSPropertyFilter, "sepia(50%) brightness(50%)");
ASSERT_TRUE(value);
FilterOperations fo =
FilterOperationResolver::CreateOffscreenFilterOperations(*value);
EXPECT_FALSE(fo.IsEmpty());
ASSERT_EQ(fo.size(), 2ul);
EXPECT_EQ(*fo.at(0), *BasicColorMatrixFilterOperation::Create(
0.5, FilterOperation::SEPIA));
EXPECT_EQ(*fo.at(1), *BasicComponentTransferFilterOperation::Create(
0.5, FilterOperation::BRIGHTNESS));
});
}
} // namespace blink
...@@ -46,7 +46,6 @@ class MultiThreadedTest : public testing::Test { ...@@ -46,7 +46,6 @@ class MultiThreadedTest : public testing::Test {
public: public:
// RunOnThreads run a closure num_threads * callbacks_per_thread times. // RunOnThreads run a closure num_threads * callbacks_per_thread times.
// The default for this is 10*100 = 1000 times. // The default for this is 10*100 = 1000 times.
template <typename FunctionType, typename... Ps> template <typename FunctionType, typename... Ps>
void RunOnThreads(FunctionType function, Ps&&... parameters) { void RunOnThreads(FunctionType function, Ps&&... parameters) {
Vector<std::unique_ptr<WebThreadSupportingGC>> threads; Vector<std::unique_ptr<WebThreadSupportingGC>> threads;
......
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