summaryrefslogtreecommitdiffstats
path: root/chromium/cc/quads/draw_quad.cc
blob: f3cd81895457b8ca8e50b2d7da7fb6d7f0154e22 (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// 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/quads/draw_quad.h"

#include "base/logging.h"
#include "base/values.h"
#include "cc/base/math_util.h"
#include "cc/debug/traced_value.h"
#include "cc/quads/checkerboard_draw_quad.h"
#include "cc/quads/debug_border_draw_quad.h"
#include "cc/quads/io_surface_draw_quad.h"
#include "cc/quads/picture_draw_quad.h"
#include "cc/quads/render_pass_draw_quad.h"
#include "cc/quads/solid_color_draw_quad.h"
#include "cc/quads/stream_video_draw_quad.h"
#include "cc/quads/texture_draw_quad.h"
#include "cc/quads/tile_draw_quad.h"
#include "cc/quads/yuv_video_draw_quad.h"
#include "ui/gfx/quad_f.h"

namespace {
template<typename T> T* TypedCopy(const cc::DrawQuad* other) {
  return new T(*T::MaterialCast(other));
}
}  // namespace

namespace cc {

DrawQuad::DrawQuad()
    : material(INVALID),
      needs_blending(false),
      shared_quad_state() {
}

void DrawQuad::SetAll(const SharedQuadState* shared_quad_state,
                      Material material,
                      gfx::Rect rect,
                      gfx::Rect opaque_rect,
                      gfx::Rect visible_rect,
                      bool needs_blending) {
  DCHECK(rect.Contains(visible_rect)) << "rect: " << rect.ToString()
                                      << " visible_rect: "
                                      << visible_rect.ToString();
  DCHECK(opaque_rect.IsEmpty() || rect.Contains(opaque_rect))
      << "rect: " << rect.ToString() << "opaque_rect "
      << opaque_rect.ToString();

  this->material = material;
  this->rect = rect;
  this->opaque_rect = opaque_rect;
  this->visible_rect = visible_rect;
  this->needs_blending = needs_blending;
  this->shared_quad_state = shared_quad_state;

  DCHECK(shared_quad_state);
  DCHECK(material != INVALID);
}

DrawQuad::~DrawQuad() {
}

scoped_ptr<DrawQuad> DrawQuad::Copy(
    const SharedQuadState* copied_shared_quad_state) const {
  scoped_ptr<DrawQuad> copy_quad;
  switch (material) {
    case CHECKERBOARD:
      copy_quad.reset(TypedCopy<CheckerboardDrawQuad>(this));
      break;
    case DEBUG_BORDER:
      copy_quad.reset(TypedCopy<DebugBorderDrawQuad>(this));
      break;
    case IO_SURFACE_CONTENT:
      copy_quad.reset(TypedCopy<IOSurfaceDrawQuad>(this));
      break;
    case PICTURE_CONTENT:
      copy_quad.reset(TypedCopy<PictureDrawQuad>(this));
      break;
    case TEXTURE_CONTENT:
      copy_quad.reset(TypedCopy<TextureDrawQuad>(this));
      break;
    case SOLID_COLOR:
      copy_quad.reset(TypedCopy<SolidColorDrawQuad>(this));
      break;
    case TILED_CONTENT:
      copy_quad.reset(TypedCopy<TileDrawQuad>(this));
      break;
    case STREAM_VIDEO_CONTENT:
      copy_quad.reset(TypedCopy<StreamVideoDrawQuad>(this));
      break;
    case YUV_VIDEO_CONTENT:
      copy_quad.reset(TypedCopy<YUVVideoDrawQuad>(this));
      break;
    case RENDER_PASS:  // RenderPass quads have their own copy() method.
    case INVALID:
      LOG(FATAL) << "Invalid DrawQuad material " << material;
      break;
  }
  copy_quad->shared_quad_state = copied_shared_quad_state;
  return copy_quad.Pass();
}

scoped_ptr<base::Value> DrawQuad::AsValue() const {
  scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
  value->SetInteger("material", material);
  value->Set("shared_state",
             TracedValue::CreateIDRef(shared_quad_state).release());

  value->Set("content_space_rect", MathUtil::AsValue(rect).release());
  bool rect_is_clipped;
  gfx::QuadF rect_as_target_space_quad = MathUtil::MapQuad(
      shared_quad_state->content_to_target_transform,
      gfx::QuadF(rect),
      &rect_is_clipped);
  value->Set("rect_as_target_space_quad",
             MathUtil::AsValue(rect_as_target_space_quad).release());
  value->SetBoolean("rect_is_clipped", rect_is_clipped);

  value->Set("content_space_opaque_rect",
             MathUtil::AsValue(opaque_rect).release());
  bool opaque_rect_is_clipped;
  gfx::QuadF opaque_rect_as_target_space_quad = MathUtil::MapQuad(
      shared_quad_state->content_to_target_transform,
      gfx::QuadF(opaque_rect),
      &opaque_rect_is_clipped);
  value->Set("opaque_rect_as_target_space_quad",
             MathUtil::AsValue(opaque_rect_as_target_space_quad).release());
  value->SetBoolean("opaque_rect_is_clipped", opaque_rect_is_clipped);

  value->Set("content_space_visible_rect",
             MathUtil::AsValue(visible_rect).release());
  bool visible_rect_is_clipped;
  gfx::QuadF visible_rect_as_target_space_quad = MathUtil::MapQuad(
      shared_quad_state->content_to_target_transform,
      gfx::QuadF(visible_rect),
      &visible_rect_is_clipped);
  value->Set("visible_rect_as_target_space_quad",
             MathUtil::AsValue(visible_rect_as_target_space_quad).release());
  value->SetBoolean("visible_rect_is_clipped", visible_rect_is_clipped);

  value->SetBoolean("needs_blending", needs_blending);
  value->SetBoolean("should_draw_with_blending", ShouldDrawWithBlending());
  ExtendValue(value.get());
  return value.PassAs<base::Value>();
}

}  // namespace cc