Unleak blink's internals from web_graphics_context_3d_provider.h

A change included an internal blink header in the public api
layer which then leaked parts of blink's internal out into the
wild dangerous world outside. This is a quick fix to close that
leak. Might need some tuning.

Bug: 902022
Change-Id: I076f4c5d0a27cd4c3070d8fe8a5be97f2f65e1e0
Reviewed-on: https://chromium-review.googlesource.com/c/1323715
Commit-Queue: Daniel Bratell <bratell@opera.com>
Reviewed-by: enne <enne@chromium.org>
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606409}
diff --git a/content/renderer/webgraphicscontext3d_provider_impl.cc b/content/renderer/webgraphicscontext3d_provider_impl.cc
index 22805b0..c1c564d 100644
--- a/content/renderer/webgraphicscontext3d_provider_impl.cc
+++ b/content/renderer/webgraphicscontext3d_provider_impl.cc
@@ -79,8 +79,7 @@
 cc::ImageDecodeCache* WebGraphicsContext3DProviderImpl::ImageDecodeCache(
     blink::CanvasColorSpace color_space,
     blink::CanvasPixelFormat pixel_format) {
-  SkColorType color_type =
-      blink::CanvasColorParams::PixelFormatToSkColorType(pixel_format);
+  SkColorType color_type = blink::PixelFormatToSkColorType(pixel_format);
 
   DCHECK(GetGrContext()->colorTypeSupportedAsImage(color_type));
   auto key = std::make_pair(color_space, pixel_format);
@@ -102,8 +101,7 @@
           provider_.get(), use_transfer_cache, color_type, kMaxWorkingSetBytes,
           provider_->ContextCapabilities().max_texture_size,
           cc::PaintImage::kDefaultGeneratorClientId,
-          blink::CanvasColorParams::CanvasColorSpaceToSkColorSpace(
-              color_space)));
+          blink::CanvasColorSpaceToSkColorSpace(color_space)));
   DCHECK(insertion_result.second);
   cache_iterator = insertion_result.first;
   return cache_iterator->second.get();
diff --git a/third_party/blink/public/platform/web_graphics_context_3d_provider.h b/third_party/blink/public/platform/web_graphics_context_3d_provider.h
index 021519b..967ae7f 100644
--- a/third_party/blink/public/platform/web_graphics_context_3d_provider.h
+++ b/third_party/blink/public/platform/web_graphics_context_3d_provider.h
@@ -33,7 +33,7 @@
 
 #include <cstdint>
 #include "base/callback_forward.h"
-#include "third_party/blink/renderer/platform/graphics/canvas_color_params.h"
+#include "base/logging.h"
 #include "third_party/skia/include/core/SkImageInfo.h"
 
 class GrContext;
