Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Side by Side Diff: third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2DTest.cpp

Issue 2828693002: [blink] Request compositing update when canvas hibernates/wakes up. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "modules/canvas2d/CanvasRenderingContext2D.h" 5 #include "modules/canvas2d/CanvasRenderingContext2D.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include "bindings/core/v8/V8Binding.h" 8 #include "bindings/core/v8/V8Binding.h"
9 #include "bindings/core/v8/V8BindingForTesting.h" 9 #include "bindings/core/v8/V8BindingForTesting.h"
10 #include "core/dom/Document.h" 10 #include "core/dom/Document.h"
11 #include "core/frame/FrameView.h" 11 #include "core/frame/FrameView.h"
12 #include "core/frame/ImageBitmap.h" 12 #include "core/frame/ImageBitmap.h"
13 #include "core/frame/Settings.h"
13 #include "core/html/HTMLCanvasElement.h" 14 #include "core/html/HTMLCanvasElement.h"
14 #include "core/html/ImageData.h" 15 #include "core/html/ImageData.h"
15 #include "core/imagebitmap/ImageBitmapOptions.h" 16 #include "core/imagebitmap/ImageBitmapOptions.h"
17 #include "core/layout/LayoutBoxModelObject.h"
16 #include "core/loader/EmptyClients.h" 18 #include "core/loader/EmptyClients.h"
19 #include "core/paint/PaintLayer.h"
17 #include "core/testing/DummyPageHolder.h" 20 #include "core/testing/DummyPageHolder.h"
18 #include "modules/canvas2d/CanvasGradient.h" 21 #include "modules/canvas2d/CanvasGradient.h"
19 #include "modules/canvas2d/CanvasPattern.h" 22 #include "modules/canvas2d/CanvasPattern.h"
20 #include "modules/webgl/WebGLRenderingContext.h" 23 #include "modules/webgl/WebGLRenderingContext.h"
21 #include "platform/graphics/Canvas2DImageBufferSurface.h" 24 #include "platform/graphics/Canvas2DImageBufferSurface.h"
22 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h" 25 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h"
23 #include "platform/graphics/RecordingImageBufferSurface.h" 26 #include "platform/graphics/RecordingImageBufferSurface.h"
24 #include "platform/graphics/StaticBitmapImage.h" 27 #include "platform/graphics/StaticBitmapImage.h"
25 #include "platform/graphics/UnacceleratedImageBufferSurface.h" 28 #include "platform/graphics/UnacceleratedImageBufferSurface.h"
26 #include "platform/graphics/test/FakeGLES2Interface.h" 29 #include "platform/graphics/test/FakeGLES2Interface.h"
27 #include "platform/graphics/test/FakeWebGraphicsContext3DProvider.h" 30 #include "platform/graphics/test/FakeWebGraphicsContext3DProvider.h"
28 #include "platform/loader/fetch/MemoryCache.h" 31 #include "platform/loader/fetch/MemoryCache.h"
32 #include "platform/testing/TestingPlatformSupport.h"
29 #include "platform/wtf/PtrUtil.h" 33 #include "platform/wtf/PtrUtil.h"
34 #include "public/platform/scheduler/test/renderer_scheduler_test_support.h"
30 #include "testing/gmock/include/gmock/gmock.h" 35 #include "testing/gmock/include/gmock/gmock.h"
31 #include "testing/gtest/include/gtest/gtest.h" 36 #include "testing/gtest/include/gtest/gtest.h"
32 #include "third_party/skia/include/core/SkColorSpaceXform.h" 37 #include "third_party/skia/include/core/SkColorSpaceXform.h"
33 #include "third_party/skia/include/core/SkImage.h" 38 #include "third_party/skia/include/core/SkImage.h"
34 #include "third_party/skia/include/core/SkSurface.h" 39 #include "third_party/skia/include/core/SkSurface.h"
35 40
36 using ::testing::Mock; 41 using ::testing::Mock;
37 42
38 namespace blink { 43 namespace blink {
39 44
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 // ::testing::Tests. 164 // ::testing::Tests.
160 Persistent<WrapGradients> wrap_gradients_; 165 Persistent<WrapGradients> wrap_gradients_;
161 166
162 protected: 167 protected:
163 // Pre-canned objects for testing 168 // Pre-canned objects for testing
164 Persistent<ImageData> full_image_data_; 169 Persistent<ImageData> full_image_data_;
165 Persistent<ImageData> partial_image_data_; 170 Persistent<ImageData> partial_image_data_;
166 FakeImageSource opaque_bitmap_; 171 FakeImageSource opaque_bitmap_;
167 FakeImageSource alpha_bitmap_; 172 FakeImageSource alpha_bitmap_;
168 173
174 // Set this to override frame settings.
175 FrameSettingOverrideFunction override_settings_function_ = nullptr;
176
169 StringOrCanvasGradientOrCanvasPattern& OpaqueGradient() { 177 StringOrCanvasGradientOrCanvasPattern& OpaqueGradient() {
170 return wrap_gradients_->opaque_gradient_; 178 return wrap_gradients_->opaque_gradient_;
171 } 179 }
172 StringOrCanvasGradientOrCanvasPattern& AlphaGradient() { 180 StringOrCanvasGradientOrCanvasPattern& AlphaGradient() {
173 return wrap_gradients_->alpha_gradient_; 181 return wrap_gradients_->alpha_gradient_;
174 } 182 }
175 }; 183 };
176 184
177 CanvasRenderingContext2DTest::CanvasRenderingContext2DTest() 185 CanvasRenderingContext2DTest::CanvasRenderingContext2DTest()
178 : wrap_gradients_(WrapGradients::Create()), 186 : wrap_gradients_(WrapGradients::Create()),
(...skipping 14 matching lines...) Expand all
193 attributes.setLinearPixelMath(true); 201 attributes.setLinearPixelMath(true);
194 } 202 }
195 } 203 }
196 canvas_element_->GetCanvasRenderingContext(canvas_type, attributes); 204 canvas_element_->GetCanvasRenderingContext(canvas_type, attributes);
197 } 205 }
198 206
199 void CanvasRenderingContext2DTest::SetUp() { 207 void CanvasRenderingContext2DTest::SetUp() {
200 Page::PageClients page_clients; 208 Page::PageClients page_clients;
201 FillWithEmptyClients(page_clients); 209 FillWithEmptyClients(page_clients);
202 dummy_page_holder_ = 210 dummy_page_holder_ =
203 DummyPageHolder::Create(IntSize(800, 600), &page_clients); 211 DummyPageHolder::Create(IntSize(800, 600), &page_clients, nullptr,
212 override_settings_function_, nullptr);
204 document_ = &dummy_page_holder_->GetDocument(); 213 document_ = &dummy_page_holder_->GetDocument();
205 document_->documentElement()->setInnerHTML( 214 document_->documentElement()->setInnerHTML(
206 "<body><canvas id='c'></canvas></body>"); 215 "<body><canvas id='c'></canvas></body>");
207 document_->View()->UpdateAllLifecyclePhases(); 216 document_->View()->UpdateAllLifecyclePhases();
208 canvas_element_ = toHTMLCanvasElement(document_->GetElementById("c")); 217 canvas_element_ = toHTMLCanvasElement(document_->GetElementById("c"));
209 218
210 full_image_data_ = ImageData::Create(IntSize(10, 10)); 219 full_image_data_ = ImageData::Create(IntSize(10, 10));
211 partial_image_data_ = ImageData::Create(IntSize(2, 2)); 220 partial_image_data_ = ImageData::Create(IntSize(2, 2));
212 221
213 NonThrowableExceptionState exception_state; 222 NonThrowableExceptionState exception_state;
(...skipping 1164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1378 } 1387 }
1379 1388
1380 RuntimeEnabledFeatures::setExperimentalCanvasFeaturesEnabled( 1389 RuntimeEnabledFeatures::setExperimentalCanvasFeaturesEnabled(
1381 experimental_canvas_features_runtime_flag); 1390 experimental_canvas_features_runtime_flag);
1382 RuntimeEnabledFeatures::setColorCorrectRenderingEnabled( 1391 RuntimeEnabledFeatures::setColorCorrectRenderingEnabled(
1383 color_correct_rendering_runtime_flag); 1392 color_correct_rendering_runtime_flag);
1384 RuntimeEnabledFeatures::setColorCorrectRenderingDefaultModeEnabled( 1393 RuntimeEnabledFeatures::setColorCorrectRenderingDefaultModeEnabled(
1385 color_correct_rendering_default_mode_runtime_flag); 1394 color_correct_rendering_default_mode_runtime_flag);
1386 } 1395 }
1387 1396
1397 void OverrideScriptEnabled(Settings& settings) {
1398 // Simulate that we allow scripts, so that HTMLCanvasElement uses
1399 // LayoutHTMLCanvas.
1400 settings.SetScriptEnabled(true);
1401 }
1402
1403 class CanvasRenderingContext2DTestWithTestingPlatform
1404 : public CanvasRenderingContext2DTest {
1405 protected:
1406 void SetUp() override {
1407 override_settings_function_ = &OverrideScriptEnabled;
1408 platform_->AdvanceClockSeconds(1.); // For non-zero DocumentParserTimings.
1409 CanvasRenderingContext2DTest::SetUp();
1410 GetDocument().View()->UpdateLayout();
1411 }
1412
1413 void RunUntilIdle() { platform_->RunUntilIdle(); }
1414
1415 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
1416 platform_;
1417 };
1418
1419 // https://crbug.com/708445: When the Canvas2DLayerBridge hibernates or wakes up
1420 // from hibernation, the compositing reasons for the canvas element may change.
1421 // In these cases, the element should request a compositing update.
1422 TEST_F(CanvasRenderingContext2DTestWithTestingPlatform,
1423 ElementRequestsCompositingUpdateOnHibernateAndWakeUp) {
1424 CreateContext(kNonOpaque);
1425 FakeGLES2Interface gl;
1426 std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider(
1427 new FakeWebGraphicsContext3DProvider(&gl));
1428 IntSize size(300, 300);
1429 RefPtr<Canvas2DLayerBridge> bridge =
1430 MakeBridge(std::move(context_provider), size,
1431 Canvas2DLayerBridge::kEnableAcceleration);
1432 // Force hibernatation to occur in an immediate task.
1433 bridge->DontUseIdleSchedulingForTesting();
1434 std::unique_ptr<Canvas2DImageBufferSurface> surface(
1435 new Canvas2DImageBufferSurface(bridge, size));
1436 CanvasElement().CreateImageBufferUsingSurfaceForTesting(std::move(surface));
1437
1438 EXPECT_TRUE(CanvasElement().Buffer()->IsAccelerated());
1439
1440 EXPECT_TRUE(CanvasElement().GetLayoutBoxModelObject());
1441 PaintLayer* layer = CanvasElement().GetLayoutBoxModelObject()->Layer();
1442 EXPECT_TRUE(layer);
1443 GetDocument().View()->UpdateAllLifecyclePhases();
1444
1445 // Hide element to trigger hibernation (if enabled).
1446 GetDocument().GetPage()->SetVisibilityState(kPageVisibilityStateHidden,
1447 false);
1448 RunUntilIdle(); // Run hibernation task.
1449 // If enabled, hibernation should cause compositing update.
1450 EXPECT_EQ(!!CANVAS2D_HIBERNATION_ENABLED,
1451 layer->NeedsCompositingInputsUpdate());
1452
1453 GetDocument().View()->UpdateAllLifecyclePhases();
1454 EXPECT_FALSE(layer->NeedsCompositingInputsUpdate());
1455
1456 // Wake up again, which should request a compositing update synchronously.
1457 GetDocument().GetPage()->SetVisibilityState(kPageVisibilityStateVisible,
1458 false);
1459 EXPECT_EQ(!!CANVAS2D_HIBERNATION_ENABLED,
1460 layer->NeedsCompositingInputsUpdate());
1461 }
1462
1388 } // namespace blink 1463 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698