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,
public:
~CanvasRenderingContext() override = default;
// A Canvas can either be "2D" or "webgl" but never both. If you request a 2D
// canvas and the existing context is already 2D, just return that. If the
// 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.
// A Canvas can either be "2D" or "webgl" but never both. Requesting a context
// with a type different from an existing will destroy the latter.
enum ContextType {
// Do not change assigned numbers of existing items: add new features to the
// end of the list.
......
......@@ -52,6 +52,7 @@
#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_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_rendering_context.h"
#include "third_party/blink/renderer/core/html/canvas/canvas_rendering_context_factory.h"
......
......@@ -37,7 +37,6 @@
#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/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_rendering_context_host.h"
#include "third_party/blink/renderer/core/html/html_element.h"
......@@ -62,6 +61,7 @@ namespace blink {
class Canvas2DLayerBridge;
class CanvasColorParams;
class CanvasContextCreationAttributesCore;
class CanvasDrawListener;
class CanvasRenderingContext;
class CanvasRenderingContextFactory;
class GraphicsContext;
......
......@@ -22,15 +22,15 @@
namespace blink {
// CanvasResourceProvider_Texture
// CanvasResourceProviderTexture
//==============================================================================
//
// * Renders to a texture managed by skia. Mailboxes are straight GL textures.
// * Layers are not overlay candidates
class CanvasResourceProvider_Texture : public CanvasResourceProvider {
class CanvasResourceProviderTexture : public CanvasResourceProvider {
public:
CanvasResourceProvider_Texture(
CanvasResourceProviderTexture(
const IntSize& size,
unsigned msaa_sample_count,
const CanvasColorParams color_params,
......@@ -41,7 +41,7 @@ class CanvasResourceProvider_Texture : public CanvasResourceProvider {
std::move(context_provider_wrapper)),
msaa_sample_count_(msaa_sample_count) {}
~CanvasResourceProvider_Texture() override = default;
~CanvasResourceProviderTexture() override = default;
bool IsValid() const final { return GetSkSurface() && !IsGpuContextLost(); }
bool IsAccelerated() const final { return true; }
......@@ -118,28 +118,28 @@ class CanvasResourceProvider_Texture : public CanvasResourceProvider {
unsigned msaa_sample_count_;
};
// CanvasResourceProvider_Texture_GpuMemoryBuffer
// CanvasResourceProviderTextureGpuMemoryBuffer
//==============================================================================
//
// * Renders to a texture managed by skia. Mailboxes are
// gpu-accelerated platform native surfaces.
// * Layers are overlay candidates
class CanvasResourceProvider_Texture_GpuMemoryBuffer final
: public CanvasResourceProvider_Texture {
class CanvasResourceProviderTextureGpuMemoryBuffer final
: public CanvasResourceProviderTexture {
public:
CanvasResourceProvider_Texture_GpuMemoryBuffer(
CanvasResourceProviderTextureGpuMemoryBuffer(
const IntSize& size,
unsigned msaa_sample_count,
const CanvasColorParams color_params,
base::WeakPtr<WebGraphicsContext3DProviderWrapper>
context_provider_wrapper)
: CanvasResourceProvider_Texture(size,
msaa_sample_count,
color_params,
std::move(context_provider_wrapper)) {}
: CanvasResourceProviderTexture(size,
msaa_sample_count,
color_params,
std::move(context_provider_wrapper)) {}
~CanvasResourceProvider_Texture_GpuMemoryBuffer() override = default;
~CanvasResourceProviderTextureGpuMemoryBuffer() override = default;
protected:
scoped_refptr<CanvasResource> CreateResource() final {
......@@ -157,7 +157,7 @@ class CanvasResourceProvider_Texture_GpuMemoryBuffer final
scoped_refptr<CanvasResource> output_resource = NewOrRecycledResource();
if (!output_resource) {
// GpuMemoryBuffer creation failed, fallback to Texture resource
return CanvasResourceProvider_Texture::ProduceFrame();
return CanvasResourceProviderTexture::ProduceFrame();
}
sk_sp<SkImage> image = GetSkSurface()->makeImageSnapshot();
......@@ -181,21 +181,21 @@ class CanvasResourceProvider_Texture_GpuMemoryBuffer final
}
};
// CanvasResourceProvider_Bitmap
// CanvasResourceProviderBitmap
//==============================================================================
//
// * Renders to a skia RAM-backed bitmap
// * Mailboxing is not supported : cannot be directly composited
class CanvasResourceProvider_Bitmap final : public CanvasResourceProvider {
class CanvasResourceProviderBitmap final : public CanvasResourceProvider {
public:
CanvasResourceProvider_Bitmap(const IntSize& size,
const CanvasColorParams color_params)
CanvasResourceProviderBitmap(const IntSize& size,
const CanvasColorParams color_params)
: CanvasResourceProvider(size,
color_params,
nullptr /*context_provider_wrapper*/) {}
~CanvasResourceProvider_Bitmap() override = default;
~CanvasResourceProviderBitmap() override = default;
bool IsValid() const final { return GetSkSurface(); }
bool IsAccelerated() const final { return false; }
......@@ -275,35 +275,37 @@ std::unique_ptr<CanvasResourceProvider> CanvasResourceProvider::Create(
switch (resource_type_fallback_list[i]) {
case kTextureGpuMemoryBufferResourceType:
DCHECK(SharedGpuContext::IsGpuCompositingEnabled());
if (RuntimeEnabledFeatures::Canvas2dImageChromiumEnabled()) {
if (!gpu::IsImageFromGpuMemoryBufferFormatSupported(
colorParams.GetBufferFormat(),
context_provider_wrapper->ContextProvider()
->GetCapabilities()))
continue;
if (!gpu::IsImageSizeValidForGpuMemoryBufferFormat(
gfx::Size(size), colorParams.GetBufferFormat()))
continue;
DCHECK(gpu::IsImageFormatCompatibleWithGpuMemoryBufferFormat(
colorParams.GLInternalFormat(), colorParams.GetBufferFormat()));
provider =
std::make_unique<CanvasResourceProvider_Texture_GpuMemoryBuffer>(
size, msaa_sample_count, colorParams,
context_provider_wrapper);
if (!RuntimeEnabledFeatures::Canvas2dImageChromiumEnabled())
break;
if (!gpu::IsImageFromGpuMemoryBufferFormatSupported(
colorParams.GetBufferFormat(),
context_provider_wrapper->ContextProvider()
->GetCapabilities())) {
continue;
}
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;
case kTextureResourceType:
// TODO(xlai): Check gpu acclereration mode before using this Resource
// Type of CanvasResourceProvider and then Add
// TODO(xlai): Check gpu acceleration mode before using this Resource
// Type of CanvasResourceProvider and then add
// "DCHECK(SharedGpuContext::IsGpuCompositingEnabled());" here.
// See crbug.com/802053.
provider = std::make_unique<CanvasResourceProvider_Texture>(
// See https://crbug.com/802053.
provider = std::make_unique<CanvasResourceProviderTexture>(
size, msaa_sample_count, colorParams, context_provider_wrapper);
break;
case kBitmapResourceType:
provider =
std::make_unique<CanvasResourceProvider_Bitmap>(size, colorParams);
std::make_unique<CanvasResourceProviderBitmap>(size, colorParams);
break;
}
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