Commit 566c308f authored by Miguel Casas's avatar Miguel Casas Committed by Commit Bot

blink canvas: some cosmetic cleanups

This CL does a bit of cleanup I found around while reading the code:
- Forward-declares CanvasDrawListener.
- Reduces a verbose comment.
- Removes _ from a few internal class names (they landed like this
 in crrev.com/c/728340 but usually Chrome derived classes don't
 use _.
- Uses early-break in CanvasResourceProvider::Create() to avoid deep
 indents and use {} for if statements with large conditionals.

Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2
Change-Id: Ib1faf4a2d334e0a9b108c9fa02ebfbeffa0ea8c3
Reviewed-on: https://chromium-review.googlesource.com/1042905Reviewed-by: default avatarJustin Novosad <junov@chromium.org>
Commit-Queue: Miguel Casas <mcasas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#556070}
parent 075c5af8
...@@ -63,11 +63,8 @@ class CORE_EXPORT CanvasRenderingContext : public ScriptWrappable, ...@@ -63,11 +63,8 @@ class CORE_EXPORT CanvasRenderingContext : public ScriptWrappable,
public: public:
~CanvasRenderingContext() override = default; ~CanvasRenderingContext() override = default;
// A Canvas can either be "2D" or "webgl" but never both. If you request a 2D // A Canvas can either be "2D" or "webgl" but never both. Requesting a context
// canvas and the existing context is already 2D, just return that. If the // with a type different from an existing will destroy the latter.
// existing context is WebGL, then destroy it before creating a new 2D
// context. Vice versa when requesting a WebGL canvas. Requesting a context
// with any other type string will destroy any existing context.
enum ContextType { enum ContextType {
// Do not change assigned numbers of existing items: add new features to the // Do not change assigned numbers of existing items: add new features to the
// end of the list. // end of the list.
......
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
#include "third_party/blink/renderer/core/frame/use_counter.h" #include "third_party/blink/renderer/core/frame/use_counter.h"
#include "third_party/blink/renderer/core/html/canvas/canvas_async_blob_creator.h" #include "third_party/blink/renderer/core/html/canvas/canvas_async_blob_creator.h"
#include "third_party/blink/renderer/core/html/canvas/canvas_context_creation_attributes_core.h" #include "third_party/blink/renderer/core/html/canvas/canvas_context_creation_attributes_core.h"
#include "third_party/blink/renderer/core/html/canvas/canvas_draw_listener.h"
#include "third_party/blink/renderer/core/html/canvas/canvas_font_cache.h" #include "third_party/blink/renderer/core/html/canvas/canvas_font_cache.h"
#include "third_party/blink/renderer/core/html/canvas/canvas_rendering_context.h" #include "third_party/blink/renderer/core/html/canvas/canvas_rendering_context.h"
#include "third_party/blink/renderer/core/html/canvas/canvas_rendering_context_factory.h" #include "third_party/blink/renderer/core/html/canvas/canvas_rendering_context_factory.h"
......
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/dom/context_lifecycle_observer.h" #include "third_party/blink/renderer/core/dom/context_lifecycle_observer.h"
#include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/html/canvas/canvas_draw_listener.h"
#include "third_party/blink/renderer/core/html/canvas/canvas_image_source.h" #include "third_party/blink/renderer/core/html/canvas/canvas_image_source.h"
#include "third_party/blink/renderer/core/html/canvas/canvas_rendering_context_host.h" #include "third_party/blink/renderer/core/html/canvas/canvas_rendering_context_host.h"
#include "third_party/blink/renderer/core/html/html_element.h" #include "third_party/blink/renderer/core/html/html_element.h"
...@@ -62,6 +61,7 @@ namespace blink { ...@@ -62,6 +61,7 @@ namespace blink {
class Canvas2DLayerBridge; class Canvas2DLayerBridge;
class CanvasColorParams; class CanvasColorParams;
class CanvasContextCreationAttributesCore; class CanvasContextCreationAttributesCore;
class CanvasDrawListener;
class CanvasRenderingContext; class CanvasRenderingContext;
class CanvasRenderingContextFactory; class CanvasRenderingContextFactory;
class GraphicsContext; class GraphicsContext;
......
...@@ -22,15 +22,15 @@ ...@@ -22,15 +22,15 @@
namespace blink { namespace blink {
// CanvasResourceProvider_Texture // CanvasResourceProviderTexture
//============================================================================== //==============================================================================
// //
// * Renders to a texture managed by skia. Mailboxes are straight GL textures. // * Renders to a texture managed by skia. Mailboxes are straight GL textures.
// * Layers are not overlay candidates // * Layers are not overlay candidates
class CanvasResourceProvider_Texture : public CanvasResourceProvider { class CanvasResourceProviderTexture : public CanvasResourceProvider {
public: public:
CanvasResourceProvider_Texture( CanvasResourceProviderTexture(
const IntSize& size, const IntSize& size,
unsigned msaa_sample_count, unsigned msaa_sample_count,
const CanvasColorParams color_params, const CanvasColorParams color_params,
...@@ -41,7 +41,7 @@ class CanvasResourceProvider_Texture : public CanvasResourceProvider { ...@@ -41,7 +41,7 @@ class CanvasResourceProvider_Texture : public CanvasResourceProvider {
std::move(context_provider_wrapper)), std::move(context_provider_wrapper)),
msaa_sample_count_(msaa_sample_count) {} msaa_sample_count_(msaa_sample_count) {}
~CanvasResourceProvider_Texture() override = default; ~CanvasResourceProviderTexture() override = default;
bool IsValid() const final { return GetSkSurface() && !IsGpuContextLost(); } bool IsValid() const final { return GetSkSurface() && !IsGpuContextLost(); }
bool IsAccelerated() const final { return true; } bool IsAccelerated() const final { return true; }
...@@ -118,28 +118,28 @@ class CanvasResourceProvider_Texture : public CanvasResourceProvider { ...@@ -118,28 +118,28 @@ class CanvasResourceProvider_Texture : public CanvasResourceProvider {
unsigned msaa_sample_count_; unsigned msaa_sample_count_;
}; };
// CanvasResourceProvider_Texture_GpuMemoryBuffer // CanvasResourceProviderTextureGpuMemoryBuffer
//============================================================================== //==============================================================================
// //
// * Renders to a texture managed by skia. Mailboxes are // * Renders to a texture managed by skia. Mailboxes are
// gpu-accelerated platform native surfaces. // gpu-accelerated platform native surfaces.
// * Layers are overlay candidates // * Layers are overlay candidates
class CanvasResourceProvider_Texture_GpuMemoryBuffer final class CanvasResourceProviderTextureGpuMemoryBuffer final
: public CanvasResourceProvider_Texture { : public CanvasResourceProviderTexture {
public: public:
CanvasResourceProvider_Texture_GpuMemoryBuffer( CanvasResourceProviderTextureGpuMemoryBuffer(
const IntSize& size, const IntSize& size,
unsigned msaa_sample_count, unsigned msaa_sample_count,
const CanvasColorParams color_params, const CanvasColorParams color_params,
base::WeakPtr<WebGraphicsContext3DProviderWrapper> base::WeakPtr<WebGraphicsContext3DProviderWrapper>
context_provider_wrapper) context_provider_wrapper)
: CanvasResourceProvider_Texture(size, : CanvasResourceProviderTexture(size,
msaa_sample_count, msaa_sample_count,
color_params, color_params,
std::move(context_provider_wrapper)) {} std::move(context_provider_wrapper)) {}
~CanvasResourceProvider_Texture_GpuMemoryBuffer() override = default; ~CanvasResourceProviderTextureGpuMemoryBuffer() override = default;
protected: protected:
scoped_refptr<CanvasResource> CreateResource() final { scoped_refptr<CanvasResource> CreateResource() final {
...@@ -157,7 +157,7 @@ class CanvasResourceProvider_Texture_GpuMemoryBuffer final ...@@ -157,7 +157,7 @@ class CanvasResourceProvider_Texture_GpuMemoryBuffer final
scoped_refptr<CanvasResource> output_resource = NewOrRecycledResource(); scoped_refptr<CanvasResource> output_resource = NewOrRecycledResource();
if (!output_resource) { if (!output_resource) {
// GpuMemoryBuffer creation failed, fallback to Texture resource // GpuMemoryBuffer creation failed, fallback to Texture resource
return CanvasResourceProvider_Texture::ProduceFrame(); return CanvasResourceProviderTexture::ProduceFrame();
} }
sk_sp<SkImage> image = GetSkSurface()->makeImageSnapshot(); sk_sp<SkImage> image = GetSkSurface()->makeImageSnapshot();
...@@ -181,21 +181,21 @@ class CanvasResourceProvider_Texture_GpuMemoryBuffer final ...@@ -181,21 +181,21 @@ class CanvasResourceProvider_Texture_GpuMemoryBuffer final
} }
}; };
// CanvasResourceProvider_Bitmap // CanvasResourceProviderBitmap
//============================================================================== //==============================================================================
// //
// * Renders to a skia RAM-backed bitmap // * Renders to a skia RAM-backed bitmap
// * Mailboxing is not supported : cannot be directly composited // * Mailboxing is not supported : cannot be directly composited
class CanvasResourceProvider_Bitmap final : public CanvasResourceProvider { class CanvasResourceProviderBitmap final : public CanvasResourceProvider {
public: public:
CanvasResourceProvider_Bitmap(const IntSize& size, CanvasResourceProviderBitmap(const IntSize& size,
const CanvasColorParams color_params) const CanvasColorParams color_params)
: CanvasResourceProvider(size, : CanvasResourceProvider(size,
color_params, color_params,
nullptr /*context_provider_wrapper*/) {} nullptr /*context_provider_wrapper*/) {}
~CanvasResourceProvider_Bitmap() override = default; ~CanvasResourceProviderBitmap() override = default;
bool IsValid() const final { return GetSkSurface(); } bool IsValid() const final { return GetSkSurface(); }
bool IsAccelerated() const final { return false; } bool IsAccelerated() const final { return false; }
...@@ -275,35 +275,37 @@ std::unique_ptr<CanvasResourceProvider> CanvasResourceProvider::Create( ...@@ -275,35 +275,37 @@ std::unique_ptr<CanvasResourceProvider> CanvasResourceProvider::Create(
switch (resource_type_fallback_list[i]) { switch (resource_type_fallback_list[i]) {
case kTextureGpuMemoryBufferResourceType: case kTextureGpuMemoryBufferResourceType:
DCHECK(SharedGpuContext::IsGpuCompositingEnabled()); DCHECK(SharedGpuContext::IsGpuCompositingEnabled());
if (RuntimeEnabledFeatures::Canvas2dImageChromiumEnabled()) { if (!RuntimeEnabledFeatures::Canvas2dImageChromiumEnabled())
if (!gpu::IsImageFromGpuMemoryBufferFormatSupported( break;
colorParams.GetBufferFormat(),
context_provider_wrapper->ContextProvider() if (!gpu::IsImageFromGpuMemoryBufferFormatSupported(
->GetCapabilities())) colorParams.GetBufferFormat(),
continue; context_provider_wrapper->ContextProvider()
if (!gpu::IsImageSizeValidForGpuMemoryBufferFormat( ->GetCapabilities())) {
gfx::Size(size), colorParams.GetBufferFormat())) continue;
continue;
DCHECK(gpu::IsImageFormatCompatibleWithGpuMemoryBufferFormat(
colorParams.GLInternalFormat(), colorParams.GetBufferFormat()));
provider =
std::make_unique<CanvasResourceProvider_Texture_GpuMemoryBuffer>(
size, msaa_sample_count, colorParams,
context_provider_wrapper);
} }
if (!gpu::IsImageSizeValidForGpuMemoryBufferFormat(
gfx::Size(size), colorParams.GetBufferFormat())) {
continue;
}
DCHECK(gpu::IsImageFormatCompatibleWithGpuMemoryBufferFormat(
colorParams.GLInternalFormat(), colorParams.GetBufferFormat()));
provider =
std::make_unique<CanvasResourceProviderTextureGpuMemoryBuffer>(
size, msaa_sample_count, colorParams, context_provider_wrapper);
break; break;
case kTextureResourceType: case kTextureResourceType:
// TODO(xlai): Check gpu acclereration mode before using this Resource // TODO(xlai): Check gpu acceleration mode before using this Resource
// Type of CanvasResourceProvider and then Add // Type of CanvasResourceProvider and then add
// "DCHECK(SharedGpuContext::IsGpuCompositingEnabled());" here. // "DCHECK(SharedGpuContext::IsGpuCompositingEnabled());" here.
// See crbug.com/802053. // See https://crbug.com/802053.
provider = std::make_unique<CanvasResourceProvider_Texture>( provider = std::make_unique<CanvasResourceProviderTexture>(
size, msaa_sample_count, colorParams, context_provider_wrapper); size, msaa_sample_count, colorParams, context_provider_wrapper);
break; break;
case kBitmapResourceType: case kBitmapResourceType:
provider = provider =
std::make_unique<CanvasResourceProvider_Bitmap>(size, colorParams); std::make_unique<CanvasResourceProviderBitmap>(size, colorParams);
break; break;
} }
if (provider && provider->IsValid()) if (provider && provider->IsValid())
......
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