summaryrefslogtreecommitdiffstats
path: root/cc/test/render_pass_test_utils.cc
blob: 4c17edd866efcca0fd84bfd1fe04c0c638d965f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cc/test/render_pass_test_utils.h"

#include "cc/append_quads_data.h"
#include "cc/quad_sink.h"
#include "cc/render_pass_draw_quad.h"
#include "cc/shared_quad_state.h"
#include "cc/solid_color_draw_quad.h"
#include "cc/test/mock_quad_culler.h"
#include "cc/test/render_pass_test_common.h"
#include "ui/gfx/rect.h"

namespace cc {

TestRenderPass* addRenderPass(RenderPassList& passList,
                              RenderPass::Id id,
                              const gfx::Rect& outputRect,
                              const gfx::Transform& rootTransform) {
  scoped_ptr<TestRenderPass> pass(TestRenderPass::Create());
  pass->SetNew(id, outputRect, outputRect, rootTransform);
  TestRenderPass* saved = pass.get();
  passList.push_back(pass.PassAs<RenderPass>());
  return saved;
}

SolidColorDrawQuad* addQuad(TestRenderPass* pass,
                            const gfx::Rect& rect,
                            SkColor color) {
  MockQuadCuller quadSink(pass->quad_list, pass->shared_quad_state_list);
  AppendQuadsData data(pass->id);
  SharedQuadState* sharedState =
      quadSink.useSharedQuadState(SharedQuadState::Create());
  sharedState->SetAll(gfx::Transform(), rect.size(), rect, rect, false, 1);
  scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::Create();
  quad->SetNew(sharedState, rect, color);
  SolidColorDrawQuad* quadPtr = quad.get();
  quadSink.append(quad.PassAs<DrawQuad>(), &data);
  return quadPtr;
}

SolidColorDrawQuad* addClippedQuad(TestRenderPass* pass,
                                   const gfx::Rect& rect,
                                   SkColor color) {
  MockQuadCuller quadSink(pass->quad_list, pass->shared_quad_state_list);
  AppendQuadsData data(pass->id);
  SharedQuadState* sharedState =
      quadSink.useSharedQuadState(SharedQuadState::Create());
  sharedState->SetAll(gfx::Transform(), rect.size(), rect, rect, true, 1);
  scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::Create();
  quad->SetNew(sharedState, rect, color);
  SolidColorDrawQuad* quadPtr = quad.get();
  quadSink.append(quad.PassAs<DrawQuad>(), &data);
  return quadPtr;
}

void addRenderPassQuad(TestRenderPass* toPass,
                       TestRenderPass* contributingPass) {
  MockQuadCuller quadSink(toPass->quad_list, toPass->shared_quad_state_list);
  AppendQuadsData data(toPass->id);
  gfx::Rect outputRect = contributingPass->output_rect;
  SharedQuadState* sharedState =
      quadSink.useSharedQuadState(SharedQuadState::Create());
  sharedState->SetAll(gfx::Transform(), outputRect.size(), outputRect, outputRect, false, 1);
  scoped_ptr<RenderPassDrawQuad> quad = RenderPassDrawQuad::Create();
  quad->SetNew(sharedState, outputRect, contributingPass->id, false, 0,
               outputRect, gfx::RectF(), WebKit::WebFilterOperations(),
               skia::RefPtr<SkImageFilter>(), WebKit::WebFilterOperations());
  quadSink.append(quad.PassAs<DrawQuad>(), &data);
}

}  // namespace cc