Reviewers: Justin Novosad, Ken Russell
CL:
https://codereview.chromium.org/2360413002/Message:
ju...@chromium.org: Please review changes in OffscreenCanvasFrameDispatcherImpl
k...@chromium.org: Please review changes in gpu pixel test
Description:
Implement OffscreenCanvas Unaccelerated 2d commit() on main thread
BUG=563852
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel;master.tryserver.chromium.android:android_optional_gpu_tests_rel
Affected files (+53, -9 lines):
M content/test/gpu/gpu_tests/pixel_expectations.py
M content/test/gpu/page_sets/pixel_tests.py
M third_party/WebKit/Source/platform/graphics/OffscreenCanvasFrameDispatcherImpl.h
M third_party/WebKit/Source/platform/graphics/OffscreenCanvasFrameDispatcherImpl.cpp
Index: content/test/gpu/gpu_tests/pixel_expectations.py
diff --git a/content/test/gpu/gpu_tests/pixel_expectations.py b/content/test/gpu/gpu_tests/pixel_expectations.py
index 801862a8e8f5dbe2f6688c458ce540f2dc4634ff..f779b4e60f5107db1c8b3182ade02d1a74c971e6 100644
--- a/content/test/gpu/gpu_tests/pixel_expectations.py
+++ b/content/test/gpu/gpu_tests/pixel_expectations.py
@@ -34,6 +34,8 @@ class PixelExpectations(GpuTestExpectations):
# TODO(xidachen) check / generate reference images
self.Fail('Pixel.OffscreenCanvasWebGLRedBoxWorker', bug=563852)
self.Fail('Pixel.OffscreenCanvasWebGLRedBoxWorkerES3', ['mac'], bug=563852)
+ self.Fail('Pixel.OffscreenCanvasAccelerated2D', bug=563852)
+ self.Fail('Pixel.OffscreenCanvasAccelerated2DWorker', bug=563852)
self.Fail('Pixel.OffscreenCanvasAccelerated2D', bug=563852)
self.Fail('Pixel.OffscreenCanvasAccelerated2DES3', ['mac'], bug=563852)
@@ -41,5 +43,7 @@ class PixelExpectations(GpuTestExpectations):
self.Fail('Pixel.OffscreenCanvasAccelerated2DWorkerES3', ['mac'],
bug=563852)
+ self.Fail('Pixel.OffscreenCanvasUnaccelerated2D', bug=563852)
+
# TODO(kbr): flakily timing out on this configuration.
self.Flaky('*', ['linux', 'intel', 'debug'], bug=648369)
Index: content/test/gpu/page_sets/pixel_tests.py
diff --git a/content/test/gpu/page_sets/pixel_tests.py b/content/test/gpu/page_sets/pixel_tests.py
index 28bf9b4ed254b93118d4cbddd6faa5104ef0d1dd..449d934c47c6141bb6bea2383822fd4e644f65f9 100644
--- a/content/test/gpu/page_sets/pixel_tests.py
+++ b/content/test/gpu/page_sets/pixel_tests.py
@@ -48,6 +48,15 @@ class IOSurface2DCanvasSharedPageState(gpu_test_base.GpuSharedPageState):
['--enable-accelerated-2d-canvas',
'--disable-display-list-2d-canvas'])
+class SoftwareOffscreenCanvas2DSharedPageState(
+ gpu_test_base.GpuSharedPageState):
+ def __init__(self, test, finder_options, story_set):
+ super(SoftwareOffscreenCanvas2DSharedPageState, self).__init__(
+ test, finder_options, story_set)
+ finder_options.browser_options.AppendExtraBrowserArgs(
+ ['--disable-accelerated-2d-canvas',
+ '--disable-gpu-compositing',
+ '--enable-experimental-canvas-features'])
class WebGLNonChromiumImageSharedPageState(gpu_test_base.GpuSharedPageState):
def __init__(self, test, finder_options, story_set):
@@ -211,6 +220,15 @@ class PixelTestsStorySet(story_set_module.StorySet):
expectations=expectations))
self.AddStory(PixelTestsPage(
+ url='file://../../data/gpu/pixel_acceleratedOffscreen2d_commit_main.html',
+ name=base_name + '.OffscreenCanvasUnaccelerated2D' + es3_suffix,
+ test_rect=[0, 0, 350, 350],
+ revision=1,
+ story_set=self,
+ shared_page_state_class=SoftwareOffscreenCanvas2DSharedPageState,
+ expectations=expectations))
+
+ self.AddStory(PixelTestsPage(
url='file://../../data/gpu/pixel_canvas2d.html',
name=base_name + '.Canvas2DRedBox' + es3_suffix,
test_rect=[0, 0, 300, 300],
Index: third_party/WebKit/Source/platform/graphics/OffscreenCanvasFrameDispatcherImpl.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/OffscreenCanvasFrameDispatcherImpl.cpp b/third_party/WebKit/Source/platform/graphics/OffscreenCanvasFrameDispatcherImpl.cpp
index d97c9a85a77abd71a28cfce4c079bd2593759e95..46011a0a7bb4e7d2bfe08ba11c08b12de8914752 100644
--- a/third_party/WebKit/Source/platform/graphics/OffscreenCanvasFrameDispatcherImpl.cpp
+++ b/third_party/WebKit/Source/platform/graphics/OffscreenCanvasFrameDispatcherImpl.cpp
@@ -11,6 +11,7 @@
#include "cc/quads/solid_color_draw_quad.h"
#include "cc/quads/texture_draw_quad.h"
#include "cc/resources/returned_resource.h"
+#include "platform/RuntimeEnabledFeatures.h"
#include "public/platform/InterfaceProvider.h"
#include "public/platform/Platform.h"
#include "public/platform/modules/offscreencanvas/offscreen_canvas_surface.mojom-blink.h"
@@ -54,8 +55,9 @@ void OffscreenCanvasFrameDispatcherImpl::dispatchFrame(RefPtr<StaticBitmapImage>
cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState();
sqs->SetAll(gfx::Transform(), bounds.size(), bounds, bounds, false, 1.f, SkXfermode::kSrcOver_Mode, 0);
- if (!image->isTextureBacked()) {
- // TODO(xlai): Make unaccelerated 2d canvas work. See
crbug.com/563858+ if (!image->isTextureBacked() && !isMainThread()) {
+ // TODO(xlai): Implement unaccelerated 2d canvas on worker.
+ // See
crbug.com/563858.
// This is a temporary code that submits a solidColor frame.
cc::SolidColorDrawQuad* quad = pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>();
const bool forceAntialiasingOff = false;
@@ -67,18 +69,34 @@ void OffscreenCanvasFrameDispatcherImpl::dispatchFrame(RefPtr<StaticBitmapImage>
// TODO(
crbug.com/645590): filter should respect the image-rendering CSS property of associated canvas element.
resource.filter = GL_LINEAR;
resource.size = gfx::Size(m_width, m_height);
- image->ensureMailbox();
- resource.mailbox_holder = gpu::MailboxHolder(image->getMailbox(), image->getSyncToken(), GL_TEXTURE_2D);
- resource.read_lock_fences_enabled = false;
- resource.is_software = false;
+ if (!image->isTextureBacked() && !RuntimeEnabledFeatures::accelerated2dCanvasEnabled()) {
+ std::unique_ptr<cc::SharedBitmap> bitmap = Platform::current()->allocateSharedBitmap(IntSize(m_width, m_height));
+ if (!bitmap)
+ return;
+ unsigned char* pixels = bitmap->pixels();
+ DCHECK(pixels);
+ SkImageInfo imageInfo = SkImageInfo::Make(m_width, m_height, kN32_SkColorType, image->isPremultiplied() ? kPremul_SkAlphaType : kUnpremul_SkAlphaType);
+ image->imageForCurrentFrame()->readPixels(imageInfo, pixels, imageInfo.minRowBytes(), 0, 0);
+ resource.mailbox_holder.mailbox = bitmap->id();
+ resource.mailbox_holder.texture_target = 0;
+ resource.is_software = true;
+
+ m_sharedBitmaps.add(m_nextResourceId++, std::move(bitmap));
+ } else {
+ image->ensureMailbox();
+ resource.mailbox_holder = gpu::MailboxHolder(image->getMailbox(), image->getSyncToken(), GL_TEXTURE_2D);
+ resource.read_lock_fences_enabled = false;
+ resource.is_software = false;
+
+ // Hold ref to |image|, to keep it alive until the browser ReturnResources.
+ // It guarantees that the resource is not re-used or deleted.
+ m_cachedImages.add(m_nextResourceId++, std::move(image));
+ }
// TODO(
crbug.com/646022): making this overlay-able.
resource.is_overlay_candidate = false;
frame.delegated_frame_data->resource_list.push_back(std::move(resource));
- // Hold ref to |image|, to keep it alive until the browser ReturnResources.
- // It guarantees that the resource is not re-used or deleted.
- m_cachedImages.add(m_nextResourceId++, std::move(image));
cc::TextureDrawQuad* quad = pass->CreateAndAppendDrawQuad<cc::TextureDrawQuad>();
gfx::Size rectSize(m_width, m_height);
@@ -105,6 +123,8 @@ void OffscreenCanvasFrameDispatcherImpl::ReturnResources(Vector<cc::mojom::blink
{
for (const auto& resource : resources)
m_cachedImages.remove(resource->id);
+ for (const auto& resource : resources)
+ m_sharedBitmaps.remove(resource->id);
}
bool OffscreenCanvasFrameDispatcherImpl::verifyImageSize(const sk_sp<SkImage>& image)
Index: third_party/WebKit/Source/platform/graphics/OffscreenCanvasFrameDispatcherImpl.h
diff --git a/third_party/WebKit/Source/platform/graphics/OffscreenCanvasFrameDispatcherImpl.h b/third_party/WebKit/Source/platform/graphics/OffscreenCanvasFrameDispatcherImpl.h
index 52384bb356bd6bf02879d2079d66b16489dd8e4e..1ea3c161e0c52508c6476362ea689bbf75984af1 100644
--- a/third_party/WebKit/Source/platform/graphics/OffscreenCanvasFrameDispatcherImpl.h
+++ b/third_party/WebKit/Source/platform/graphics/OffscreenCanvasFrameDispatcherImpl.h
@@ -6,6 +6,7 @@
#define OffscreenCanvasFrameDispatcherImpl_h
#include "cc/ipc/mojo_compositor_frame_sink.mojom-blink.h"
+#include "cc/resources/shared_bitmap.h"
#include "cc/surfaces/surface_id.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "platform/graphics/OffscreenCanvasFrameDispatcher.h"
@@ -34,6 +35,7 @@ private:
unsigned m_nextResourceId;
HashMap<unsigned, RefPtr<StaticBitmapImage>> m_cachedImages;
+ HashMap<unsigned, std::unique_ptr<cc::SharedBitmap>> m_sharedBitmaps;
bool verifyImageSize(const sk_sp<SkImage>&);