Home | History | Annotate | Download | only in surfaces_app
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "mojo/examples/surfaces_app/embedder.h"
      6 
      7 #include "cc/output/compositor_frame.h"
      8 #include "cc/output/delegated_frame_data.h"
      9 #include "cc/quads/render_pass.h"
     10 #include "cc/quads/solid_color_draw_quad.h"
     11 #include "cc/quads/surface_draw_quad.h"
     12 #include "mojo/examples/surfaces_app/surfaces_util.h"
     13 #include "mojo/services/public/cpp/surfaces/surfaces_type_converters.h"
     14 #include "mojo/services/public/interfaces/surfaces/surface_id.mojom.h"
     15 #include "ui/gfx/rect.h"
     16 #include "ui/gfx/size.h"
     17 #include "ui/gfx/transform.h"
     18 
     19 namespace mojo {
     20 namespace examples {
     21 
     22 using cc::RenderPass;
     23 using cc::RenderPassId;
     24 using cc::SurfaceDrawQuad;
     25 using cc::DrawQuad;
     26 using cc::SolidColorDrawQuad;
     27 using cc::DelegatedFrameData;
     28 using cc::CompositorFrame;
     29 
     30 Embedder::Embedder(Surface* surface) : surface_(surface) {
     31 }
     32 
     33 Embedder::~Embedder() {
     34 }
     35 
     36 void Embedder::ProduceFrame(cc::SurfaceId child_one,
     37                             cc::SurfaceId child_two,
     38                             const gfx::Size& child_size,
     39                             const gfx::Size& size,
     40                             int offset) {
     41   gfx::Rect rect(size);
     42   RenderPassId pass_id(1, 1);
     43   scoped_ptr<RenderPass> pass = RenderPass::Create();
     44   pass->SetNew(pass_id, rect, rect, gfx::Transform());
     45 
     46   if (!child_one.is_null()) {
     47     gfx::Transform one_transform;
     48     one_transform.Translate(10 + child_size.width() / 2,
     49                             50 + child_size.height() / 2);
     50     one_transform.Translate(0, offset);
     51     one_transform.Translate(-child_size.width() / 2, -child_size.height() / 2);
     52     CreateAndAppendSimpleSharedQuadState(pass.get(), one_transform, size);
     53 
     54     SurfaceDrawQuad* surface_one_quad =
     55         pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
     56     gfx::Rect one_rect(child_size);
     57     surface_one_quad->SetNew(
     58         pass->shared_quad_state_list.back(), one_rect, one_rect, child_one);
     59   }
     60 
     61   if (!child_two.is_null()) {
     62     gfx::Transform two_transform;
     63     two_transform.Translate(10 + size.width() / 2 + child_size.width() / 2,
     64                             50 + child_size.height() / 2);
     65     two_transform.Translate(0, 200 - offset);
     66     two_transform.Translate(-child_size.width() / 2, -child_size.height() / 2);
     67     CreateAndAppendSimpleSharedQuadState(pass.get(), two_transform, size);
     68 
     69     SurfaceDrawQuad* surface_two_quad =
     70         pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
     71     gfx::Rect two_rect(child_size);
     72     surface_two_quad->SetNew(
     73         pass->shared_quad_state_list.back(), two_rect, two_rect, child_two);
     74   }
     75 
     76   CreateAndAppendSimpleSharedQuadState(pass.get(), gfx::Transform(), size);
     77   SolidColorDrawQuad* color_quad =
     78       pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
     79   bool force_anti_aliasing_off = false;
     80   color_quad->SetNew(pass->shared_quad_state_list.back(),
     81                      rect,
     82                      rect,
     83                      SK_ColorYELLOW,
     84                      force_anti_aliasing_off);
     85 
     86   scoped_ptr<DelegatedFrameData> delegated_frame_data(new DelegatedFrameData);
     87   delegated_frame_data->render_pass_list.push_back(pass.Pass());
     88 
     89   scoped_ptr<CompositorFrame> frame(new CompositorFrame);
     90   frame->delegated_frame_data = delegated_frame_data.Pass();
     91 
     92   surface_->SubmitFrame(mojo::SurfaceId::From(id_),
     93                         mojo::Frame::From(*frame));
     94 }
     95 
     96 }  // namespace examples
     97 }  // namespace mojo
     98