File: canvas_resource_test.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (101 lines) | stat: -rw-r--r-- 4,567 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright 2017 The Chromium Authors
// 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/platform/graphics/canvas_resource.h"

#include "base/run_loop.h"
#include "components/viz/common/resources/transferable_resource.h"
#include "components/viz/test/test_context_provider.h"
#include "gpu/GLES2/gl2extchromium.h"
#include "gpu/command_buffer/common/gpu_memory_buffer_support.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/platform/graphics/gpu/shared_gpu_context.h"
#include "third_party/blink/renderer/platform/graphics/static_bitmap_image.h"
#include "third_party/blink/renderer/platform/graphics/test/fake_gles2_interface.h"
#include "third_party/blink/renderer/platform/graphics/test/fake_web_graphics_context_3d_provider.h"
#include "third_party/blink/renderer/platform/graphics/test/gpu_memory_buffer_test_platform.h"
#include "third_party/blink/renderer/platform/graphics/test/gpu_test_utils.h"
#include "third_party/blink/renderer/platform/graphics/test/test_webgraphics_shared_image_interface_provider.h"
#include "third_party/blink/renderer/platform/testing/task_environment.h"
#include "third_party/blink/renderer/platform/testing/testing_platform_support.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/skia/include/core/SkSurface.h"

namespace blink {

namespace {

class AcceleratedCompositingTestPlatform
    : public blink::TestingPlatformSupport {
 public:
  bool IsGpuCompositingDisabled() const override { return false; }
};

}  // namespace

TEST(CanvasResourceTest, PrepareTransferableResource_Software) {
  test::TaskEnvironment task_environment;
  std::unique_ptr<WebGraphicsSharedImageInterfaceProvider>
      test_web_shared_image_interface_provider =
          TestWebGraphicsSharedImageInterfaceProvider::Create();
  auto shared_image_interface_provider =
      test_web_shared_image_interface_provider->GetWeakPtr();

  scoped_refptr<CanvasResource> canvas_resource =
      CanvasResourceSharedImage::CreateSoftware(
          gfx::Size(10, 10), viz::SinglePlaneFormat::kBGRA_8888,
          kPremul_SkAlphaType, gfx::ColorSpace::CreateSRGB(),
          /*CanvasResourceProvider=*/nullptr, shared_image_interface_provider);
  EXPECT_TRUE(!!canvas_resource);
  viz::TransferableResource resource;
  CanvasResource::ReleaseCallback release_callback;
  bool success = canvas_resource->PrepareTransferableResource(
      &resource, &release_callback, /*needs_verified_synctoken=*/false);

  EXPECT_TRUE(success);
  EXPECT_TRUE(resource.is_software);

  std::move(release_callback)
      .Run(std::move(canvas_resource), gpu::SyncToken(), false);
}

TEST(CanvasResourceTest, PrepareTransferableResource_PreservesAlphaType) {
  test::TaskEnvironment task_environment;
  auto accelerated_compositing_platform = std::make_unique<
      ScopedTestingPlatformSupport<AcceleratedCompositingTestPlatform>>();
  auto test_context_provider = viz::TestContextProvider::CreateRaster();
  InitializeSharedGpuContextRaster(test_context_provider.get());

  viz::TransferableResource resource;
  CanvasResource::ReleaseCallback release_callback;

  scoped_refptr<CanvasResource> premul_canvas_resource =
      CanvasResourceSharedImage::Create(
          gfx::Size(10, 10), viz::SinglePlaneFormat::kRGBA_8888,
          kPremul_SkAlphaType, gfx::ColorSpace::CreateSRGB(),
          SharedGpuContext::ContextProviderWrapper(),
          /*CanvasResourceProvider=*/nullptr,
          /*is_accelerated=*/false, gpu::SHARED_IMAGE_USAGE_DISPLAY_READ);

  ASSERT_TRUE(premul_canvas_resource->PrepareTransferableResource(
      &resource, &release_callback, /*needs_verified_synctoken=*/false));
  EXPECT_EQ(resource.alpha_type, kPremul_SkAlphaType);

  scoped_refptr<CanvasResource> unpremul_canvas_resource =
      CanvasResourceSharedImage::Create(
          gfx::Size(10, 10), viz::SinglePlaneFormat::kRGBA_8888,
          kUnpremul_SkAlphaType, gfx::ColorSpace::CreateSRGB(),
          SharedGpuContext::ContextProviderWrapper(),
          /*CanvasResourceProvider=*/nullptr,
          /*is_accelerated=*/false,
          gpu::SHARED_IMAGE_USAGE_DISPLAY_READ |
              gpu::SHARED_IMAGE_USAGE_RASTER_WRITE);

  ASSERT_TRUE(unpremul_canvas_resource->PrepareTransferableResource(
      &resource, &release_callback, /*needs_verified_synctoken=*/false));
  EXPECT_EQ(resource.alpha_type, kUnpremul_SkAlphaType);
}

}  // namespace blink