Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" | |
| 13 #include "platform/graphics/StaticBitmapImage.h" | |
| 12 #include "public/platform/InterfaceProvider.h" | 14 #include "public/platform/InterfaceProvider.h" |
| 13 #include "public/platform/Platform.h" | 15 #include "public/platform/Platform.h" |
| 16 #include "third_party/khronos/GLES2/gl2.h" | |
| 14 #include "third_party/skia/include/core/SkColor.h" | 17 #include "third_party/skia/include/core/SkColor.h" |
| 15 #include "third_party/skia/include/core/SkXfermode.h" | 18 #include "third_party/skia/include/core/SkXfermode.h" |
| 16 #include "ui/gfx/geometry/rect.h" | 19 #include "ui/gfx/geometry/rect.h" |
| 17 #include "ui/gfx/transform.h" | 20 #include "ui/gfx/transform.h" |
| 18 | 21 |
| 19 namespace blink { | 22 namespace blink { |
| 20 | 23 |
| 21 OffscreenCanvasFrameDispatcherImpl::OffscreenCanvasFrameDispatcherImpl(uint32_t clientId, uint32_t localId, uint64_t nonce, int width, int height) | 24 OffscreenCanvasFrameDispatcherImpl::OffscreenCanvasFrameDispatcherImpl(uint32_t clientId, uint32_t localId, uint64_t nonce, int width, int height) |
| 22 : m_surfaceId(cc::SurfaceId(clientId, localId, nonce)) | 25 : m_surfaceId(cc::SurfaceId(clientId, localId, nonce)) |
| 23 , m_width(width) | 26 , m_width(width) |
| 24 , m_height(height) | 27 , m_height(height) |
| 25 { | 28 { |
| 26 DCHECK(!m_service.is_bound()); | 29 DCHECK(!m_service.is_bound()); |
| 27 Platform::current()->interfaceProvider()->getInterface(mojo::GetProxy(&m_ser vice)); | 30 Platform::current()->interfaceProvider()->getInterface(mojo::GetProxy(&m_ser vice)); |
| 28 } | 31 } |
| 29 | 32 |
| 30 void OffscreenCanvasFrameDispatcherImpl::dispatchFrame() | 33 void OffscreenCanvasFrameDispatcherImpl::dispatchFrame(PassRefPtr<StaticBitmapIm age> image) |
| 31 { | 34 { |
| 32 // TODO(563852/xlai): Currently this is just a simple solid-color compositor | |
| 33 // frame. We need to update this function to extract the image data from can vas. | |
| 34 cc::CompositorFrame frame; | 35 cc::CompositorFrame frame; |
| 35 frame.metadata.device_scale_factor = 1.0f; | 36 frame.metadata.device_scale_factor = 1.0f; |
| 36 frame.delegated_frame_data.reset(new cc::DelegatedFrameData); | 37 frame.delegated_frame_data.reset(new cc::DelegatedFrameData); |
| 37 | 38 |
| 38 const gfx::Rect bounds(m_width, m_height); | 39 const gfx::Rect bounds(m_width, m_height); |
| 39 const cc::RenderPassId renderPassId(1, 1); | 40 const cc::RenderPassId renderPassId(1, 1); |
| 40 std::unique_ptr<cc::RenderPass> pass = cc::RenderPass::Create(); | 41 std::unique_ptr<cc::RenderPass> pass = cc::RenderPass::Create(); |
| 41 pass->SetAll(renderPassId, bounds, bounds, gfx::Transform(), false); | 42 pass->SetAll(renderPassId, bounds, bounds, gfx::Transform(), false); |
| 42 | 43 |
| 43 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); | 44 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); |
| 44 sqs->SetAll(gfx::Transform(), bounds.size(), bounds, bounds, false, 1.f, SkX fermode::kSrcOver_Mode, 0); | 45 sqs->SetAll(gfx::Transform(), bounds.size(), bounds, bounds, false, 1.f, SkX fermode::kSrcOver_Mode, 0); |
| 45 | 46 |
| 46 cc::SolidColorDrawQuad* quad = pass->CreateAndAppendDrawQuad<cc::SolidColorD rawQuad>(); | 47 // TODO(xidachen): for now, we just submit a SolidColor frame to compositor in the 2d case, |
| 47 const bool forceAntialiasingOff = false; | 48 // we should extract data from image. |
| 48 quad->SetNew(sqs, bounds, bounds, SK_ColorGREEN, forceAntialiasingOff); | 49 if (!image) { |
| 50 cc::SolidColorDrawQuad* quad = pass->CreateAndAppendDrawQuad<cc::SolidCo lorDrawQuad>(); | |
| 51 const bool forceAntialiasingOff = false; | |
| 52 quad->SetNew(sqs, bounds, bounds, SK_ColorGREEN, forceAntialiasingOff); | |
| 53 } else { // WebGL | |
| 54 cc::TransferableResource resource; | |
|
Justin Novosad
2016/09/09 19:10:51
Here, we should probably assert that 'image' is gp
xidachen
2016/09/09 19:23:42
Done.
| |
| 55 resource.id = image->getTextureId(); | |
|
Justin Novosad
2016/09/09 19:10:50
I suspect is wrong. The texture Id is useless out
xidachen
2016/09/09 19:23:42
I am not very sure. I looked at this example:
http
| |
| 56 resource.format = cc::ResourceFormat::RGBA_8888; | |
|
Justin Novosad
2016/09/09 19:10:51
we should be extracting format from 'image' instea
xidachen
2016/09/09 19:23:42
My impression was that this mailbox is a resource
| |
| 57 resource.filter = GL_LINEAR; | |
|
Justin Novosad
2016/09/09 19:10:51
Please add a TODO and create a crbug for this: the
xidachen
2016/09/09 19:23:42
Done.
| |
| 58 resource.size = gfx::Size(m_width, m_height); | |
| 59 resource.mailbox_holder = gpu::MailboxHolder(image->getMailbox(), image- >getSyncToken(), GL_TEXTURE_2D); | |
| 60 resource.read_lock_fences_enabled = false; | |
| 61 resource.is_software = false; | |
| 62 resource.is_overlay_candidate = false; | |
| 63 frame.delegated_frame_data->resource_list.push_back(std::move(resource)) ; | |
| 64 | |
| 65 cc::TextureDrawQuad* quad = pass->CreateAndAppendDrawQuad<cc::TextureDra wQuad>(); | |
| 66 gfx::Size rectSize(m_width, m_height); | |
| 67 | |
| 68 const bool needsBlending = true; | |
| 69 const bool premultipliedAlpha = true; | |
| 70 const gfx::PointF uvTopLeft(0.f, 0.f); | |
| 71 const gfx::PointF uvBottomRight(1.f, 1.f); | |
| 72 float vertexOpacity[4] = {1.f, 1.f, 1.f, 1.f}; | |
| 73 const bool yflipped = false; | |
| 74 const bool nearestNeighbor = false; | |
|
Justin Novosad
2016/09/09 19:10:50
TODO: needs to be true when using style "image-ren
xidachen
2016/09/09 19:23:42
Done.
| |
| 75 quad->SetAll(sqs, bounds, bounds, bounds, needsBlending, resource.id, gf x::Size(), premultipliedAlpha, | |
| 76 uvTopLeft, uvBottomRight, SK_ColorTRANSPARENT, vertexOpacity, yflipp ed, nearestNeighbor, false); | |
| 77 } | |
| 49 | 78 |
| 50 frame.delegated_frame_data->render_pass_list.push_back(std::move(pass)); | 79 frame.delegated_frame_data->render_pass_list.push_back(std::move(pass)); |
| 51 | 80 |
| 52 m_service->SubmitCompositorFrame(m_surfaceId, std::move(frame)); | 81 m_service->SubmitCompositorFrame(m_surfaceId, std::move(frame)); |
| 53 } | 82 } |
| 54 | 83 |
| 55 } // namespace blink | 84 } // namespace blink |
| OLD | NEW |