@@ -61,6 +61,53 @@
 
 namespace blink {
 
+enum CanvasColorSpace {
+  kSRGBCanvasColorSpace,
+  kLinearRGBCanvasColorSpace,
+  kRec2020CanvasColorSpace,
+  kP3CanvasColorSpace,
+  kMaxCanvasColorSpace = kP3CanvasColorSpace
+};
+
+enum CanvasPixelFormat {
+  kRGBA8CanvasPixelFormat,
+  kF16CanvasPixelFormat,
+  kMaxCanvasPixelFormat = kF16CanvasPixelFormat
+};
+
+inline SkColorType PixelFormatToSkColorType(CanvasPixelFormat pixel_format) {
+  switch (pixel_format) {
+    case kF16CanvasPixelFormat:
+      return kRGBA_F16_SkColorType;
+    case kRGBA8CanvasPixelFormat:
+      return kN32_SkColorType;
+  }
+  NOTREACHED();
+  return kN32_SkColorType;
+}
+
+inline sk_sp<SkColorSpace> CanvasColorSpaceToSkColorSpace(
+    CanvasColorSpace color_space) {
+  SkColorSpace::Gamut gamut = SkColorSpace::kSRGB_Gamut;
+  SkColorSpace::RenderTargetGamma gamma = SkColorSpace::kSRGB_RenderTargetGamma;
+  switch (color_space) {
+    case kSRGBCanvasColorSpace:
+      break;
+    case kLinearRGBCanvasColorSpace:
+      gamma = SkColorSpace::kLinear_RenderTargetGamma;
+      break;
+    case kRec2020CanvasColorSpace:
+      gamut = SkColorSpace::kRec2020_Gamut;
+      gamma = SkColorSpace::kLinear_RenderTargetGamma;
+      break;
+    case kP3CanvasColorSpace:
+      gamut = SkColorSpace::kDCIP3_D65_Gamut;
+      gamma = SkColorSpace::kLinear_RenderTargetGamma;
+      break;
+  }
+  return SkColorSpace::MakeRGB(gamma, gamut);
+}
+
 class WebGraphicsContext3DProvider {
  public:
   virtual ~WebGraphicsContext3DProvider() = default;
diff --git a/third_party/blink/renderer/platform/graphics/canvas_color_params.cc b/third_party/blink/renderer/platform/graphics/canvas_color_params.cc
index e8271b2..696705d 100644
--- a/third_party/blink/renderer/platform/graphics/canvas_color_params.cc
+++ b/third_party/blink/renderer/platform/graphics/canvas_color_params.cc
@@ -124,19 +124,6 @@
   return PixelFormatToSkColorType(pixel_format_);
 }
 
-// static
-SkColorType CanvasColorParams::PixelFormatToSkColorType(
-    CanvasPixelFormat pixel_format) {
-  switch (pixel_format) {
-    case kF16CanvasPixelFormat:
-      return kRGBA_F16_SkColorType;
-    case kRGBA8CanvasPixelFormat:
-      return kN32_SkColorType;
-  }
-  NOTREACHED();
-  return kN32_SkColorType;
-}
-
 SkAlphaType CanvasColorParams::GetSkAlphaType() const {
   if (opacity_mode_ == kOpaque)
     return kOpaque_SkAlphaType;
@@ -184,28 +171,6 @@
   return CanvasColorSpaceToSkColorSpace(color_space_);
 }
 
-sk_sp<SkColorSpace> CanvasColorParams::CanvasColorSpaceToSkColorSpace(
-    CanvasColorSpace color_space) {
-  SkColorSpace::Gamut gamut = SkColorSpace::kSRGB_Gamut;
-  SkColorSpace::RenderTargetGamma gamma = SkColorSpace::kSRGB_RenderTargetGamma;
-  switch (color_space) {
-    case kSRGBCanvasColorSpace:
-      break;
-    case kLinearRGBCanvasColorSpace:
-      gamma = SkColorSpace::kLinear_RenderTargetGamma;
-      break;
-    case kRec2020CanvasColorSpace:
-      gamut = SkColorSpace::kRec2020_Gamut;
-      gamma = SkColorSpace::kLinear_RenderTargetGamma;
-      break;
-    case kP3CanvasColorSpace:
-      gamut = SkColorSpace::kDCIP3_D65_Gamut;
-      gamma = SkColorSpace::kLinear_RenderTargetGamma;
-      break;
-  }
-  return SkColorSpace::MakeRGB(gamma, gamut);
-}
-
 gfx::BufferFormat CanvasColorParams::GetBufferFormat() const {
   static_assert(kN32_SkColorType == kRGBA_8888_SkColorType ||
                     kN32_SkColorType == kBGRA_8888_SkColorType,
diff --git a/third_party/blink/renderer/platform/graphics/canvas_color_params.h b/third_party/blink/renderer/platform/graphics/canvas_color_params.h
index eb5a1df..83c9d73f 100644
--- a/third_party/blink/renderer/platform/graphics/canvas_color_params.h
+++ b/third_party/blink/renderer/platform/graphics/canvas_color_params.h
@@ -6,6 +6,7 @@
 #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_CANVAS_COLOR_PARAMS_H_
 
 #include "components/viz/common/resources/resource_format.h"
+#include "third_party/blink/public/platform/web_graphics_context_3d_provider.h"
 #include "third_party/blink/renderer/platform/graphics/graphics_types.h"
 #include "third_party/blink/renderer/platform/platform_export.h"
 #include "third_party/skia/include/core/SkColorSpace.h"
@@ -24,20 +25,6 @@
 
 namespace blink {
 
-enum CanvasColorSpace {
-  kSRGBCanvasColorSpace,
-  kLinearRGBCanvasColorSpace,
-  kRec2020CanvasColorSpace,
-  kP3CanvasColorSpace,
-  kMaxCanvasColorSpace = kP3CanvasColorSpace
-};
-
-enum CanvasPixelFormat {
-  kRGBA8CanvasPixelFormat,
-  kF16CanvasPixelFormat,
-  kMaxCanvasPixelFormat = kF16CanvasPixelFormat
-};
-
 class PLATFORM_EXPORT CanvasColorParams {
  public:
   // The default constructor will create an output-blended 8-bit surface.
@@ -74,7 +61,9 @@
 
   // The pixel format to use for allocating SkSurfaces.
   SkColorType GetSkColorType() const;
-  static SkColorType PixelFormatToSkColorType(CanvasPixelFormat pixel_format);
+  static SkColorType PixelFormatToSkColorType(CanvasPixelFormat pixel_format) {
+    return ::blink::PixelFormatToSkColorType(pixel_format);
+  }
   uint8_t BytesPerPixel() const;
 
   // The color space in which pixels read from the canvas via a shader will be
@@ -86,7 +75,9 @@
   gfx::ColorSpace GetStorageGfxColorSpace() const;
   sk_sp<SkColorSpace> GetSkColorSpace() const;
   static sk_sp<SkColorSpace> CanvasColorSpaceToSkColorSpace(
-      CanvasColorSpace color_space);
+      CanvasColorSpace color_space) {
+    return ::blink::CanvasColorSpaceToSkColorSpace(color_space);
+  }
   SkAlphaType GetSkAlphaType() const;
   const SkSurfaceProps* GetSkSurfaceProps() const;