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

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

Issue 2360413002: Implement OffscreenCanvas Unaccelerated 2d commit() on main thread (Closed)
Patch Set: Mac 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"
11 #include "cc/quads/solid_color_draw_quad.h" 11 #include "cc/quads/solid_color_draw_quad.h"
12 #include "cc/quads/texture_draw_quad.h" 12 #include "cc/quads/texture_draw_quad.h"
13 #include "cc/resources/returned_resource.h" 13 #include "cc/resources/returned_resource.h"
14 #include "platform/RuntimeEnabledFeatures.h"
14 #include "public/platform/InterfaceProvider.h" 15 #include "public/platform/InterfaceProvider.h"
15 #include "public/platform/Platform.h" 16 #include "public/platform/Platform.h"
16 #include "public/platform/modules/offscreencanvas/offscreen_canvas_surface.mojom -blink.h" 17 #include "public/platform/modules/offscreencanvas/offscreen_canvas_surface.mojom -blink.h"
17 #include "third_party/khronos/GLES2/gl2.h" 18 #include "third_party/khronos/GLES2/gl2.h"
18 #include "third_party/skia/include/core/SkColor.h" 19 #include "third_party/skia/include/core/SkColor.h"
19 #include "third_party/skia/include/core/SkImage.h" 20 #include "third_party/skia/include/core/SkImage.h"
20 #include "third_party/skia/include/core/SkXfermode.h" 21 #include "third_party/skia/include/core/SkXfermode.h"
21 #include "ui/gfx/geometry/rect.h" 22 #include "ui/gfx/geometry/rect.h"
22 #include "ui/gfx/transform.h" 23 #include "ui/gfx/transform.h"
23 24
(...skipping 23 matching lines...) Expand all
47 frame.delegated_frame_data.reset(new cc::DelegatedFrameData); 48 frame.delegated_frame_data.reset(new cc::DelegatedFrameData);
48 49
49 const gfx::Rect bounds(m_width, m_height); 50 const gfx::Rect bounds(m_width, m_height);
50 const cc::RenderPassId renderPassId(1, 1); 51 const cc::RenderPassId renderPassId(1, 1);
51 std::unique_ptr<cc::RenderPass> pass = cc::RenderPass::Create(); 52 std::unique_ptr<cc::RenderPass> pass = cc::RenderPass::Create();
52 pass->SetAll(renderPassId, bounds, bounds, gfx::Transform(), false); 53 pass->SetAll(renderPassId, bounds, bounds, gfx::Transform(), false);
53 54
54 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); 55 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState();
55 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);
56 57
57 if (!image->isTextureBacked()) { 58 if (!image->isTextureBacked() && !isMainThread()) {
58 // TODO(xlai): Make unaccelerated 2d canvas work. See crbug.com/563858 59 // TODO(xlai): Implement unaccelerated 2d canvas on worker.
60 // See crbug.com/563858.
59 // This is a temporary code that submits a solidColor frame. 61 // This is a temporary code that submits a solidColor frame.
60 cc::SolidColorDrawQuad* quad = pass->CreateAndAppendDrawQuad<cc::SolidCo lorDrawQuad>(); 62 cc::SolidColorDrawQuad* quad = pass->CreateAndAppendDrawQuad<cc::SolidCo lorDrawQuad>();
61 const bool forceAntialiasingOff = false; 63 const bool forceAntialiasingOff = false;
62 quad->SetNew(sqs, bounds, bounds, SK_ColorGREEN, forceAntialiasingOff); 64 quad->SetNew(sqs, bounds, bounds, SK_ColorGREEN, forceAntialiasingOff);
63 } else { 65 } else {
64 cc::TransferableResource resource; 66 cc::TransferableResource resource;
65 resource.id = m_nextResourceId; 67 resource.id = m_nextResourceId;
66 resource.format = cc::ResourceFormat::RGBA_8888; 68 resource.format = cc::ResourceFormat::RGBA_8888;
67 // TODO(crbug.com/645590): filter should respect the image-rendering CSS property of associated canvas element. 69 // TODO(crbug.com/645590): filter should respect the image-rendering CSS property of associated canvas element.
68 resource.filter = GL_LINEAR; 70 resource.filter = GL_LINEAR;
69 resource.size = gfx::Size(m_width, m_height); 71 resource.size = gfx::Size(m_width, m_height);
70 image->ensureMailbox(); 72 if (!image->isTextureBacked() && !RuntimeEnabledFeatures::accelerated2dC anvasEnabled()) {
Justin Novosad 2016/09/23 20:54:52 You do not need to check RuntimeEnabledFeatures::a
danakj 2016/09/23 20:56:02 Can the image be not hardware but the compositor i
xidachen 2016/09/24 01:20:20 danakj@: Yes, that is possible. I will have a CL i
xlai (Olivia) 2016/09/29 15:53:07 Done.
71 resource.mailbox_holder = gpu::MailboxHolder(image->getMailbox(), image- >getSyncToken(), GL_TEXTURE_2D); 73 std::unique_ptr<cc::SharedBitmap> bitmap = Platform::current()->allo cateSharedBitmap(IntSize(m_width, m_height));
72 resource.read_lock_fences_enabled = false; 74 if (!bitmap)
73 resource.is_software = false; 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 image->imageForCurrentFrame()->readPixels(imageInfo, pixels, imageIn fo.minRowBytes(), 0, 0);
xidachen 2016/09/27 11:22:44 junov@: I have some thoughts about this line. Righ
80 resource.mailbox_holder.mailbox = bitmap->id();
81 resource.mailbox_holder.texture_target = 0;
Justin Novosad 2016/09/23 20:54:52 Is this line really necessary?
xlai (Olivia) 2016/09/29 15:53:07 Done.
82 resource.is_software = true;
83
84 m_sharedBitmaps.add(m_nextResourceId++, std::move(bitmap));
Justin Novosad 2016/09/23 20:54:52 I know this is not currently a bug, but could we d
xlai (Olivia) 2016/09/29 15:53:07 Done. Put that in the function getNextResourceIdAn
85 } else {
86 image->ensureMailbox();
87 resource.mailbox_holder = gpu::MailboxHolder(image->getMailbox(), im age->getSyncToken(), GL_TEXTURE_2D);
88 resource.read_lock_fences_enabled = false;
89 resource.is_software = false;
90
91 // Hold ref to |image|, to keep it alive until the browser ReturnRes ources.
92 // It guarantees that the resource is not re-used or deleted.
Justin Novosad 2016/09/23 20:54:52 Improve this comment to explain why it is not nece
xidachen 2016/09/24 01:20:20 junov@: this is not software path, it is hardware
Justin Novosad 2016/09/27 15:11:15 Let me rephrase. Please explain, in the comments,
danakj 2016/09/27 19:05:20 I think it is needed. Deleting the shared memory b
xidachen 2016/09/27 20:17:23 In my opinion, this is not needed for software pat
xlai (Olivia) 2016/09/29 15:53:07 Exactly. In the software path, after pixels are fi
93 m_cachedImages.add(m_nextResourceId++, std::move(image));
94 }
74 // TODO(crbug.com/646022): making this overlay-able. 95 // TODO(crbug.com/646022): making this overlay-able.
75 resource.is_overlay_candidate = false; 96 resource.is_overlay_candidate = false;
xidachen 2016/09/24 01:20:20 This line should be inside the else block.
xidachen 2016/09/24 01:24:52 Oh, my bad, I believe your intention is to have th
76 97
77 frame.delegated_frame_data->resource_list.push_back(std::move(resource)) ; 98 frame.delegated_frame_data->resource_list.push_back(std::move(resource)) ;
78 99
79 // Hold ref to |image|, to keep it alive until the browser ReturnResourc es.
80 // It guarantees that the resource is not re-used or deleted.
81 m_cachedImages.add(m_nextResourceId++, std::move(image));
82 100
83 cc::TextureDrawQuad* quad = pass->CreateAndAppendDrawQuad<cc::TextureDra wQuad>(); 101 cc::TextureDrawQuad* quad = pass->CreateAndAppendDrawQuad<cc::TextureDra wQuad>();
84 gfx::Size rectSize(m_width, m_height); 102 gfx::Size rectSize(m_width, m_height);
85 103
86 const bool needsBlending = true; 104 const bool needsBlending = true;
87 // TOOD(crbug.com/645993): this should be inherited from WebGL context's creation settings. 105 // TOOD(crbug.com/645993): this should be inherited from WebGL context's creation settings.
88 const bool premultipliedAlpha = true; 106 const bool premultipliedAlpha = true;
89 const gfx::PointF uvTopLeft(0.f, 0.f); 107 const gfx::PointF uvTopLeft(0.f, 0.f);
90 const gfx::PointF uvBottomRight(1.f, 1.f); 108 const gfx::PointF uvBottomRight(1.f, 1.f);
91 float vertexOpacity[4] = { 1.f, 1.f, 1.f, 1.f }; 109 float vertexOpacity[4] = { 1.f, 1.f, 1.f, 1.f };
92 const bool yflipped = false; 110 const bool yflipped = false;
93 // TODO(crbug.com/645994): this should be true when using style "image-r endering: pixelated". 111 // TODO(crbug.com/645994): this should be true when using style "image-r endering: pixelated".
94 const bool nearestNeighbor = false; 112 const bool nearestNeighbor = false;
95 quad->SetAll(sqs, bounds, bounds, bounds, needsBlending, resource.id, gf x::Size(), premultipliedAlpha, 113 quad->SetAll(sqs, bounds, bounds, bounds, needsBlending, resource.id, gf x::Size(), premultipliedAlpha,
96 uvTopLeft, uvBottomRight, SK_ColorTRANSPARENT, vertexOpacity, yflipp ed, nearestNeighbor, false); 114 uvTopLeft, uvBottomRight, SK_ColorTRANSPARENT, vertexOpacity, yflipp ed, nearestNeighbor, false);
97 } 115 }
98 116
99 frame.delegated_frame_data->render_pass_list.push_back(std::move(pass)); 117 frame.delegated_frame_data->render_pass_list.push_back(std::move(pass));
100 118
101 m_sink->SubmitCompositorFrame(std::move(frame), base::Closure()); 119 m_sink->SubmitCompositorFrame(std::move(frame), base::Closure());
102 } 120 }
103 121
104 void OffscreenCanvasFrameDispatcherImpl::ReturnResources(Vector<cc::mojom::blink ::ReturnedResourcePtr> resources) 122 void OffscreenCanvasFrameDispatcherImpl::ReturnResources(Vector<cc::mojom::blink ::ReturnedResourcePtr> resources)
105 { 123 {
106 for (const auto& resource : resources) 124 for (const auto& resource : resources)
107 m_cachedImages.remove(resource->id); 125 m_cachedImages.remove(resource->id);
126 for (const auto& resource : resources)
Justin Novosad 2016/09/23 20:54:52 You could have a single 'for' loop here. Also, for
xlai (Olivia) 2016/09/29 15:53:07 I can't. The ReturnedResource does not have is_sof
127 m_sharedBitmaps.remove(resource->id);
108 } 128 }
109 129
110 bool OffscreenCanvasFrameDispatcherImpl::verifyImageSize(const sk_sp<SkImage>& i mage) 130 bool OffscreenCanvasFrameDispatcherImpl::verifyImageSize(const sk_sp<SkImage>& i mage)
111 { 131 {
112 if (image && image->width() == m_width && image->height() == m_height) 132 if (image && image->width() == m_width && image->height() == m_height)
113 return true; 133 return true;
114 return false; 134 return false;
115 } 135 }
116 136
117 } // namespace blink 137 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698