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

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: style 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
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 frame.delegated_frame_data.reset(new cc::DelegatedFrameData); 48 frame.delegated_frame_data.reset(new cc::DelegatedFrameData);
49 49
50 const gfx::Rect bounds(m_width, m_height); 50 const gfx::Rect bounds(m_width, m_height);
51 const cc::RenderPassId renderPassId(1, 1); 51 const cc::RenderPassId renderPassId(1, 1);
52 std::unique_ptr<cc::RenderPass> pass = cc::RenderPass::Create(); 52 std::unique_ptr<cc::RenderPass> pass = cc::RenderPass::Create();
53 pass->SetAll(renderPassId, bounds, bounds, gfx::Transform(), false); 53 pass->SetAll(renderPassId, bounds, bounds, gfx::Transform(), false);
54 54
55 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); 55 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState();
56 sqs->SetAll(gfx::Transform(), bounds.size(), bounds, bounds, false, 1.f, SkX fermode::kSrcOver_Mode, 0); 56 sqs->SetAll(gfx::Transform(), bounds.size(), bounds, bounds, false, 1.f, SkX fermode::kSrcOver_Mode, 0);
57 57
58 if (!image->isTextureBacked() && !isMainThread()) { 58 cc::TransferableResource resource;
59 // TODO(xlai): Implement unaccelerated 2d canvas on worker. 59 resource.id = m_nextResourceId;
60 // See crbug.com/563858. 60 resource.format = cc::ResourceFormat::RGBA_8888;
61 // This is a temporary code that submits a solidColor frame. 61 // TODO(crbug.com/645590): filter should respect the image-rendering CSS pro perty of associated canvas element.
62 cc::SolidColorDrawQuad* quad = pass->CreateAndAppendDrawQuad<cc::SolidCo lorDrawQuad>(); 62 resource.filter = GL_LINEAR;
63 const bool forceAntialiasingOff = false; 63 resource.size = gfx::Size(m_width, m_height);
64 quad->SetNew(sqs, bounds, bounds, SK_ColorGREEN, forceAntialiasingOff); 64 if (!image->isTextureBacked()) {
Justin Novosad 2016/10/03 15:13:53 Nit: Remove the '!' and swap what is before/after
65 std::unique_ptr<cc::SharedBitmap> bitmap = Platform::current()->allocate SharedBitmap(IntSize(m_width, m_height));
66 if (!bitmap)
67 return;
68 unsigned char* pixels = bitmap->pixels();
69 DCHECK(pixels);
70 SkImageInfo imageInfo = SkImageInfo::Make(m_width, m_height, kN32_SkColo rType, image->isPremultiplied() ? kPremul_SkAlphaType : kUnpremul_SkAlphaType);
71 // TODO(xlai): Optimize to avoid copying pixels. See crbug.com/651456.
72 image->imageForCurrentFrame()->readPixels(imageInfo, pixels, imageInfo.m inRowBytes(), 0, 0);
73 resource.mailbox_holder.mailbox = bitmap->id();
74 resource.is_software = true;
75
76 // Hold ref to |bitmap|, to keep it alive until the browser ReturnResour ces.
77 // It guarantees that the shared bitmap is not re-used or deleted.
78 m_sharedBitmaps.add(getNextResourceIdAndIncrement(), std::move(bitmap));
65 } else { 79 } else {
66 cc::TransferableResource resource; 80 image->ensureMailbox();
67 resource.id = m_nextResourceId; 81 resource.mailbox_holder = gpu::MailboxHolder(image->getMailbox(), image- >getSyncToken(), GL_TEXTURE_2D);
68 resource.format = cc::ResourceFormat::RGBA_8888; 82 resource.read_lock_fences_enabled = false;
69 // TODO(crbug.com/645590): filter should respect the image-rendering CSS property of associated canvas element. 83 resource.is_software = false;
70 resource.filter = GL_LINEAR;
71 resource.size = gfx::Size(m_width, m_height);
72 if (!image->isTextureBacked()) {
73 std::unique_ptr<cc::SharedBitmap> bitmap = Platform::current()->allo cateSharedBitmap(IntSize(m_width, m_height));
74 if (!bitmap)
75 return;
76 unsigned char* pixels = bitmap->pixels();
77 DCHECK(pixels);
78 SkImageInfo imageInfo = SkImageInfo::Make(m_width, m_height, kN32_Sk ColorType, image->isPremultiplied() ? kPremul_SkAlphaType : kUnpremul_SkAlphaTyp e);
79 // TODO(xlai): Optimize to avoid copying pixels. See crbug.com/65145 6.
80 image->imageForCurrentFrame()->readPixels(imageInfo, pixels, imageIn fo.minRowBytes(), 0, 0);
81 resource.mailbox_holder.mailbox = bitmap->id();
82 resource.is_software = true;
83 84
84 // Hold ref to |bitmap|, to keep it alive until the browser ReturnRe sources. 85 // Hold ref to |image|, to keep it alive until the browser ReturnResourc es.
85 // It guarantees that the shared bitmap is not re-used or deleted. 86 // It guarantees that the resource is not re-used or deleted.
86 m_sharedBitmaps.add(getNextResourceIdAndIncrement(), std::move(bitma p)); 87 m_cachedImages.add(getNextResourceIdAndIncrement(), std::move(image));
87 } else { 88 }
88 image->ensureMailbox(); 89 // TODO(crbug.com/646022): making this overlay-able.
89 resource.mailbox_holder = gpu::MailboxHolder(image->getMailbox(), im age->getSyncToken(), GL_TEXTURE_2D); 90 resource.is_overlay_candidate = false;
90 resource.read_lock_fences_enabled = false;
91 resource.is_software = false;
92 91
93 // Hold ref to |image|, to keep it alive until the browser ReturnRes ources. 92 frame.delegated_frame_data->resource_list.push_back(std::move(resource));
94 // It guarantees that the resource is not re-used or deleted.
95 m_cachedImages.add(getNextResourceIdAndIncrement(), std::move(image) );
96 }
97 // TODO(crbug.com/646022): making this overlay-able.
98 resource.is_overlay_candidate = false;
99 93
100 frame.delegated_frame_data->resource_list.push_back(std::move(resource)) ; 94 cc::TextureDrawQuad* quad = pass->CreateAndAppendDrawQuad<cc::TextureDrawQua d>();
95 gfx::Size rectSize(m_width, m_height);
101 96
102 97 const bool needsBlending = true;
103 cc::TextureDrawQuad* quad = pass->CreateAndAppendDrawQuad<cc::TextureDra wQuad>(); 98 // TOOD(crbug.com/645993): this should be inherited from WebGL context's cre ation settings.
104 gfx::Size rectSize(m_width, m_height); 99 const bool premultipliedAlpha = true;
105 100 const gfx::PointF uvTopLeft(0.f, 0.f);
106 const bool needsBlending = true; 101 const gfx::PointF uvBottomRight(1.f, 1.f);
107 // TOOD(crbug.com/645993): this should be inherited from WebGL context's creation settings. 102 float vertexOpacity[4] = { 1.f, 1.f, 1.f, 1.f };
108 const bool premultipliedAlpha = true; 103 const bool yflipped = false;
109 const gfx::PointF uvTopLeft(0.f, 0.f); 104 // TODO(crbug.com/645994): this should be true when using style "image-rende ring: pixelated".
110 const gfx::PointF uvBottomRight(1.f, 1.f); 105 const bool nearestNeighbor = false;
111 float vertexOpacity[4] = { 1.f, 1.f, 1.f, 1.f }; 106 quad->SetAll(sqs, bounds, bounds, bounds, needsBlending, resource.id, gfx::S ize(), premultipliedAlpha,
112 const bool yflipped = false; 107 uvTopLeft, uvBottomRight, SK_ColorTRANSPARENT, vertexOpacity, yflipped, nearestNeighbor, false);
113 // TODO(crbug.com/645994): this should be true when using style "image-r endering: pixelated".
114 const bool nearestNeighbor = false;
115 quad->SetAll(sqs, bounds, bounds, bounds, needsBlending, resource.id, gf x::Size(), premultipliedAlpha,
116 uvTopLeft, uvBottomRight, SK_ColorTRANSPARENT, vertexOpacity, yflipp ed, nearestNeighbor, false);
117 }
118 108
119 frame.delegated_frame_data->render_pass_list.push_back(std::move(pass)); 109 frame.delegated_frame_data->render_pass_list.push_back(std::move(pass));
120 110
121 m_sink->SubmitCompositorFrame(std::move(frame), base::Closure()); 111 m_sink->SubmitCompositorFrame(std::move(frame), base::Closure());
122 } 112 }
123 113
124 void OffscreenCanvasFrameDispatcherImpl::ReturnResources(Vector<cc::mojom::blink ::ReturnedResourcePtr> resources) 114 void OffscreenCanvasFrameDispatcherImpl::ReturnResources(Vector<cc::mojom::blink ::ReturnedResourcePtr> resources)
125 { 115 {
126 for (const auto& resource : resources) { 116 for (const auto& resource : resources) {
127 m_cachedImages.remove(resource->id); 117 m_cachedImages.remove(resource->id);
128 m_sharedBitmaps.remove(resource->id); 118 m_sharedBitmaps.remove(resource->id);
129 } 119 }
130 } 120 }
131 121
132 bool OffscreenCanvasFrameDispatcherImpl::verifyImageSize(const sk_sp<SkImage>& i mage) 122 bool OffscreenCanvasFrameDispatcherImpl::verifyImageSize(const sk_sp<SkImage>& i mage)
133 { 123 {
134 if (image && image->width() == m_width && image->height() == m_height) 124 if (image && image->width() == m_width && image->height() == m_height)
135 return true; 125 return true;
136 return false; 126 return false;
137 } 127 }
138 128
139 } // namespace blink 129 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698