Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/OffscreenCanvasFrameDispatcherImpl.cpp

Issue 2382883005: Implement OffscreenCanvas.commit() on Unaccelerated 2D on worker (Closed)
Patch Set: rebase Nits Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/test/gpu/gpu_tests/pixel_test_pages.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "platform/graphics/OffscreenCanvasFrameDispatcherImpl.h" 5 #include "platform/graphics/OffscreenCanvasFrameDispatcherImpl.h"
6 6
7 #include "cc/output/compositor_frame.h" 7 #include "cc/output/compositor_frame.h"
8 #include "cc/output/delegated_frame_data.h" 8 #include "cc/output/delegated_frame_data.h"
9 #include "cc/quads/render_pass.h" 9 #include "cc/quads/render_pass.h"
10 #include "cc/quads/shared_quad_state.h" 10 #include "cc/quads/shared_quad_state.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 58
59 const gfx::Rect bounds(m_width, m_height); 59 const gfx::Rect bounds(m_width, m_height);
60 const cc::RenderPassId renderPassId(1, 1); 60 const cc::RenderPassId renderPassId(1, 1);
61 std::unique_ptr<cc::RenderPass> pass = cc::RenderPass::Create(); 61 std::unique_ptr<cc::RenderPass> pass = cc::RenderPass::Create();
62 pass->SetAll(renderPassId, bounds, bounds, gfx::Transform(), false); 62 pass->SetAll(renderPassId, bounds, bounds, gfx::Transform(), false);
63 63
64 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); 64 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState();
65 sqs->SetAll(gfx::Transform(), bounds.size(), bounds, bounds, false, 1.f, 65 sqs->SetAll(gfx::Transform(), bounds.size(), bounds, bounds, false, 1.f,
66 SkXfermode::kSrcOver_Mode, 0); 66 SkXfermode::kSrcOver_Mode, 0);
67 67
68 if (!image->isTextureBacked() && !isMainThread()) { 68 cc::TransferableResource resource;
69 // TODO(xlai): Implement unaccelerated 2d canvas on worker. 69 resource.id = m_nextResourceId;
70 // See crbug.com/563858. 70 resource.format = cc::ResourceFormat::RGBA_8888;
71 // This is a temporary code that submits a solidColor frame. 71 // TODO(crbug.com/645590): filter should respect the image-rendering CSS prope rty of associated canvas element.
72 cc::SolidColorDrawQuad* quad = 72 resource.filter = GL_LINEAR;
73 pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>(); 73 resource.size = gfx::Size(m_width, m_height);
74 const bool forceAntialiasingOff = false; 74 if (image->isTextureBacked()) {
75 quad->SetNew(sqs, bounds, bounds, SK_ColorGREEN, forceAntialiasingOff); 75 image->ensureMailbox();
76 resource.mailbox_holder = gpu::MailboxHolder(
77 image->getMailbox(), image->getSyncToken(), GL_TEXTURE_2D);
78 resource.read_lock_fences_enabled = false;
79 resource.is_software = false;
80
81 // Hold ref to |image|, to keep it alive until the browser ReturnResources.
82 // It guarantees that the resource is not re-used or deleted.
83 m_cachedImages.add(getNextResourceIdAndIncrement(), std::move(image));
76 } else { 84 } else {
77 cc::TransferableResource resource; 85 std::unique_ptr<cc::SharedBitmap> bitmap =
78 resource.id = m_nextResourceId; 86 Platform::current()->allocateSharedBitmap(IntSize(m_width, m_height));
79 resource.format = cc::ResourceFormat::RGBA_8888; 87 if (!bitmap)
80 // TODO(crbug.com/645590): filter should respect the image-rendering CSS pro perty of associated canvas element. 88 return;
81 resource.filter = GL_LINEAR; 89 unsigned char* pixels = bitmap->pixels();
82 resource.size = gfx::Size(m_width, m_height); 90 DCHECK(pixels);
83 if (!image->isTextureBacked()) { 91 SkImageInfo imageInfo = SkImageInfo::Make(
84 std::unique_ptr<cc::SharedBitmap> bitmap = 92 m_width, m_height, kN32_SkColorType,
85 Platform::current()->allocateSharedBitmap(IntSize(m_width, m_height)); 93 image->isPremultiplied() ? kPremul_SkAlphaType : kUnpremul_SkAlphaType);
86 if (!bitmap) 94 // TODO(xlai): Optimize to avoid copying pixels. See crbug.com/651456.
87 return; 95 image->imageForCurrentFrame()->readPixels(imageInfo, pixels,
88 unsigned char* pixels = bitmap->pixels(); 96 imageInfo.minRowBytes(), 0, 0);
89 DCHECK(pixels); 97 resource.mailbox_holder.mailbox = bitmap->id();
90 SkImageInfo imageInfo = 98 resource.is_software = true;
91 SkImageInfo::Make(m_width, m_height, kN32_SkColorType,
92 image->isPremultiplied() ? kPremul_SkAlphaType
93 : kUnpremul_SkAlphaType);
94 // TODO(xlai): Optimize to avoid copying pixels. See crbug.com/651456.
95 image->imageForCurrentFrame()->readPixels(imageInfo, pixels,
96 imageInfo.minRowBytes(), 0, 0);
97 resource.mailbox_holder.mailbox = bitmap->id();
98 resource.is_software = true;
99 99
100 // Hold ref to |bitmap|, to keep it alive until the browser ReturnResource s. 100 // Hold ref to |bitmap|, to keep it alive until the browser ReturnResources.
101 // It guarantees that the shared bitmap is not re-used or deleted. 101 // It guarantees that the shared bitmap is not re-used or deleted.
102 m_sharedBitmaps.add(getNextResourceIdAndIncrement(), std::move(bitmap)); 102 m_sharedBitmaps.add(getNextResourceIdAndIncrement(), std::move(bitmap));
103 } else { 103 }
104 image->ensureMailbox(); 104 // TODO(crbug.com/646022): making this overlay-able.
105 resource.mailbox_holder = gpu::MailboxHolder( 105 resource.is_overlay_candidate = false;
106 image->getMailbox(), image->getSyncToken(), GL_TEXTURE_2D);
107 resource.read_lock_fences_enabled = false;
108 resource.is_software = false;
109 106
110 // Hold ref to |image|, to keep it alive until the browser ReturnResources . 107 frame.delegated_frame_data->resource_list.push_back(std::move(resource));
111 // It guarantees that the resource is not re-used or deleted.
112 m_cachedImages.add(getNextResourceIdAndIncrement(), std::move(image));
113 }
114 // TODO(crbug.com/646022): making this overlay-able.
115 resource.is_overlay_candidate = false;
116 108
117 frame.delegated_frame_data->resource_list.push_back(std::move(resource)); 109 cc::TextureDrawQuad* quad =
110 pass->CreateAndAppendDrawQuad<cc::TextureDrawQuad>();
111 gfx::Size rectSize(m_width, m_height);
118 112
119 cc::TextureDrawQuad* quad = 113 const bool needsBlending = true;
120 pass->CreateAndAppendDrawQuad<cc::TextureDrawQuad>(); 114 // TOOD(crbug.com/645993): this should be inherited from WebGL context's creat ion settings.
121 gfx::Size rectSize(m_width, m_height); 115 const bool premultipliedAlpha = true;
122 116 const gfx::PointF uvTopLeft(0.f, 0.f);
123 const bool needsBlending = true; 117 const gfx::PointF uvBottomRight(1.f, 1.f);
124 // TOOD(crbug.com/645993): this should be inherited from WebGL context's cre ation settings. 118 float vertexOpacity[4] = {1.f, 1.f, 1.f, 1.f};
125 const bool premultipliedAlpha = true; 119 const bool yflipped = false;
126 const gfx::PointF uvTopLeft(0.f, 0.f); 120 // TODO(crbug.com/645994): this should be true when using style "image-renderi ng: pixelated".
127 const gfx::PointF uvBottomRight(1.f, 1.f); 121 const bool nearestNeighbor = false;
128 float vertexOpacity[4] = {1.f, 1.f, 1.f, 1.f}; 122 quad->SetAll(sqs, bounds, bounds, bounds, needsBlending, resource.id,
129 const bool yflipped = false; 123 gfx::Size(), premultipliedAlpha, uvTopLeft, uvBottomRight,
130 // TODO(crbug.com/645994): this should be true when using style "image-rende ring: pixelated". 124 SK_ColorTRANSPARENT, vertexOpacity, yflipped, nearestNeighbor,
131 const bool nearestNeighbor = false; 125 false);
132 quad->SetAll(sqs, bounds, bounds, bounds, needsBlending, resource.id,
133 gfx::Size(), premultipliedAlpha, uvTopLeft, uvBottomRight,
134 SK_ColorTRANSPARENT, vertexOpacity, yflipped, nearestNeighbor,
135 false);
136 }
137 126
138 frame.delegated_frame_data->render_pass_list.push_back(std::move(pass)); 127 frame.delegated_frame_data->render_pass_list.push_back(std::move(pass));
139 128
140 m_sink->SubmitCompositorFrame(std::move(frame), base::Closure()); 129 m_sink->SubmitCompositorFrame(std::move(frame), base::Closure());
141 } 130 }
142 131
143 void OffscreenCanvasFrameDispatcherImpl::ReturnResources( 132 void OffscreenCanvasFrameDispatcherImpl::ReturnResources(
144 Vector<cc::mojom::blink::ReturnedResourcePtr> resources) { 133 Vector<cc::mojom::blink::ReturnedResourcePtr> resources) {
145 for (const auto& resource : resources) { 134 for (const auto& resource : resources) {
146 m_cachedImages.remove(resource->id); 135 m_cachedImages.remove(resource->id);
147 m_sharedBitmaps.remove(resource->id); 136 m_sharedBitmaps.remove(resource->id);
148 } 137 }
149 } 138 }
150 139
151 bool OffscreenCanvasFrameDispatcherImpl::verifyImageSize( 140 bool OffscreenCanvasFrameDispatcherImpl::verifyImageSize(
152 const sk_sp<SkImage>& image) { 141 const sk_sp<SkImage>& image) {
153 if (image && image->width() == m_width && image->height() == m_height) 142 if (image && image->width() == m_width && image->height() == m_height)
154 return true; 143 return true;
155 return false; 144 return false;
156 } 145 }
157 146
158 } // namespace blink 147 } // namespace blink
OLDNEW
« no previous file with comments | « content/test/gpu/gpu_tests/pixel_test_pages.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698