diff options
author | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-18 07:50:56 +0000 |
---|---|---|
committer | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-18 07:50:56 +0000 |
commit | 89e8267acd40726861cbe9eef803534000286c70 (patch) | |
tree | de43b0649d24dc07f1ed01845b2d9c9612485014 /cc/quads | |
parent | 20e99aef44b446c91465cd7b64b8e126c6387620 (diff) | |
download | chromium_src-89e8267acd40726861cbe9eef803534000286c70.zip chromium_src-89e8267acd40726861cbe9eef803534000286c70.tar.gz chromium_src-89e8267acd40726861cbe9eef803534000286c70.tar.bz2 |
Part 6 of cc/ directory shuffles: quads
Continuation of https://src.chromium.org/viewvc/chrome?view=rev&revision=188681
BUG=190824
TBR=enne@chromium.org, jschuh@chromium.org
Review URL: https://codereview.chromium.org/12913005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188693 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/quads')
26 files changed, 2379 insertions, 0 deletions
diff --git a/cc/quads/checkerboard_draw_quad.cc b/cc/quads/checkerboard_draw_quad.cc new file mode 100644 index 0000000..fcc6dc5 --- /dev/null +++ b/cc/quads/checkerboard_draw_quad.cc @@ -0,0 +1,48 @@ +// 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/checkerboard_draw_quad.h" + +#include "base/logging.h" + +namespace cc { + +CheckerboardDrawQuad::CheckerboardDrawQuad() : color(0) {} + +scoped_ptr<CheckerboardDrawQuad> CheckerboardDrawQuad::Create() { + return make_scoped_ptr(new CheckerboardDrawQuad); +} + +void CheckerboardDrawQuad::SetNew(const SharedQuadState* shared_quad_state, + gfx::Rect rect, + SkColor color) { + gfx::Rect opaque_rect = SkColorGetA(color) == 255 ? rect : gfx::Rect(); + gfx::Rect visible_rect = rect; + bool needs_blending = false; + DrawQuad::SetAll(shared_quad_state, DrawQuad::CHECKERBOARD, rect, opaque_rect, + visible_rect, needs_blending); + this->color = color; +} + +void CheckerboardDrawQuad::SetAll(const SharedQuadState* shared_quad_state, + gfx::Rect rect, + gfx::Rect opaque_rect, + gfx::Rect visible_rect, + bool needs_blending, + SkColor color) { + DrawQuad::SetAll(shared_quad_state, DrawQuad::CHECKERBOARD, rect, opaque_rect, + visible_rect, needs_blending); + this->color = color; +} + +void CheckerboardDrawQuad::IterateResources( + const ResourceIteratorCallback& callback) {} + +const CheckerboardDrawQuad* CheckerboardDrawQuad::MaterialCast( + const DrawQuad* quad) { + DCHECK(quad->material == DrawQuad::CHECKERBOARD); + return static_cast<const CheckerboardDrawQuad*>(quad); +} + +} // namespace cc diff --git a/cc/quads/checkerboard_draw_quad.h b/cc/quads/checkerboard_draw_quad.h new file mode 100644 index 0000000..53d1c5e --- /dev/null +++ b/cc/quads/checkerboard_draw_quad.h @@ -0,0 +1,42 @@ +// 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. + +#ifndef CC_QUADS_CHECKERBOARD_DRAW_QUAD_H_ +#define CC_QUADS_CHECKERBOARD_DRAW_QUAD_H_ + +#include "base/memory/scoped_ptr.h" +#include "cc/base/cc_export.h" +#include "cc/quads/draw_quad.h" +#include "third_party/skia/include/core/SkColor.h" + +namespace cc { + +class CC_EXPORT CheckerboardDrawQuad : public DrawQuad { + public: + static scoped_ptr<CheckerboardDrawQuad> Create(); + + void SetNew(const SharedQuadState* shared_quad_state, + gfx::Rect rect, + SkColor color); + + void SetAll(const SharedQuadState* shared_quad_state, + gfx::Rect rect, + gfx::Rect opaque_rect, + gfx::Rect visible_rect, + bool needs_blending, + SkColor color); + + SkColor color; + + virtual void IterateResources(const ResourceIteratorCallback& callback) + OVERRIDE; + + static const CheckerboardDrawQuad* MaterialCast(const DrawQuad*); + private: + CheckerboardDrawQuad(); +}; + +} + +#endif // CC_QUADS_CHECKERBOARD_DRAW_QUAD_H_ diff --git a/cc/quads/debug_border_draw_quad.cc b/cc/quads/debug_border_draw_quad.cc new file mode 100644 index 0000000..1ebc0a6 --- /dev/null +++ b/cc/quads/debug_border_draw_quad.cc @@ -0,0 +1,55 @@ +// 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/debug_border_draw_quad.h" + +#include "base/logging.h" + +namespace cc { + +DebugBorderDrawQuad::DebugBorderDrawQuad() + : color(0), + width(0) { +} + +scoped_ptr<DebugBorderDrawQuad> DebugBorderDrawQuad::Create() { + return make_scoped_ptr(new DebugBorderDrawQuad); +} + +void DebugBorderDrawQuad::SetNew(const SharedQuadState* shared_quad_state, + gfx::Rect rect, + SkColor color, + int width) { + gfx::Rect opaque_rect; + gfx::Rect visible_rect = rect; + bool needs_blending = SkColorGetA(color) < 255; + DrawQuad::SetAll(shared_quad_state, DrawQuad::DEBUG_BORDER, rect, opaque_rect, + visible_rect, needs_blending); + this->color = color; + this->width = width; +} + +void DebugBorderDrawQuad::SetAll(const SharedQuadState* shared_quad_state, + gfx::Rect rect, + gfx::Rect opaque_rect, + gfx::Rect visible_rect, + bool needs_blending, + SkColor color, + int width) { + DrawQuad::SetAll(shared_quad_state, DrawQuad::DEBUG_BORDER, rect, opaque_rect, + visible_rect, needs_blending); + this->color = color; + this->width = width; +} + +void DebugBorderDrawQuad::IterateResources( + const ResourceIteratorCallback& callback) {} + +const DebugBorderDrawQuad* DebugBorderDrawQuad::MaterialCast( + const DrawQuad* quad) { + DCHECK(quad->material == DrawQuad::DEBUG_BORDER); + return static_cast<const DebugBorderDrawQuad*>(quad); +} + +} // namespace cc diff --git a/cc/quads/debug_border_draw_quad.h b/cc/quads/debug_border_draw_quad.h new file mode 100644 index 0000000..80484368 --- /dev/null +++ b/cc/quads/debug_border_draw_quad.h @@ -0,0 +1,45 @@ +// 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. + +#ifndef CC_QUADS_DEBUG_BORDER_DRAW_QUAD_H_ +#define CC_QUADS_DEBUG_BORDER_DRAW_QUAD_H_ + +#include "base/memory/scoped_ptr.h" +#include "cc/base/cc_export.h" +#include "cc/quads/draw_quad.h" +#include "third_party/skia/include/core/SkColor.h" + +namespace cc { + +class CC_EXPORT DebugBorderDrawQuad : public DrawQuad { + public: + static scoped_ptr<DebugBorderDrawQuad> Create(); + + void SetNew(const SharedQuadState* shared_quad_state, + gfx::Rect rect, + SkColor color, + int width); + + void SetAll(const SharedQuadState* shared_quad_state, + gfx::Rect rect, + gfx::Rect opaque_rect, + gfx::Rect visible_rect, + bool needs_blending, + SkColor color, + int width); + + SkColor color; + int width; + + virtual void IterateResources(const ResourceIteratorCallback& callback) + OVERRIDE; + + static const DebugBorderDrawQuad* MaterialCast(const DrawQuad*); + private: + DebugBorderDrawQuad(); +}; + +} + +#endif // CC_QUADS_DEBUG_BORDER_DRAW_QUAD_H_ diff --git a/cc/quads/draw_quad.cc b/cc/quads/draw_quad.cc new file mode 100644 index 0000000..7de1b99 --- /dev/null +++ b/cc/quads/draw_quad.cc @@ -0,0 +1,92 @@ +// 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 "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/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" + +namespace { + +template<typename T> T* TypedCopy(const cc::DrawQuad* other) { + return new T(*T::MaterialCast(other)); +} + +} + +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) { + 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 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(); +} + +} // namespace cc diff --git a/cc/quads/draw_quad.h b/cc/quads/draw_quad.h new file mode 100644 index 0000000..a924330 --- /dev/null +++ b/cc/quads/draw_quad.h @@ -0,0 +1,119 @@ +// 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. + +#ifndef CC_QUADS_DRAW_QUAD_H_ +#define CC_QUADS_DRAW_QUAD_H_ + +#include "base/callback.h" +#include "cc/base/cc_export.h" +#include "cc/quads/shared_quad_state.h" +#include "cc/resource_provider.h" + +namespace cc { + +// DrawQuad is a bag of data used for drawing a quad. Because different +// materials need different bits of per-quad data to render, classes that derive +// from DrawQuad store additional data in their derived instance. The Material +// enum is used to "safely" downcast to the derived class. +class CC_EXPORT DrawQuad { + public: + enum Material { + INVALID, + CHECKERBOARD, + DEBUG_BORDER, + IO_SURFACE_CONTENT, + RENDER_PASS, + TEXTURE_CONTENT, + SOLID_COLOR, + TILED_CONTENT, + YUV_VIDEO_CONTENT, + STREAM_VIDEO_CONTENT, + }; + + virtual ~DrawQuad(); + + scoped_ptr<DrawQuad> Copy( + const SharedQuadState* copied_shared_quad_state) const; + + // TODO(danakj): Chromify or remove these SharedQuadState helpers. + const gfx::Transform& quadTransform() const { return shared_quad_state->content_to_target_transform; } + gfx::Rect visibleContentRect() const { return shared_quad_state->visible_content_rect; } + gfx::Rect clipRect() const { return shared_quad_state->clip_rect; } + bool isClipped() const { return shared_quad_state->is_clipped; } + float opacity() const { return shared_quad_state->opacity; } + + Material material; + + // This rect, after applying the quad_transform(), gives the geometry that + // this quad should draw to. + gfx::Rect rect; + + // This specifies the region of the quad that is opaque. + gfx::Rect opaque_rect; + + // Allows changing the rect that gets drawn to make it smaller. This value + // should be clipped to quadRect. + gfx::Rect visible_rect; + + // By default blending is used when some part of the quad is not opaque. + // With this setting, it is possible to force blending on regardless of the + // opaque area. + bool needs_blending; + + // Stores state common to a large bundle of quads; kept separate for memory + // efficiency. There is special treatment to reconstruct these pointers + // during serialization. + const SharedQuadState* shared_quad_state; + + bool IsDebugQuad() const { return material == DEBUG_BORDER; } + + bool ShouldDrawWithBlending() const { + return needs_blending || shared_quad_state->opacity < 1.0f || + !opaque_rect.Contains(visible_rect); + } + + typedef base::Callback<ResourceProvider::ResourceId( + ResourceProvider::ResourceId)> ResourceIteratorCallback; + virtual void IterateResources(const ResourceIteratorCallback& callback) = 0; + + // Is the left edge of this tile aligned with the originating layer's + // left edge? + bool IsLeftEdge() const { return !rect.x(); } + + // Is the top edge of this tile aligned with the originating layer's + // top edge? + bool IsTopEdge() const { return !rect.y(); } + + // Is the right edge of this tile aligned with the originating layer's + // right edge? + bool IsRightEdge() const { + return rect.right() == shared_quad_state->content_bounds.width(); + } + + // Is the bottom edge of this tile aligned with the originating layer's + // bottom edge? + bool IsBottomEdge() const { + return rect.bottom() == shared_quad_state->content_bounds.height(); + } + + // Is any edge of this tile aligned with the originating layer's + // corresponding edge? + bool IsEdge() const { + return IsLeftEdge() || IsTopEdge() || IsRightEdge() || IsBottomEdge(); + } + + protected: + DrawQuad(); + + void SetAll(const SharedQuadState* shared_quad_state, + Material material, + gfx::Rect rect, + gfx::Rect opaque_rect, + gfx::Rect visible_rect, + bool needs_blending); +}; + +} + +#endif // CC_QUADS_DRAW_QUAD_H_ diff --git a/cc/quads/draw_quad_unittest.cc b/cc/quads/draw_quad_unittest.cc new file mode 100644 index 0000000..3c7eecb --- /dev/null +++ b/cc/quads/draw_quad_unittest.cc @@ -0,0 +1,681 @@ +// 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/bind.h" +#include "cc/base/math_util.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/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 "cc/test/geometry_test_utils.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperations.h" +#include "third_party/skia/include/effects/SkBlurImageFilter.h" +#include "ui/gfx/transform.h" + +namespace cc { +namespace { + +TEST(DrawQuadTest, copySharedQuadState) +{ + gfx::Transform quadTransform = gfx::Transform(1.0, 0.0, 0.5, 1.0, 0.5, 0.0); + gfx::Size contentBounds(26, 28); + gfx::Rect visibleContentRect(10, 12, 14, 16); + gfx::Rect clipRect(19, 21, 23, 25); + bool isClipped = true; + float opacity = 0.25; + + scoped_ptr<SharedQuadState> state(SharedQuadState::Create()); + state->SetAll(quadTransform, contentBounds, visibleContentRect, clipRect, + isClipped, opacity); + + scoped_ptr<SharedQuadState> copy(state->Copy()); + EXPECT_EQ(quadTransform, copy->content_to_target_transform); + EXPECT_RECT_EQ(visibleContentRect, copy->visible_content_rect); + EXPECT_EQ(opacity, copy->opacity); + EXPECT_RECT_EQ(clipRect, copy->clip_rect); + EXPECT_EQ(isClipped, copy->is_clipped); +} + +scoped_ptr<SharedQuadState> createSharedQuadState() +{ + gfx::Transform quadTransform = gfx::Transform(1.0, 0.0, 0.5, 1.0, 0.5, 0.0); + gfx::Size contentBounds(26, 28); + gfx::Rect visibleContentRect(10, 12, 14, 16); + gfx::Rect clipRect(19, 21, 23, 25); + bool isClipped = false; + float opacity = 1; + + scoped_ptr<SharedQuadState> state(SharedQuadState::Create()); + state->SetAll(quadTransform, contentBounds, visibleContentRect, clipRect, + isClipped, opacity); + return state.Pass(); +} + +void compareDrawQuad(DrawQuad* quad, DrawQuad* copy, SharedQuadState* copySharedState) +{ + EXPECT_EQ(quad->material, copy->material); + EXPECT_RECT_EQ(quad->rect, copy->rect); + EXPECT_RECT_EQ(quad->visible_rect, copy->visible_rect); + EXPECT_RECT_EQ(quad->opaque_rect, copy->opaque_rect); + EXPECT_EQ(quad->needs_blending, copy->needs_blending); + EXPECT_EQ(copySharedState, copy->shared_quad_state); +} + +#define CREATE_SHARED_STATE() \ + scoped_ptr<SharedQuadState> sharedState(createSharedQuadState()); \ + scoped_ptr<SharedQuadState> copySharedState(sharedState->Copy()); \ + +#define QUAD_DATA \ + gfx::Rect quadRect(30, 40, 50, 60); \ + gfx::Rect quadVisibleRect(40, 50, 30, 20); \ + gfx::Rect quadOpaqueRect(60, 55, 10, 10); \ + bool needsBlending = true; + +#define SETUP_AND_COPY_QUAD_NEW(Type, quad) \ + scoped_ptr<DrawQuad> copyNew(quadNew->Copy(copySharedState.get())); \ + compareDrawQuad(quadNew.get(), copyNew.get(), copySharedState.get()); \ + const Type* copyQuad = Type::MaterialCast(copyNew.get()); + +#define SETUP_AND_COPY_QUAD_ALL(Type, quad) \ + scoped_ptr<DrawQuad> copyAll(quadAll->Copy(copySharedState.get())); \ + compareDrawQuad(quadAll.get(), copyAll.get(), copySharedState.get()); \ + copyQuad = Type::MaterialCast(copyAll.get()); + +#define SETUP_AND_COPY_QUAD_NEW_1(Type, quad, a) \ + scoped_ptr<DrawQuad> copyNew(quadNew->Copy(copySharedState.get(), a)); \ + compareDrawQuad(quadNew.get(), copyNew.get(), copySharedState.get()); \ + const Type* copyQuad = Type::MaterialCast(copyNew.get()); + +#define SETUP_AND_COPY_QUAD_ALL_1(Type, quad, a) \ + scoped_ptr<DrawQuad> copyAll(quadAll->Copy(copySharedState.get(), a)); \ + compareDrawQuad(quadAll.get(), copyAll.get(), copySharedState.get()); \ + copyQuad = Type::MaterialCast(copyAll.get()); + +#define CREATE_QUAD_1_NEW(Type, a) \ + scoped_ptr<Type> quadNew(Type::Create()); \ + { QUAD_DATA \ + quadNew->SetNew(sharedState.get(), quadRect, a); } \ + SETUP_AND_COPY_QUAD_NEW(Type, quadNew); + +#define CREATE_QUAD_1_ALL(Type, a) \ + scoped_ptr<Type> quadAll(Type::Create()); \ + { QUAD_DATA \ + quadAll->SetAll(sharedState.get(), quadRect, quadOpaqueRect, quadVisibleRect, needsBlending, a); } \ + SETUP_AND_COPY_QUAD_ALL(Type, quadAll); + +#define CREATE_QUAD_2_NEW(Type, a, b) \ + scoped_ptr<Type> quadNew(Type::Create()); \ + { QUAD_DATA \ + quadNew->SetNew(sharedState.get(), quadRect, a, b); } \ + SETUP_AND_COPY_QUAD_NEW(Type, quadNew); + +#define CREATE_QUAD_2_ALL(Type, a, b) \ + scoped_ptr<Type> quadAll(Type::Create()); \ + { QUAD_DATA \ + quadAll->SetAll(sharedState.get(), quadRect, quadOpaqueRect, quadVisibleRect, needsBlending, a, b); } \ + SETUP_AND_COPY_QUAD_ALL(Type, quadAll); + +#define CREATE_QUAD_3_NEW(Type, a, b, c) \ + scoped_ptr<Type> quadNew(Type::Create()); \ + { QUAD_DATA \ + quadNew->SetNew(sharedState.get(), quadRect, a, b, c); } \ + SETUP_AND_COPY_QUAD_NEW(Type, quadNew); + +#define CREATE_QUAD_3_ALL(Type, a, b, c) \ + scoped_ptr<Type> quadAll(Type::Create()); \ + { QUAD_DATA \ + quadAll->SetAll(sharedState.get(), quadRect, quadOpaqueRect, quadVisibleRect, needsBlending, a, b, c); } \ + SETUP_AND_COPY_QUAD_ALL(Type, quadAll); + +#define CREATE_QUAD_4_NEW(Type, a, b, c, d) \ + scoped_ptr<Type> quadNew(Type::Create()); \ + { QUAD_DATA \ + quadNew->SetNew(sharedState.get(), quadRect, a, b, c, d); } \ + SETUP_AND_COPY_QUAD_NEW(Type, quadNew); + +#define CREATE_QUAD_4_ALL(Type, a, b, c, d) \ + scoped_ptr<Type> quadAll(Type::Create()); \ + { QUAD_DATA \ + quadAll->SetAll(sharedState.get(), quadRect, quadOpaqueRect, quadVisibleRect, needsBlending, a, b, c, d); } \ + SETUP_AND_COPY_QUAD_ALL(Type, quadAll); + +#define CREATE_QUAD_5_NEW(Type, a, b, c, d, e) \ + scoped_ptr<Type> quadNew(Type::Create()); \ + { QUAD_DATA \ + quadNew->SetNew(sharedState.get(), quadRect, a, b, c, d, e); } \ + SETUP_AND_COPY_QUAD_NEW(Type, quadNew); + +#define CREATE_QUAD_5_ALL(Type, a, b, c, d, e) \ + scoped_ptr<Type> quadAll(Type::Create()); \ + { QUAD_DATA \ + quadAll->SetAll(sharedState.get(), quadRect, quadOpaqueRect, quadVisibleRect, needsBlending, a, b, c, d, e); } \ + SETUP_AND_COPY_QUAD_ALL(Type, quadAll); + +#define CREATE_QUAD_5_NEW_1(Type, a, b, c, d, e, copyA) \ + scoped_ptr<Type> quadNew(Type::Create()); \ + { QUAD_DATA \ + quadNew->SetNew(sharedState.get(), quadRect, a, b, c, d, e); } \ + SETUP_AND_COPY_QUAD_NEW_1(Type, quadNew, copyA); + +#define CREATE_QUAD_5_ALL_1(Type, a, b, c, d, e, copyA) \ + scoped_ptr<Type> quadAll(Type::Create()); \ + { QUAD_DATA \ + quadAll->SetAll(sharedState.get(), quadRect, quadOpaqueRect, quadVisibleRect, needsBlending, a, b, c, d, e); } \ + SETUP_AND_COPY_QUAD_ALL_1(Type, quadAll, copyA); + +#define CREATE_QUAD_6_NEW(Type, a, b, c, d, e, f) \ + scoped_ptr<Type> quadNew(Type::Create()); \ + { QUAD_DATA \ + quadNew->SetNew(sharedState.get(), quadRect, a, b, c, d, e, f); } \ + SETUP_AND_COPY_QUAD_NEW(Type, quadNew); + +#define CREATE_QUAD_6_ALL(Type, a, b, c, d, e, f) \ + scoped_ptr<Type> quadAll(Type::Create()); \ + { QUAD_DATA \ + quadAll->SetAll(sharedState.get(), quadRect, quadOpaqueRect, quadVisibleRect, needsBlending, a, b, c, d, e, f); } \ + SETUP_AND_COPY_QUAD_ALL(Type, quadAll); + +#define CREATE_QUAD_7_NEW(Type, a, b, c, d, e, f, g) \ + scoped_ptr<Type> quadNew(Type::Create()); \ + { QUAD_DATA \ + quadNew->SetNew(sharedState.get(), quadRect, a, b, c, d, e, f, g); } \ + SETUP_AND_COPY_QUAD_NEW(Type, quadNew); + +#define CREATE_QUAD_7_ALL(Type, a, b, c, d, e, f, g) \ + scoped_ptr<Type> quadAll(Type::Create()); \ + { QUAD_DATA \ + quadAll->SetAll(sharedState.get(), quadRect, quadOpaqueRect, quadVisibleRect, needsBlending, a, b, c, d, e, f, g); } \ + SETUP_AND_COPY_QUAD_ALL(Type, quadAll); + +#define CREATE_QUAD_8_NEW(Type, a, b, c, d, e, f, g, h) \ + scoped_ptr<Type> quadNew(Type::Create()); \ + { QUAD_DATA \ + quadNew->SetNew(sharedState.get(), quadRect, a, b, c, d, e, f, g, h); } \ + SETUP_AND_COPY_QUAD_NEW(Type, quadNew); + +#define CREATE_QUAD_8_ALL(Type, a, b, c, d, e, f, g, h) \ + scoped_ptr<Type> quadAll(Type::Create()); \ + { QUAD_DATA \ + quadAll->SetAll(sharedState.get(), quadRect, quadOpaqueRect, quadVisibleRect, needsBlending, a, b, c, d, e, f, g, h); } \ + SETUP_AND_COPY_QUAD_ALL(Type, quadAll); + +#define CREATE_QUAD_8_NEW_1(Type, a, b, c, d, e, f, g, h, copyA) \ + scoped_ptr<Type> quadNew(Type::Create()); \ + { QUAD_DATA \ + quadNew->SetNew(sharedState.get(), quadRect, a, b, c, d, e, f, g, h); } \ + SETUP_AND_COPY_QUAD_NEW_1(Type, quadNew, copyA); + +#define CREATE_QUAD_8_ALL_1(Type, a, b, c, d, e, f, g, h, copyA) \ + scoped_ptr<Type> quadAll(Type::Create()); \ + { QUAD_DATA \ + quadAll->SetAll(sharedState.get(), quadRect, quadOpaqueRect, quadVisibleRect, needsBlending, a, b, c, d, e, f, g, h); } \ + SETUP_AND_COPY_QUAD_ALL_1(Type, quadAll, copyA); + +#define CREATE_QUAD_9_NEW(Type, a, b, c, d, e, f, g, h, i) \ + scoped_ptr<Type> quadNew(Type::Create()); \ + { QUAD_DATA \ + quadNew->SetNew(sharedState.get(), quadRect, a, b, c, d, e, f, g, h, i); } \ + SETUP_AND_COPY_QUAD_NEW(Type, quadNew); + +#define CREATE_QUAD_9_ALL(Type, a, b, c, d, e, f, g, h, i) \ + scoped_ptr<Type> quadAll(Type::Create()); \ + { QUAD_DATA \ + quadAll->SetAll(sharedState.get(), quadRect, quadOpaqueRect, quadVisibleRect, needsBlending, a, b, c, d, e, f, g, h, i); } \ + SETUP_AND_COPY_QUAD_ALL(Type, quadAll); + +TEST(DrawQuadTest, copyCheckerboardDrawQuad) +{ + SkColor color = 0xfabb0011; + CREATE_SHARED_STATE(); + + CREATE_QUAD_1_NEW(CheckerboardDrawQuad, color); + EXPECT_EQ(DrawQuad::CHECKERBOARD, copyQuad->material); + EXPECT_EQ(color, copyQuad->color); + + CREATE_QUAD_1_ALL(CheckerboardDrawQuad, color); + EXPECT_EQ(DrawQuad::CHECKERBOARD, copyQuad->material); + EXPECT_EQ(color, copyQuad->color); +} + +TEST(DrawQuadTest, copyDebugBorderDrawQuad) +{ + SkColor color = 0xfabb0011; + int width = 99; + CREATE_SHARED_STATE(); + + CREATE_QUAD_2_NEW(DebugBorderDrawQuad, color, width); + EXPECT_EQ(DrawQuad::DEBUG_BORDER, copyQuad->material); + EXPECT_EQ(color, copyQuad->color); + EXPECT_EQ(width, copyQuad->width); + + CREATE_QUAD_2_ALL(DebugBorderDrawQuad, color, width); + EXPECT_EQ(DrawQuad::DEBUG_BORDER, copyQuad->material); + EXPECT_EQ(color, copyQuad->color); + EXPECT_EQ(width, copyQuad->width); +} + +TEST(DrawQuadTest, copyIOSurfaceDrawQuad) +{ + gfx::Rect opaqueRect(3, 7, 10, 12); + gfx::Size size(58, 95); + unsigned textureId = 72; + IOSurfaceDrawQuad::Orientation orientation = IOSurfaceDrawQuad::UNFLIPPED; + CREATE_SHARED_STATE(); + + CREATE_QUAD_4_NEW(IOSurfaceDrawQuad, opaqueRect, size, textureId, orientation); + EXPECT_EQ(DrawQuad::IO_SURFACE_CONTENT, copyQuad->material); + EXPECT_RECT_EQ(opaqueRect, copyQuad->opaque_rect); + EXPECT_EQ(size, copyQuad->io_surface_size); + EXPECT_EQ(textureId, copyQuad->io_surface_texture_id); + EXPECT_EQ(orientation, copyQuad->orientation); + + CREATE_QUAD_3_ALL(IOSurfaceDrawQuad, size, textureId, orientation); + EXPECT_EQ(DrawQuad::IO_SURFACE_CONTENT, copyQuad->material); + EXPECT_EQ(size, copyQuad->io_surface_size); + EXPECT_EQ(textureId, copyQuad->io_surface_texture_id); + EXPECT_EQ(orientation, copyQuad->orientation); +} + +TEST(DrawQuadTest, copyRenderPassDrawQuad) +{ + RenderPass::Id renderPassId(22, 64); + bool isReplica = true; + ResourceProvider::ResourceId maskResourceId = 78; + gfx::Rect contentsChangedSinceLastFrame(42, 11, 74, 24); + gfx::RectF maskUVRect(-45, -21, 33, 19); + WebKit::WebFilterOperations filters; + filters.append(WebKit::WebFilterOperation::createBlurFilter(1.f)); + WebKit::WebFilterOperations background_filters; + background_filters.append( + WebKit::WebFilterOperation::createGrayscaleFilter(1.f)); + skia::RefPtr<SkImageFilter> filter = skia::AdoptRef( + new SkBlurImageFilter(SK_Scalar1, SK_Scalar1)); + + RenderPass::Id copiedRenderPassId(235, 11); + CREATE_SHARED_STATE(); + + CREATE_QUAD_8_NEW_1(RenderPassDrawQuad, renderPassId, isReplica, maskResourceId, contentsChangedSinceLastFrame, maskUVRect, filters, filter, background_filters, copiedRenderPassId); + EXPECT_EQ(DrawQuad::RENDER_PASS, copyQuad->material); + EXPECT_EQ(copiedRenderPassId, copyQuad->render_pass_id); + EXPECT_EQ(isReplica, copyQuad->is_replica); + EXPECT_EQ(maskResourceId, copyQuad->mask_resource_id); + EXPECT_RECT_EQ(contentsChangedSinceLastFrame, copyQuad->contents_changed_since_last_frame); + EXPECT_EQ(maskUVRect.ToString(), copyQuad->mask_uv_rect.ToString()); + EXPECT_EQ(filters, copyQuad->filters); + EXPECT_EQ(filter, copyQuad->filter); + EXPECT_EQ(background_filters, copyQuad->background_filters); + + CREATE_QUAD_8_ALL_1(RenderPassDrawQuad, renderPassId, isReplica, maskResourceId, contentsChangedSinceLastFrame, maskUVRect, filters, filter, background_filters, copiedRenderPassId); + EXPECT_EQ(DrawQuad::RENDER_PASS, copyQuad->material); + EXPECT_EQ(copiedRenderPassId, copyQuad->render_pass_id); + EXPECT_EQ(isReplica, copyQuad->is_replica); + EXPECT_EQ(maskResourceId, copyQuad->mask_resource_id); + EXPECT_RECT_EQ(contentsChangedSinceLastFrame, copyQuad->contents_changed_since_last_frame); + EXPECT_EQ(maskUVRect.ToString(), copyQuad->mask_uv_rect.ToString()); + EXPECT_EQ(filters, copyQuad->filters); + EXPECT_EQ(filter, copyQuad->filter); + EXPECT_EQ(background_filters, copyQuad->background_filters); +} + +TEST(DrawQuadTest, copySolidColorDrawQuad) +{ + SkColor color = 0x49494949; + CREATE_SHARED_STATE(); + + CREATE_QUAD_1_NEW(SolidColorDrawQuad, color); + EXPECT_EQ(DrawQuad::SOLID_COLOR, copyQuad->material); + EXPECT_EQ(color, copyQuad->color); + + CREATE_QUAD_1_ALL(SolidColorDrawQuad, color); + EXPECT_EQ(DrawQuad::SOLID_COLOR, copyQuad->material); + EXPECT_EQ(color, copyQuad->color); +} + +TEST(DrawQuadTest, copyStreamVideoDrawQuad) +{ + gfx::Rect opaqueRect(3, 7, 10, 12); + unsigned textureId = 64; + gfx::Transform matrix = gfx::Transform(0.5, 0.25, 1, 0.75, 0, 1); + CREATE_SHARED_STATE(); + + CREATE_QUAD_3_NEW(StreamVideoDrawQuad, opaqueRect, textureId, matrix); + EXPECT_EQ(DrawQuad::STREAM_VIDEO_CONTENT, copyQuad->material); + EXPECT_RECT_EQ(opaqueRect, copyQuad->opaque_rect); + EXPECT_EQ(textureId, copyQuad->texture_id); + EXPECT_EQ(matrix, copyQuad->matrix); + + CREATE_QUAD_2_ALL(StreamVideoDrawQuad, textureId, matrix); + EXPECT_EQ(DrawQuad::STREAM_VIDEO_CONTENT, copyQuad->material); + EXPECT_EQ(textureId, copyQuad->texture_id); + EXPECT_EQ(matrix, copyQuad->matrix); +} + +TEST(DrawQuadTest, copyTextureDrawQuad) +{ + gfx::Rect opaqueRect(3, 7, 10, 12); + unsigned resourceId = 82; + bool premultipliedAlpha = true; + gfx::PointF uvTopLeft(0.5f, 224.f); + gfx::PointF uvBottomRight(51.5f, 260.f); + const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; + bool flipped = true; + CREATE_SHARED_STATE(); + + CREATE_QUAD_7_NEW(TextureDrawQuad, opaqueRect, resourceId, premultipliedAlpha, uvTopLeft, uvBottomRight, vertex_opacity, flipped); + EXPECT_EQ(DrawQuad::TEXTURE_CONTENT, copyQuad->material); + EXPECT_RECT_EQ(opaqueRect, copyQuad->opaque_rect); + EXPECT_EQ(resourceId, copyQuad->resource_id); + EXPECT_EQ(premultipliedAlpha, copyQuad->premultiplied_alpha); + EXPECT_EQ(uvTopLeft, copyQuad->uv_top_left); + EXPECT_EQ(uvBottomRight, copyQuad->uv_bottom_right); + EXPECT_FLOAT_ARRAY_EQ(vertex_opacity, copyQuad->vertex_opacity, 4); + EXPECT_EQ(flipped, copyQuad->flipped); + + CREATE_QUAD_6_ALL(TextureDrawQuad, resourceId, premultipliedAlpha, uvTopLeft, uvBottomRight, vertex_opacity, flipped); + EXPECT_EQ(DrawQuad::TEXTURE_CONTENT, copyQuad->material); + EXPECT_EQ(resourceId, copyQuad->resource_id); + EXPECT_EQ(premultipliedAlpha, copyQuad->premultiplied_alpha); + EXPECT_EQ(uvTopLeft, copyQuad->uv_top_left); + EXPECT_EQ(uvBottomRight, copyQuad->uv_bottom_right); + EXPECT_FLOAT_ARRAY_EQ(vertex_opacity, copyQuad->vertex_opacity, 4); + EXPECT_EQ(flipped, copyQuad->flipped); +} + +TEST(DrawQuadTest, clipTextureDrawQuad) +{ + gfx::Rect opaqueRect(3, 7, 10, 12); + unsigned resourceId = 82; + bool premultipliedAlpha = true; + bool flipped = true; + CREATE_SHARED_STATE(); + // The original quad position is (30, 40) its size is 50*60. + sharedState->content_to_target_transform = gfx::Transform(1.f, 0.f, 0.f, 1.f, 10.f, 20.f); + // After transformation, the quad position is (40, 60) its size is 50*60. + sharedState->clip_rect = gfx::Rect(50, 70, 30, 20); + + // The original quad is 'ABCD', the clipped quad is 'abcd': + //40 50 90 + // B--:-------C 60 + // | b----c -|-70 + // | | | | + // | a----d -|-90 + // | | + // A----------D 120 + // UV and vertex opacity are stored per vertex on the parent rectangle 'ABCD'. + + // This is the UV value for vertex 'B'. + gfx::PointF uvTopLeft(0.1f, 0.2f); + // This is the UV value for vertex 'D'. + gfx::PointF uvBottomRight(0.9f, 0.8f); + // This the vertex opacity for the vertices 'ABCD'. + const float vertexOpacity[] = {0.3f, 0.4f, 0.7f, 0.8f}; + + { + CREATE_QUAD_7_NEW(TextureDrawQuad, opaqueRect, resourceId, premultipliedAlpha, uvTopLeft, uvBottomRight, vertexOpacity, flipped); + CREATE_QUAD_6_ALL(TextureDrawQuad, resourceId, premultipliedAlpha, uvTopLeft, uvBottomRight, vertexOpacity, flipped); + EXPECT_TRUE(quadAll->PerformClipping()); + + // This is the expected UV value for vertex 'b'. + // uv(b) = uv(B) + (Bb / BD) * (uv(D) - uv(B)) + // 0.3 = 0.2 + (10 / 60) * (0.8 - 0.2) + gfx::PointF uvTopLeftClipped(0.26f, 0.3f); + // This is the expected UV value for vertex 'd'. + // uv(d) = uv(B) + (Bd / BD) * (uv(D) - uv(B)) + gfx::PointF uvBottomRightClipped(0.74f, 0.5f); + // This the expected vertex opacity for the vertices 'abcd'. + // They are computed with a bilinear interpolation of the corner values. + const float vertexOpacityClipped[] = {0.43f, 0.45f, 0.65f, 0.67f}; + + EXPECT_EQ(uvTopLeftClipped, quadAll->uv_top_left); + EXPECT_EQ(uvBottomRightClipped, quadAll->uv_bottom_right); + EXPECT_FLOAT_ARRAY_EQ(vertexOpacityClipped, quadAll->vertex_opacity, 4); + } + + uvTopLeft = gfx::PointF(0.8f, 0.7f); + uvBottomRight = gfx::PointF(0.2f, 0.1f); + + { + CREATE_QUAD_7_NEW(TextureDrawQuad, opaqueRect, resourceId, premultipliedAlpha, uvTopLeft, uvBottomRight, vertexOpacity, flipped); + CREATE_QUAD_6_ALL(TextureDrawQuad, resourceId, premultipliedAlpha, uvTopLeft, uvBottomRight, vertexOpacity, flipped); + EXPECT_TRUE(quadAll->PerformClipping()); + + // This is the expected UV value for vertex 'b'. + gfx::PointF uvTopLeftClipped(0.68f, 0.6f); + // This is the expected UV value for vertex 'd'. + gfx::PointF uvBottomRightClipped(0.32f, 0.4f); + + EXPECT_EQ(uvTopLeftClipped, quadAll->uv_top_left); + EXPECT_EQ(uvBottomRightClipped, quadAll->uv_bottom_right); + } +} + +TEST(DrawQuadTest, copyTileDrawQuad) +{ + gfx::Rect opaqueRect(33, 44, 22, 33); + unsigned resourceId = 104; + gfx::RectF texCoordRect(31, 12, 54, 20); + gfx::Size textureSize(85, 32); + bool swizzleContents = true; + CREATE_SHARED_STATE(); + + CREATE_QUAD_5_NEW(TileDrawQuad, opaqueRect, resourceId, texCoordRect, textureSize, swizzleContents); + EXPECT_EQ(DrawQuad::TILED_CONTENT, copyQuad->material); + EXPECT_RECT_EQ(opaqueRect, copyQuad->opaque_rect); + EXPECT_EQ(resourceId, copyQuad->resource_id); + EXPECT_EQ(texCoordRect, copyQuad->tex_coord_rect); + EXPECT_EQ(textureSize, copyQuad->texture_size); + EXPECT_EQ(swizzleContents, copyQuad->swizzle_contents); + + CREATE_QUAD_4_ALL(TileDrawQuad, resourceId, texCoordRect, textureSize, swizzleContents); + EXPECT_EQ(DrawQuad::TILED_CONTENT, copyQuad->material); + EXPECT_EQ(resourceId, copyQuad->resource_id); + EXPECT_EQ(texCoordRect, copyQuad->tex_coord_rect); + EXPECT_EQ(textureSize, copyQuad->texture_size); + EXPECT_EQ(swizzleContents, copyQuad->swizzle_contents); +} + +TEST(DrawQuadTest, copyYUVVideoDrawQuad) +{ + gfx::Rect opaqueRect(3, 7, 10, 12); + gfx::SizeF texScale(0.75, 0.5); + VideoLayerImpl::FramePlane yPlane; + yPlane.resource_id = 45; + yPlane.size = gfx::Size(34, 23); + yPlane.format = 8; + VideoLayerImpl::FramePlane uPlane; + uPlane.resource_id = 532; + uPlane.size = gfx::Size(134, 16); + uPlane.format = 2; + VideoLayerImpl::FramePlane vPlane; + vPlane.resource_id = 4; + vPlane.size = gfx::Size(456, 486); + vPlane.format = 46; + CREATE_SHARED_STATE(); + + CREATE_QUAD_5_NEW(YUVVideoDrawQuad, opaqueRect, texScale, yPlane, uPlane, vPlane); + EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT, copyQuad->material); + EXPECT_RECT_EQ(opaqueRect, copyQuad->opaque_rect); + EXPECT_EQ(texScale, copyQuad->tex_scale); + EXPECT_EQ(yPlane.resource_id, copyQuad->y_plane.resource_id); + EXPECT_EQ(yPlane.size, copyQuad->y_plane.size); + EXPECT_EQ(yPlane.format, copyQuad->y_plane.format); + EXPECT_EQ(uPlane.resource_id, copyQuad->u_plane.resource_id); + EXPECT_EQ(uPlane.size, copyQuad->u_plane.size); + EXPECT_EQ(uPlane.format, copyQuad->u_plane.format); + EXPECT_EQ(vPlane.resource_id, copyQuad->v_plane.resource_id); + EXPECT_EQ(vPlane.size, copyQuad->v_plane.size); + EXPECT_EQ(vPlane.format, copyQuad->v_plane.format); + + CREATE_QUAD_4_ALL(YUVVideoDrawQuad, texScale, yPlane, uPlane, vPlane); + EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT, copyQuad->material); + EXPECT_EQ(texScale, copyQuad->tex_scale); + EXPECT_EQ(yPlane.resource_id, copyQuad->y_plane.resource_id); + EXPECT_EQ(yPlane.size, copyQuad->y_plane.size); + EXPECT_EQ(yPlane.format, copyQuad->y_plane.format); + EXPECT_EQ(uPlane.resource_id, copyQuad->u_plane.resource_id); + EXPECT_EQ(uPlane.size, copyQuad->u_plane.size); + EXPECT_EQ(uPlane.format, copyQuad->u_plane.format); + EXPECT_EQ(vPlane.resource_id, copyQuad->v_plane.resource_id); + EXPECT_EQ(vPlane.size, copyQuad->v_plane.size); + EXPECT_EQ(vPlane.format, copyQuad->v_plane.format); +} + +class DrawQuadIteratorTest : public testing::Test { + protected: + ResourceProvider::ResourceId IncrementResourceId( + ResourceProvider::ResourceId id) { + ++num_resources_; + return id + 1; + } + + int IterateAndCount(DrawQuad* quad) { + num_resources_ = 0; + quad->IterateResources(base::Bind( + &DrawQuadIteratorTest::IncrementResourceId, + base::Unretained(this))); + return num_resources_; + } + + private: + int num_resources_; +}; + +TEST_F(DrawQuadIteratorTest, CheckerboardDrawQuad) { + SkColor color = 0xfabb0011; + + CREATE_SHARED_STATE(); + CREATE_QUAD_1_NEW(CheckerboardDrawQuad, color); + EXPECT_EQ(0, IterateAndCount(quadNew.get())); +} + +TEST_F(DrawQuadIteratorTest, DebugBorderDrawQuad) { + SkColor color = 0xfabb0011; + int width = 99; + + CREATE_SHARED_STATE(); + CREATE_QUAD_2_NEW(DebugBorderDrawQuad, color, width); + EXPECT_EQ(0, IterateAndCount(quadNew.get())); +} + +TEST_F(DrawQuadIteratorTest, IOSurfaceDrawQuad) { + gfx::Rect opaqueRect(3, 7, 10, 12); + gfx::Size size(58, 95); + unsigned textureId = 72; + IOSurfaceDrawQuad::Orientation orientation = IOSurfaceDrawQuad::UNFLIPPED; + + CREATE_SHARED_STATE(); + CREATE_QUAD_4_NEW(IOSurfaceDrawQuad, opaqueRect, size, textureId, orientation); + EXPECT_EQ(0, IterateAndCount(quadNew.get())); +} + +TEST_F(DrawQuadIteratorTest, RenderPassDrawQuad) { + RenderPass::Id renderPassId(22, 64); + bool isReplica = true; + ResourceProvider::ResourceId maskResourceId = 78; + gfx::Rect contentsChangedSinceLastFrame(42, 11, 74, 24); + gfx::RectF maskUVRect(-45, -21, 33, 19); + WebKit::WebFilterOperations filters; + filters.append(WebKit::WebFilterOperation::createBlurFilter(1.f)); + WebKit::WebFilterOperations background_filters; + background_filters.append( + WebKit::WebFilterOperation::createGrayscaleFilter(1.f)); + skia::RefPtr<SkImageFilter> filter = skia::AdoptRef( + new SkBlurImageFilter(SK_Scalar1, SK_Scalar1)); + + RenderPass::Id copiedRenderPassId(235, 11); + + CREATE_SHARED_STATE(); + CREATE_QUAD_8_NEW_1(RenderPassDrawQuad, renderPassId, isReplica, maskResourceId, contentsChangedSinceLastFrame, maskUVRect, filters, filter, background_filters, copiedRenderPassId); + EXPECT_EQ(maskResourceId, quadNew->mask_resource_id); + EXPECT_EQ(1, IterateAndCount(quadNew.get())); + EXPECT_EQ(maskResourceId + 1, quadNew->mask_resource_id); +} + +TEST_F(DrawQuadIteratorTest, SolidColorDrawQuad) { + SkColor color = 0x49494949; + + CREATE_SHARED_STATE(); + CREATE_QUAD_1_NEW(SolidColorDrawQuad, color); + EXPECT_EQ(0, IterateAndCount(quadNew.get())); +} + +TEST_F(DrawQuadIteratorTest, StreamVideoDrawQuad) { + gfx::Rect opaqueRect(3, 7, 10, 12); + unsigned textureId = 64; + gfx::Transform matrix = gfx::Transform(0.5, 0.25, 1, 0.75, 0, 1); + + CREATE_SHARED_STATE(); + CREATE_QUAD_3_NEW(StreamVideoDrawQuad, opaqueRect, textureId, matrix); + EXPECT_EQ(0, IterateAndCount(quadNew.get())); +} + +TEST_F(DrawQuadIteratorTest, TextureDrawQuad) { + gfx::Rect opaqueRect(3, 7, 10, 12); + unsigned resourceId = 82; + bool premultipliedAlpha = true; + gfx::PointF uvTopLeft(0.5f, 224.f); + gfx::PointF uvBottomRight(51.5f, 260.f); + const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; + bool flipped = true; + + CREATE_SHARED_STATE(); + CREATE_QUAD_7_NEW(TextureDrawQuad, opaqueRect, resourceId, premultipliedAlpha, uvTopLeft, uvBottomRight, vertex_opacity, flipped); + EXPECT_EQ(resourceId, quadNew->resource_id); + EXPECT_EQ(1, IterateAndCount(quadNew.get())); + EXPECT_EQ(resourceId + 1, quadNew->resource_id); +} + +TEST_F(DrawQuadIteratorTest, TileDrawQuad) { + gfx::Rect opaqueRect(33, 44, 22, 33); + unsigned resourceId = 104; + gfx::RectF texCoordRect(31, 12, 54, 20); + gfx::Size textureSize(85, 32); + bool swizzleContents = true; + + CREATE_SHARED_STATE(); + CREATE_QUAD_5_NEW(TileDrawQuad, opaqueRect, resourceId, texCoordRect, textureSize, swizzleContents); + EXPECT_EQ(resourceId, quadNew->resource_id); + EXPECT_EQ(1, IterateAndCount(quadNew.get())); + EXPECT_EQ(resourceId + 1, quadNew->resource_id); +} + +TEST_F(DrawQuadIteratorTest, YUVVideoDrawQuad) { + gfx::Rect opaqueRect(3, 7, 10, 12); + gfx::SizeF texScale(0.75, 0.5); + VideoLayerImpl::FramePlane yPlane; + yPlane.resource_id = 45; + yPlane.size = gfx::Size(34, 23); + yPlane.format = 8; + VideoLayerImpl::FramePlane uPlane; + uPlane.resource_id = 532; + uPlane.size = gfx::Size(134, 16); + uPlane.format = 2; + VideoLayerImpl::FramePlane vPlane; + vPlane.resource_id = 4; + vPlane.size = gfx::Size(456, 486); + vPlane.format = 46; + + CREATE_SHARED_STATE(); + CREATE_QUAD_5_NEW(YUVVideoDrawQuad, opaqueRect, texScale, yPlane, uPlane, vPlane); + EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT, copyQuad->material); + EXPECT_EQ(yPlane.resource_id, quadNew->y_plane.resource_id); + EXPECT_EQ(uPlane.resource_id, quadNew->u_plane.resource_id); + EXPECT_EQ(vPlane.resource_id, quadNew->v_plane.resource_id); + EXPECT_EQ(3, IterateAndCount(quadNew.get())); + EXPECT_EQ(yPlane.resource_id + 1, quadNew->y_plane.resource_id); + EXPECT_EQ(uPlane.resource_id + 1, quadNew->u_plane.resource_id); + EXPECT_EQ(vPlane.resource_id + 1, quadNew->v_plane.resource_id); +} + + +} // namespace +} // namespace cc diff --git a/cc/quads/io_surface_draw_quad.cc b/cc/quads/io_surface_draw_quad.cc new file mode 100644 index 0000000..ac107c1 --- /dev/null +++ b/cc/quads/io_surface_draw_quad.cc @@ -0,0 +1,62 @@ +// 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/io_surface_draw_quad.h" + +#include "base/logging.h" + +namespace cc { + +IOSurfaceDrawQuad::IOSurfaceDrawQuad() + : io_surface_texture_id(0), + orientation(FLIPPED) { +} + +scoped_ptr<IOSurfaceDrawQuad> IOSurfaceDrawQuad::Create() { + return make_scoped_ptr(new IOSurfaceDrawQuad); +} + +void IOSurfaceDrawQuad::SetNew(const SharedQuadState* shared_quad_state, + gfx::Rect rect, + gfx::Rect opaque_rect, + gfx::Size io_surface_size, + unsigned io_surface_texture_id, + Orientation orientation) { + gfx::Rect visible_rect = rect; + bool needs_blending = false; + DrawQuad::SetAll(shared_quad_state, DrawQuad::IO_SURFACE_CONTENT, rect, + opaque_rect, visible_rect, needs_blending); + this->io_surface_size = io_surface_size; + this->io_surface_texture_id = io_surface_texture_id; + this->orientation = orientation; +} + +void IOSurfaceDrawQuad::SetAll(const SharedQuadState* shared_quad_state, + gfx::Rect rect, + gfx::Rect opaque_rect, + gfx::Rect visible_rect, + bool needs_blending, + gfx::Size io_surface_size, + unsigned io_surface_texture_id, + Orientation orientation) { + DrawQuad::SetAll(shared_quad_state, DrawQuad::IO_SURFACE_CONTENT, rect, + opaque_rect, visible_rect, needs_blending); + this->io_surface_size = io_surface_size; + this->io_surface_texture_id = io_surface_texture_id; + this->orientation = orientation; +} + +void IOSurfaceDrawQuad::IterateResources( + const ResourceIteratorCallback& callback) { + // TODO(danakj): Convert to TextureDrawQuad? + NOTIMPLEMENTED(); +} + +const IOSurfaceDrawQuad* IOSurfaceDrawQuad::MaterialCast( + const DrawQuad* quad) { + DCHECK(quad->material == DrawQuad::IO_SURFACE_CONTENT); + return static_cast<const IOSurfaceDrawQuad*>(quad); +} + +} // namespace cc diff --git a/cc/quads/io_surface_draw_quad.h b/cc/quads/io_surface_draw_quad.h new file mode 100644 index 0000000..d0559e2 --- /dev/null +++ b/cc/quads/io_surface_draw_quad.h @@ -0,0 +1,54 @@ +// 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. + +#ifndef CC_QUADS_IO_SURFACE_DRAW_QUAD_H_ +#define CC_QUADS_IO_SURFACE_DRAW_QUAD_H_ + +#include "base/memory/scoped_ptr.h" +#include "cc/base/cc_export.h" +#include "cc/quads/draw_quad.h" +#include "ui/gfx/size.h" + +namespace cc { + +class CC_EXPORT IOSurfaceDrawQuad : public DrawQuad { + public: + enum Orientation { + FLIPPED, + UNFLIPPED + }; + + static scoped_ptr<IOSurfaceDrawQuad> Create(); + + void SetNew(const SharedQuadState* shared_quad_state, + gfx::Rect rect, + gfx::Rect opaque_rect, + gfx::Size io_surface_size, + unsigned io_surface_texture_id, + Orientation orientation); + + void SetAll(const SharedQuadState* shared_quad_state, + gfx::Rect rect, + gfx::Rect opaque_rect, + gfx::Rect visible_rect, + bool needs_blending, + gfx::Size io_surface_size, + unsigned io_surface_texture_id, + Orientation orientation); + + gfx::Size io_surface_size; + unsigned io_surface_texture_id; + Orientation orientation; + + virtual void IterateResources(const ResourceIteratorCallback& callback) + OVERRIDE; + + static const IOSurfaceDrawQuad* MaterialCast(const DrawQuad*); + private: + IOSurfaceDrawQuad(); +}; + +} + +#endif // CC_QUADS_IO_SURFACE_DRAW_QUAD_H_ diff --git a/cc/quads/render_pass.cc b/cc/quads/render_pass.cc new file mode 100644 index 0000000..ef681df --- /dev/null +++ b/cc/quads/render_pass.cc @@ -0,0 +1,75 @@ +// Copyright 2011 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/render_pass.h" + +#include "cc/quads/draw_quad.h" +#include "cc/quads/shared_quad_state.h" + +namespace cc { + +scoped_ptr<RenderPass> RenderPass::Create() { + return make_scoped_ptr(new RenderPass); +} + +RenderPass::RenderPass() + : id(Id(-1, -1)), + has_transparent_background(true), + has_occlusion_from_outside_target_surface(false) { +} + +RenderPass::~RenderPass() { +} + +scoped_ptr<RenderPass> RenderPass::Copy(Id new_id) const { + DCHECK(new_id != id); + + scoped_ptr<RenderPass> copy_pass(Create()); + copy_pass->SetAll(new_id, + output_rect, + damage_rect, + transform_to_root_target, + has_transparent_background, + has_occlusion_from_outside_target_surface); + return copy_pass.Pass(); +} + +void RenderPass::SetNew(Id id, + gfx::Rect output_rect, + gfx::RectF damage_rect, + const gfx::Transform& transform_to_root_target) { + DCHECK_GT(id.layer_id, 0); + DCHECK_GE(id.index, 0); + + this->id = id; + this->output_rect = output_rect; + this->damage_rect = damage_rect; + this->transform_to_root_target = transform_to_root_target; + + DCHECK(quad_list.empty()); + DCHECK(shared_quad_state_list.empty()); +} + +void RenderPass::SetAll(Id id, + gfx::Rect output_rect, + gfx::RectF damage_rect, + const gfx::Transform& transform_to_root_target, + bool has_transparent_background, + bool has_occlusion_from_outside_target_surface) { + DCHECK_GT(id.layer_id, 0); + DCHECK_GE(id.index, 0); + + this->id = id; + this->output_rect = output_rect; + this->damage_rect = damage_rect; + this->transform_to_root_target = transform_to_root_target; + this->has_transparent_background = has_transparent_background; + this->has_occlusion_from_outside_target_surface = + has_occlusion_from_outside_target_surface; + + DCHECK(quad_list.empty()); + DCHECK(shared_quad_state_list.empty()); +} + +} // namespace cc diff --git a/cc/quads/render_pass.h b/cc/quads/render_pass.h new file mode 100644 index 0000000..6259716 --- /dev/null +++ b/cc/quads/render_pass.h @@ -0,0 +1,135 @@ +// Copyright 2011 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. + +#ifndef CC_QUADS_RENDER_PASS_H_ +#define CC_QUADS_RENDER_PASS_H_ + +#include <vector> + +#include "base/basictypes.h" +#include "cc/base/cc_export.h" +#include "cc/base/hash_pair.h" +#include "cc/base/scoped_ptr_hash_map.h" +#include "cc/base/scoped_ptr_vector.h" +#include "skia/ext/refptr.h" +#include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperations.h" +#include "third_party/skia/include/core/SkColor.h" +#include "third_party/skia/include/core/SkImageFilter.h" +#include "ui/gfx/rect.h" +#include "ui/gfx/rect_f.h" +#include "ui/gfx/transform.h" + +namespace cc { + +class DrawQuad; +class SharedQuadState; + +// A list of DrawQuad objects, sorted internally in front-to-back order. +class QuadList : public ScopedPtrVector<DrawQuad> { + public: + typedef reverse_iterator backToFrontIterator; + typedef const_reverse_iterator constBackToFrontIterator; + + inline backToFrontIterator backToFrontBegin() { return rbegin(); } + inline backToFrontIterator backToFrontEnd() { return rend(); } + inline constBackToFrontIterator backToFrontBegin() const { return rbegin(); } + inline constBackToFrontIterator backToFrontEnd() const { return rend(); } +}; + +typedef ScopedPtrVector<SharedQuadState> SharedQuadStateList; + +class CC_EXPORT RenderPass { + public: + struct Id { + int layer_id; + int index; + + Id(int layer_id, int index) : layer_id(layer_id), index(index) {} + + bool operator==(const Id& other) const { + return layer_id == other.layer_id && index == other.index; + } + bool operator!=(const Id& other) const { + return !(*this == other); + } + bool operator<(const Id& other) const { + return layer_id < other.layer_id || + (layer_id == other.layer_id && index < other.index); + } + }; + + ~RenderPass(); + + static scoped_ptr<RenderPass> Create(); + + // A shallow copy of the render pass, which does not include its quads. + scoped_ptr<RenderPass> Copy(Id newId) const; + + void SetNew(Id id, + gfx::Rect output_rect, + gfx::RectF damage_rect, + const gfx::Transform& transform_to_root_target); + + void SetAll(Id id, + gfx::Rect output_rect, + gfx::RectF damage_rect, + const gfx::Transform& transform_to_root_target, + bool has_transparent_background, + bool has_occlusion_from_outside_target_surface); + + // Uniquely identifies the render pass in the compositor's current frame. + Id id; + + // These are in the space of the render pass' physical pixels. + gfx::Rect output_rect; + gfx::RectF damage_rect; + + // Transforms from the origin of the |output_rect| to the origin of the root + // render pass' |output_rect|. + gfx::Transform transform_to_root_target; + + // If false, the pixels in the render pass' texture are all opaque. + bool has_transparent_background; + + // If true, then there may be pixels in the render pass' texture that are not + // complete, since they are occluded. + bool has_occlusion_from_outside_target_surface; + + QuadList quad_list; + SharedQuadStateList shared_quad_state_list; + + protected: + RenderPass(); + + DISALLOW_COPY_AND_ASSIGN(RenderPass); +}; + +} // namespace cc + +namespace BASE_HASH_NAMESPACE { +#if defined(COMPILER_MSVC) +template<> +inline size_t hash_value<cc::RenderPass::Id>(const cc::RenderPass::Id& key) { + return hash_value<std::pair<int, int> >( + std::pair<int, int>(key.layer_id, key.index)); +} +#elif defined(COMPILER_GCC) +template<> +struct hash<cc::RenderPass::Id> { + size_t operator()(cc::RenderPass::Id key) const { + return hash<std::pair<int, int> >()( + std::pair<int, int>(key.layer_id, key.index)); + } +}; +#else +#error define a hash function for your compiler +#endif // COMPILER +} + +namespace cc { +typedef ScopedPtrVector<RenderPass> RenderPassList; +typedef base::hash_map<RenderPass::Id, RenderPass*> RenderPassIdHashMap; +} // namespace cc + +#endif // CC_QUADS_RENDER_PASS_H_ diff --git a/cc/quads/render_pass_draw_quad.cc b/cc/quads/render_pass_draw_quad.cc new file mode 100644 index 0000000..8c0bbe3 --- /dev/null +++ b/cc/quads/render_pass_draw_quad.cc @@ -0,0 +1,95 @@ +// Copyright 2011 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/render_pass_draw_quad.h" + +namespace cc { + +RenderPassDrawQuad::RenderPassDrawQuad() + : render_pass_id(RenderPass::Id(-1, -1)), + is_replica(false), + mask_resource_id(-1) { +} + +RenderPassDrawQuad::~RenderPassDrawQuad() { +} + +scoped_ptr<RenderPassDrawQuad> RenderPassDrawQuad::Create() { + return make_scoped_ptr(new RenderPassDrawQuad); +} + +scoped_ptr<RenderPassDrawQuad> RenderPassDrawQuad::Copy( + const SharedQuadState* copied_shared_quad_state, + RenderPass::Id copied_render_pass_id) const { + scoped_ptr<RenderPassDrawQuad> copy_quad( + new RenderPassDrawQuad(*MaterialCast(this))); + copy_quad->shared_quad_state = copied_shared_quad_state; + copy_quad->render_pass_id = copied_render_pass_id; + return copy_quad.Pass(); +} + +void RenderPassDrawQuad::SetNew( + const SharedQuadState* shared_quad_state, + gfx::Rect rect, + RenderPass::Id render_pass_id, + bool is_replica, + ResourceProvider::ResourceId mask_resource_id, + gfx::Rect contents_changed_since_last_frame, + gfx::RectF mask_uv_rect, + const WebKit::WebFilterOperations& filters, + skia::RefPtr<SkImageFilter> filter, + const WebKit::WebFilterOperations& background_filters) { + DCHECK(render_pass_id.layer_id > 0); + DCHECK(render_pass_id.index >= 0); + + gfx::Rect opaque_rect; + gfx::Rect visible_rect = rect; + bool needs_blending = false; + SetAll(shared_quad_state, rect, opaque_rect, visible_rect, needs_blending, + render_pass_id, is_replica, mask_resource_id, + contents_changed_since_last_frame, mask_uv_rect, filters, filter, + background_filters); +} + +void RenderPassDrawQuad::SetAll( + const SharedQuadState* shared_quad_state, + gfx::Rect rect, + gfx::Rect opaque_rect, + gfx::Rect visible_rect, + bool needs_blending, + RenderPass::Id render_pass_id, + bool is_replica, + ResourceProvider::ResourceId mask_resource_id, + gfx::Rect contents_changed_since_last_frame, + gfx::RectF mask_uv_rect, + const WebKit::WebFilterOperations& filters, + skia::RefPtr<SkImageFilter> filter, + const WebKit::WebFilterOperations& background_filters) { + DCHECK(render_pass_id.layer_id > 0); + DCHECK(render_pass_id.index >= 0); + + DrawQuad::SetAll(shared_quad_state, DrawQuad::RENDER_PASS, rect, opaque_rect, + visible_rect, needs_blending); + this->render_pass_id = render_pass_id; + this->is_replica = is_replica; + this->mask_resource_id = mask_resource_id; + this->contents_changed_since_last_frame = contents_changed_since_last_frame; + this->mask_uv_rect = mask_uv_rect; + this->filters = filters; + this->filter = filter; + this->background_filters = background_filters; +} + +void RenderPassDrawQuad::IterateResources( + const ResourceIteratorCallback& callback) { + mask_resource_id = callback.Run(mask_resource_id); +} + +const RenderPassDrawQuad* RenderPassDrawQuad::MaterialCast( + const DrawQuad* quad) { + DCHECK(quad->material == DrawQuad::RENDER_PASS); + return static_cast<const RenderPassDrawQuad*>(quad); +} + +} // namespace cc diff --git a/cc/quads/render_pass_draw_quad.h b/cc/quads/render_pass_draw_quad.h new file mode 100644 index 0000000..8c330d7 --- /dev/null +++ b/cc/quads/render_pass_draw_quad.h @@ -0,0 +1,79 @@ +// Copyright 2011 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. + +#ifndef CC_QUADS_RENDER_PASS_DRAW_QUAD_H_ +#define CC_QUADS_RENDER_PASS_DRAW_QUAD_H_ + +#include "base/basictypes.h" +#include "base/memory/scoped_ptr.h" +#include "cc/base/cc_export.h" +#include "cc/quads/draw_quad.h" +#include "cc/quads/render_pass.h" +#include "cc/resource_provider.h" +#include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperations.h" + +namespace cc { + +class CC_EXPORT RenderPassDrawQuad : public DrawQuad { + public: + static scoped_ptr<RenderPassDrawQuad> Create(); + virtual ~RenderPassDrawQuad(); + + void SetNew(const SharedQuadState* shared_quad_state, + gfx::Rect rect, + RenderPass::Id render_pass_id, + bool is_replica, + ResourceProvider::ResourceId mask_resource_id, + gfx::Rect contents_changed_since_last_frame, + gfx::RectF mask_uv_rect, + const WebKit::WebFilterOperations& filters, + skia::RefPtr<SkImageFilter> filter, + const WebKit::WebFilterOperations& background_filters); + + void SetAll(const SharedQuadState* shared_quad_state, + gfx::Rect rect, + gfx::Rect opaque_rect, + gfx::Rect visible_rect, + bool needs_blending, + RenderPass::Id render_pass_id, + bool is_replica, + ResourceProvider::ResourceId mask_resource_id, + gfx::Rect contents_changed_since_last_frame, + gfx::RectF mask_uv_rect, + const WebKit::WebFilterOperations& filters, + skia::RefPtr<SkImageFilter> filter, + const WebKit::WebFilterOperations& background_filters); + + scoped_ptr<RenderPassDrawQuad> Copy( + const SharedQuadState* copied_shared_quad_state, + RenderPass::Id copied_render_pass_id) const; + + RenderPass::Id render_pass_id; + bool is_replica; + ResourceProvider::ResourceId mask_resource_id; + gfx::Rect contents_changed_since_last_frame; + gfx::RectF mask_uv_rect; + + // Deprecated post-processing filters, applied to the pixels in the render + // pass' texture. + WebKit::WebFilterOperations filters; + // Post-processing filter applied to the pixels in the render pass' texture. + skia::RefPtr<SkImageFilter> filter; + + // Post-processing filters, applied to the pixels showing through the + // background of the render pass, from behind it. + WebKit::WebFilterOperations background_filters; + + virtual void IterateResources(const ResourceIteratorCallback& callback) + OVERRIDE; + + static const RenderPassDrawQuad* MaterialCast(const DrawQuad*); + +private: + RenderPassDrawQuad(); +}; + +} + +#endif // CC_QUADS_RENDER_PASS_DRAW_QUAD_H_ diff --git a/cc/quads/render_pass_unittest.cc b/cc/quads/render_pass_unittest.cc new file mode 100644 index 0000000..743ad50 --- /dev/null +++ b/cc/quads/render_pass_unittest.cc @@ -0,0 +1,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/quads/render_pass.h" + +#include "cc/base/math_util.h" +#include "cc/quads/checkerboard_draw_quad.h" +#include "cc/test/geometry_test_utils.h" +#include "cc/test/render_pass_test_common.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperations.h" +#include "third_party/skia/include/effects/SkBlurImageFilter.h" +#include "ui/gfx/transform.h" + +using cc::TestRenderPass; + +namespace cc { +namespace { + +struct RenderPassSize { + // If you add a new field to this class, make sure to add it to the copy() tests. + RenderPass::Id m_id; + QuadList m_quadList; + SharedQuadStateList m_sharedQuadStateList; + gfx::Transform m_transformToRootTarget; + gfx::Rect m_outputRect; + gfx::RectF m_damageRect; + bool m_hasTransparentBackground; + bool m_hasOcclusionFromOutsideTargetSurface; +}; + +TEST(RenderPassTest, copyShouldBeIdenticalExceptIdAndQuads) +{ + RenderPass::Id id(3, 2); + gfx::Rect outputRect(45, 22, 120, 13); + gfx::Transform transformToRoot = gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0); + gfx::Rect damageRect(56, 123, 19, 43); + bool hasTransparentBackground = true; + bool hasOcclusionFromOutsideTargetSurface = true; + + scoped_ptr<TestRenderPass> pass = TestRenderPass::Create(); + pass->SetAll(id, + outputRect, + damageRect, + transformToRoot, + hasTransparentBackground, + hasOcclusionFromOutsideTargetSurface); + + // Stick a quad in the pass, this should not get copied. + scoped_ptr<SharedQuadState> sharedState = SharedQuadState::Create(); + sharedState->SetAll(gfx::Transform(), gfx::Size(), gfx::Rect(), gfx::Rect(), false, 1); + pass->AppendSharedQuadState(sharedState.Pass()); + + scoped_ptr<CheckerboardDrawQuad> checkerboardQuad = CheckerboardDrawQuad::Create(); + checkerboardQuad->SetNew(pass->shared_quad_state_list.back(), gfx::Rect(), SkColor()); + pass->quad_list.push_back(checkerboardQuad.PassAs<DrawQuad>()); + + RenderPass::Id newId(63, 4); + + scoped_ptr<RenderPass> copy = pass->Copy(newId); + EXPECT_EQ(newId, copy->id); + EXPECT_RECT_EQ(pass->output_rect, copy->output_rect); + EXPECT_EQ(pass->transform_to_root_target, copy->transform_to_root_target); + EXPECT_RECT_EQ(pass->damage_rect, copy->damage_rect); + EXPECT_EQ(pass->has_transparent_background, copy->has_transparent_background); + EXPECT_EQ(pass->has_occlusion_from_outside_target_surface, copy->has_occlusion_from_outside_target_surface); + EXPECT_EQ(0u, copy->quad_list.size()); + + EXPECT_EQ(sizeof(RenderPassSize), sizeof(RenderPass)); +} + +} // namespace +} // namespace cc diff --git a/cc/quads/shared_quad_state.cc b/cc/quads/shared_quad_state.cc new file mode 100644 index 0000000..2b9470d --- /dev/null +++ b/cc/quads/shared_quad_state.cc @@ -0,0 +1,36 @@ +// 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/shared_quad_state.h" + +namespace cc { + +SharedQuadState::SharedQuadState() : is_clipped(false), opacity(0.f) {} + +SharedQuadState::~SharedQuadState() {} + +scoped_ptr<SharedQuadState> SharedQuadState::Create() { + return make_scoped_ptr(new SharedQuadState); +} + +scoped_ptr<SharedQuadState> SharedQuadState::Copy() const { + return make_scoped_ptr(new SharedQuadState(*this)); +} + +void SharedQuadState::SetAll( + const gfx::Transform& content_to_target_transform, + const gfx::Size content_bounds, + const gfx::Rect& visible_content_rect, + const gfx::Rect& clip_rect, + bool is_clipped, + float opacity) { + this->content_to_target_transform = content_to_target_transform; + this->content_bounds = content_bounds; + this->visible_content_rect = visible_content_rect; + this->clip_rect = clip_rect; + this->is_clipped = is_clipped; + this->opacity = opacity; +} + +} // namespace cc diff --git a/cc/quads/shared_quad_state.h b/cc/quads/shared_quad_state.h new file mode 100644 index 0000000..c7c1bc0 --- /dev/null +++ b/cc/quads/shared_quad_state.h @@ -0,0 +1,44 @@ +// 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. + +#ifndef CC_QUADS_SHARED_QUAD_STATE_H_ +#define CC_QUADS_SHARED_QUAD_STATE_H_ + +#include "base/memory/scoped_ptr.h" +#include "cc/base/cc_export.h" +#include "ui/gfx/rect.h" +#include "ui/gfx/transform.h" + +namespace cc { + +class CC_EXPORT SharedQuadState { + public: + static scoped_ptr<SharedQuadState> Create(); + ~SharedQuadState(); + + scoped_ptr<SharedQuadState> Copy() const; + + void SetAll(const gfx::Transform& content_to_target_transform, + const gfx::Size content_bounds, + const gfx::Rect& visible_content_rect, + const gfx::Rect& clip_rect, + bool is_clipped, + float opacity); + + // Transforms from quad's original content space to its target content space. + gfx::Transform content_to_target_transform; + // This rect lives in the content space for the quad's originating layer. + gfx::Size content_bounds; + gfx::Rect visible_content_rect; + gfx::Rect clip_rect; + bool is_clipped; + float opacity; + + private: + SharedQuadState(); +}; + +} + +#endif // CC_QUADS_SHARED_QUAD_STATE_H_ diff --git a/cc/quads/solid_color_draw_quad.cc b/cc/quads/solid_color_draw_quad.cc new file mode 100644 index 0000000..4d004cee --- /dev/null +++ b/cc/quads/solid_color_draw_quad.cc @@ -0,0 +1,48 @@ +// 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/solid_color_draw_quad.h" + +#include "base/logging.h" + +namespace cc { + +SolidColorDrawQuad::SolidColorDrawQuad() : color(0) {} + +scoped_ptr<SolidColorDrawQuad> SolidColorDrawQuad::Create() { + return make_scoped_ptr(new SolidColorDrawQuad); +} + +void SolidColorDrawQuad::SetNew(const SharedQuadState* shared_quad_state, + gfx::Rect rect, + SkColor color) { + gfx::Rect opaque_rect = SkColorGetA(color) == 255 ? rect : gfx::Rect(); + gfx::Rect visible_rect = rect; + bool needs_blending = false; + DrawQuad::SetAll(shared_quad_state, DrawQuad::SOLID_COLOR, rect, opaque_rect, + visible_rect, needs_blending); + this->color = color; +} + +void SolidColorDrawQuad::SetAll(const SharedQuadState* shared_quad_state, + gfx::Rect rect, + gfx::Rect opaque_rect, + gfx::Rect visible_rect, + bool needs_blending, + SkColor color) { + DrawQuad::SetAll(shared_quad_state, DrawQuad::SOLID_COLOR, rect, opaque_rect, + visible_rect, needs_blending); + this->color = color; +} + +void SolidColorDrawQuad::IterateResources( + const ResourceIteratorCallback& callback) {} + +const SolidColorDrawQuad* SolidColorDrawQuad::MaterialCast( + const DrawQuad* quad) { + DCHECK(quad->material == DrawQuad::SOLID_COLOR); + return static_cast<const SolidColorDrawQuad*>(quad); +} + +} // namespacec cc diff --git a/cc/quads/solid_color_draw_quad.h b/cc/quads/solid_color_draw_quad.h new file mode 100644 index 0000000..a300063 --- /dev/null +++ b/cc/quads/solid_color_draw_quad.h @@ -0,0 +1,42 @@ +// 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. + +#ifndef CC_QUADS_SOLID_COLOR_DRAW_QUAD_H_ +#define CC_QUADS_SOLID_COLOR_DRAW_QUAD_H_ + +#include "base/memory/scoped_ptr.h" +#include "cc/base/cc_export.h" +#include "cc/quads/draw_quad.h" +#include "third_party/skia/include/core/SkColor.h" + +namespace cc { + +class CC_EXPORT SolidColorDrawQuad : public DrawQuad { + public: + static scoped_ptr<SolidColorDrawQuad> Create(); + + void SetNew(const SharedQuadState* shared_quad_state, + gfx::Rect rect, + SkColor color); + + void SetAll(const SharedQuadState* shared_quad_state, + gfx::Rect rect, + gfx::Rect opaque_rect, + gfx::Rect visible_rect, + bool needs_blending, + SkColor color); + + SkColor color; + + virtual void IterateResources(const ResourceIteratorCallback& callback) + OVERRIDE; + + static const SolidColorDrawQuad* MaterialCast(const DrawQuad*); + private: + SolidColorDrawQuad(); +}; + +} + +#endif // CC_QUADS_SOLID_COLOR_DRAW_QUAD_H_ diff --git a/cc/quads/stream_video_draw_quad.cc b/cc/quads/stream_video_draw_quad.cc new file mode 100644 index 0000000..89e4003 --- /dev/null +++ b/cc/quads/stream_video_draw_quad.cc @@ -0,0 +1,55 @@ +// 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/stream_video_draw_quad.h" + +#include "base/logging.h" + +namespace cc { + +StreamVideoDrawQuad::StreamVideoDrawQuad() : texture_id(0) {} + +scoped_ptr<StreamVideoDrawQuad> StreamVideoDrawQuad::Create() { + return make_scoped_ptr(new StreamVideoDrawQuad); +} + +void StreamVideoDrawQuad::SetNew(const SharedQuadState* shared_quad_state, + gfx::Rect rect, + gfx::Rect opaque_rect, + unsigned texture_id, + const gfx::Transform& matrix) { + gfx::Rect visible_rect = rect; + bool needs_blending = false; + DrawQuad::SetAll(shared_quad_state, DrawQuad::STREAM_VIDEO_CONTENT, rect, + opaque_rect, visible_rect, needs_blending); + this->texture_id = texture_id; + this->matrix = matrix; +} + +void StreamVideoDrawQuad::SetAll(const SharedQuadState* shared_quad_state, + gfx::Rect rect, + gfx::Rect opaque_rect, + gfx::Rect visible_rect, + bool needs_blending, + unsigned texture_id, + const gfx::Transform& matrix) { + DrawQuad::SetAll(shared_quad_state, DrawQuad::STREAM_VIDEO_CONTENT, rect, + opaque_rect, visible_rect, needs_blending); + this->texture_id = texture_id; + this->matrix = matrix; +} + +void StreamVideoDrawQuad::IterateResources( + const ResourceIteratorCallback& callback) { + // TODO(danakj): Convert to TextureDrawQuad? + NOTIMPLEMENTED(); +} + +const StreamVideoDrawQuad* StreamVideoDrawQuad::MaterialCast( + const DrawQuad* quad) { + DCHECK(quad->material == DrawQuad::STREAM_VIDEO_CONTENT); + return static_cast<const StreamVideoDrawQuad*>(quad); +} + +} // namespace cc diff --git a/cc/quads/stream_video_draw_quad.h b/cc/quads/stream_video_draw_quad.h new file mode 100644 index 0000000..bfbcdf4 --- /dev/null +++ b/cc/quads/stream_video_draw_quad.h @@ -0,0 +1,46 @@ +// 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. + +#ifndef CC_QUADS_STREAM_VIDEO_DRAW_QUAD_H_ +#define CC_QUADS_STREAM_VIDEO_DRAW_QUAD_H_ + +#include "base/memory/scoped_ptr.h" +#include "cc/base/cc_export.h" +#include "cc/quads/draw_quad.h" +#include "ui/gfx/transform.h" + +namespace cc { + +class CC_EXPORT StreamVideoDrawQuad : public DrawQuad { + public: + static scoped_ptr<StreamVideoDrawQuad> Create(); + + void SetNew(const SharedQuadState* shared_quad_state, + gfx::Rect rect, + gfx::Rect opaque_rect, + unsigned texture_id, + const gfx::Transform& matrix); + + void SetAll(const SharedQuadState* shared_quad_state, + gfx::Rect rect, + gfx::Rect opaque_rect, + gfx::Rect visible_rect, + bool needs_blending, + unsigned texture_id, + const gfx::Transform& matrix); + + unsigned texture_id; + gfx::Transform matrix; + + virtual void IterateResources(const ResourceIteratorCallback& callback) + OVERRIDE; + + static const StreamVideoDrawQuad* MaterialCast(const DrawQuad*); + private: + StreamVideoDrawQuad(); +}; + +} + +#endif // CC_QUADS_STREAM_VIDEO_DRAW_QUAD_H_ diff --git a/cc/quads/texture_draw_quad.cc b/cc/quads/texture_draw_quad.cc new file mode 100644 index 0000000..6b3958f --- /dev/null +++ b/cc/quads/texture_draw_quad.cc @@ -0,0 +1,152 @@ +// 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/texture_draw_quad.h" + +#include "base/logging.h" +#include "ui/gfx/vector2d_f.h" + +namespace cc { + +TextureDrawQuad::TextureDrawQuad() + : resource_id(0), + premultiplied_alpha(false), + flipped(false) { + this->vertex_opacity[0] = 0.f; + this->vertex_opacity[1] = 0.f; + this->vertex_opacity[2] = 0.f; + this->vertex_opacity[3] = 0.f; +} + +scoped_ptr<TextureDrawQuad> TextureDrawQuad::Create() { + return make_scoped_ptr(new TextureDrawQuad); +} + +void TextureDrawQuad::SetNew(const SharedQuadState* shared_quad_state, + gfx::Rect rect, gfx::Rect opaque_rect, + unsigned resource_id, bool premultiplied_alpha, + gfx::PointF uv_top_left, + gfx::PointF uv_bottom_right, + const float vertex_opacity[4], bool flipped) { + gfx::Rect visible_rect = rect; + bool needs_blending = vertex_opacity[0] != 1.0f || vertex_opacity[1] != 1.0f + || vertex_opacity[2] != 1.0f || vertex_opacity[3] != 1.0f; + DrawQuad::SetAll(shared_quad_state, DrawQuad::TEXTURE_CONTENT, rect, + opaque_rect, visible_rect, needs_blending); + this->resource_id = resource_id; + this->premultiplied_alpha = premultiplied_alpha; + this->uv_top_left = uv_top_left; + this->uv_bottom_right = uv_bottom_right; + this->vertex_opacity[0] = vertex_opacity[0]; + this->vertex_opacity[1] = vertex_opacity[1]; + this->vertex_opacity[2] = vertex_opacity[2]; + this->vertex_opacity[3] = vertex_opacity[3]; + this->flipped = flipped; +} + +void TextureDrawQuad::SetAll(const SharedQuadState* shared_quad_state, + gfx::Rect rect, gfx::Rect opaque_rect, + gfx::Rect visible_rect, bool needs_blending, + unsigned resource_id, bool premultiplied_alpha, + gfx::PointF uv_top_left, + gfx::PointF uv_bottom_right, + const float vertex_opacity[4], bool flipped) { + DrawQuad::SetAll(shared_quad_state, DrawQuad::TEXTURE_CONTENT, rect, + opaque_rect, visible_rect, needs_blending); + this->resource_id = resource_id; + this->premultiplied_alpha = premultiplied_alpha; + this->uv_top_left = uv_top_left; + this->uv_bottom_right = uv_bottom_right; + this->vertex_opacity[0] = vertex_opacity[0]; + this->vertex_opacity[1] = vertex_opacity[1]; + this->vertex_opacity[2] = vertex_opacity[2]; + this->vertex_opacity[3] = vertex_opacity[3]; + this->flipped = flipped; +} + +void TextureDrawQuad::IterateResources( + const ResourceIteratorCallback& callback) { + resource_id = callback.Run(resource_id); +} + +const TextureDrawQuad* TextureDrawQuad::MaterialCast(const DrawQuad* quad) { + DCHECK(quad->material == DrawQuad::TEXTURE_CONTENT); + return static_cast<const TextureDrawQuad*>(quad); +} + +bool TextureDrawQuad::PerformClipping() { + // This only occurs if the rect is only scaled and translated (and thus still + // axis aligned). + if (!quadTransform().IsPositiveScaleOrTranslation()) + return false; + + // Grab our scale and make sure it's positive. + float x_scale = static_cast<float>(quadTransform().matrix().getDouble(0, 0)); + float y_scale = static_cast<float>(quadTransform().matrix().getDouble(1, 1)); + + // Grab our offset. + gfx::Vector2dF offset( + static_cast<float>(quadTransform().matrix().getDouble(0, 3)), + static_cast<float>(quadTransform().matrix().getDouble(1, 3))); + + // Transform the rect by the scale and offset. + gfx::RectF rectF = rect; + rectF.Scale(x_scale, y_scale); + rectF += offset; + + // Perform clipping and check to see if the result is empty. + gfx::RectF clippedRect = IntersectRects(rectF, clipRect()); + if (clippedRect.IsEmpty()) { + rect = gfx::Rect(); + uv_top_left = gfx::PointF(); + uv_bottom_right = gfx::PointF(); + return true; + } + + // Create a new uv-rect by clipping the old one to the new bounds. + gfx::Vector2dF uv_scale(uv_bottom_right - uv_top_left); + uv_scale.Scale(1.f / rectF.width(), 1.f / rectF.height()); + uv_bottom_right = uv_top_left + + gfx::ScaleVector2d( + clippedRect.bottom_right() - rectF.origin(), + uv_scale.x(), + uv_scale.y()); + uv_top_left = uv_top_left + + gfx::ScaleVector2d( + clippedRect.origin() - rectF.origin(), + uv_scale.x(), + uv_scale.y()); + + // Indexing according to the quad vertex generation: + // 1--2 + // | | + // 0--3 + if (vertex_opacity[0] != vertex_opacity[1] + || vertex_opacity[0] != vertex_opacity[2] + || vertex_opacity[0] != vertex_opacity[3]) { + const float x1 = (clippedRect.x() - rectF.x()) / rectF.width(); + const float y1 = (clippedRect.y() - rectF.y()) / rectF.height(); + const float x3 = (clippedRect.right() - rectF.x()) / rectF.width(); + const float y3 = (clippedRect.bottom() - rectF.y()) / rectF.height(); + const float x1y1 = x1 * vertex_opacity[2] + (1.0f - x1) * vertex_opacity[1]; + const float x1y3 = x1 * vertex_opacity[3] + (1.0f - x1) * vertex_opacity[0]; + const float x3y1 = x3 * vertex_opacity[2] + (1.0f - x3) * vertex_opacity[1]; + const float x3y3 = x3 * vertex_opacity[3] + (1.0f - x3) * vertex_opacity[0]; + vertex_opacity[0] = y3 * x1y3 + (1.0f - y3) * x1y1; + vertex_opacity[1] = y1 * x1y3 + (1.0f - y1) * x1y1; + vertex_opacity[2] = y1 * x3y3 + (1.0f - y1) * x3y1; + vertex_opacity[3] = y3 * x3y3 + (1.0f - y3) * x3y1; + } + + // Move the clipped rectangle back into its space. + clippedRect -= offset; + clippedRect.Scale(1.0f / x_scale, 1.0f / y_scale); + rect = gfx::Rect(static_cast<int>(clippedRect.x() + 0.5f), + static_cast<int>(clippedRect.y() + 0.5f), + static_cast<int>(clippedRect.width() + 0.5f), + static_cast<int>(clippedRect.height() + 0.5f)); + return true; +} + +} // namespace cc diff --git a/cc/quads/texture_draw_quad.h b/cc/quads/texture_draw_quad.h new file mode 100644 index 0000000..c888eca --- /dev/null +++ b/cc/quads/texture_draw_quad.h @@ -0,0 +1,60 @@ +// 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. + +#ifndef CC_QUADS_TEXTURE_DRAW_QUAD_H_ +#define CC_QUADS_TEXTURE_DRAW_QUAD_H_ + +#include "base/memory/scoped_ptr.h" +#include "cc/base/cc_export.h" +#include "cc/quads/draw_quad.h" +#include "ui/gfx/rect_f.h" + +namespace cc { + +class CC_EXPORT TextureDrawQuad : public DrawQuad { + public: + static scoped_ptr<TextureDrawQuad> Create(); + + void SetNew(const SharedQuadState* shared_quad_state, + gfx::Rect rect, + gfx::Rect opaque_rect, + unsigned resource_id, + bool premultiplied_alpha, + gfx::PointF uv_top_left, + gfx::PointF uv_bottom_right, + const float vertex_opacity[4], + bool flipped); + + void SetAll(const SharedQuadState* shared_quad_state, + gfx::Rect rect, + gfx::Rect opaque_rect, + gfx::Rect visible_rect, + bool needs_blending, + unsigned resource_id, + bool premultiplied_alpha, + gfx::PointF uv_top_left, + gfx::PointF uv_bottom_right, + const float vertex_opacity[4], + bool flipped); + + unsigned resource_id; + bool premultiplied_alpha; + gfx::PointF uv_top_left; + gfx::PointF uv_bottom_right; + float vertex_opacity[4]; + bool flipped; + + virtual void IterateResources(const ResourceIteratorCallback& callback) + OVERRIDE; + + static const TextureDrawQuad* MaterialCast(const DrawQuad*); + + bool PerformClipping(); + private: + TextureDrawQuad(); +}; + +} + +#endif // CC_QUADS_TEXTURE_DRAW_QUAD_H_ diff --git a/cc/quads/tile_draw_quad.cc b/cc/quads/tile_draw_quad.cc new file mode 100644 index 0000000..04c4738 --- /dev/null +++ b/cc/quads/tile_draw_quad.cc @@ -0,0 +1,66 @@ +// 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/tile_draw_quad.h" + +#include "base/logging.h" +#include "third_party/khronos/GLES2/gl2.h" + +namespace cc { + +TileDrawQuad::TileDrawQuad() + : resource_id(0), + swizzle_contents(false) { +} + +scoped_ptr<TileDrawQuad> TileDrawQuad::Create() { + return make_scoped_ptr(new TileDrawQuad); +} + +void TileDrawQuad::SetNew(const SharedQuadState* shared_quad_state, + gfx::Rect rect, + gfx::Rect opaque_rect, + unsigned resource_id, + const gfx::RectF& tex_coord_rect, + gfx::Size texture_size, + bool swizzle_contents) { + gfx::Rect visible_rect = rect; + bool needs_blending = false; + DrawQuad::SetAll(shared_quad_state, DrawQuad::TILED_CONTENT, rect, + opaque_rect, visible_rect, needs_blending); + this->resource_id = resource_id; + this->tex_coord_rect = tex_coord_rect; + this->texture_size = texture_size; + this->swizzle_contents = swizzle_contents; +} + +void TileDrawQuad::SetAll(const SharedQuadState* shared_quad_state, + gfx::Rect rect, + gfx::Rect opaque_rect, + gfx::Rect visible_rect, + bool needs_blending, + unsigned resource_id, + const gfx::RectF& tex_coord_rect, + gfx::Size texture_size, + bool swizzle_contents) { + DrawQuad::SetAll(shared_quad_state, DrawQuad::TILED_CONTENT, rect, + opaque_rect, visible_rect, needs_blending); + this->resource_id = resource_id; + this->tex_coord_rect = tex_coord_rect; + this->texture_size = texture_size; + this->swizzle_contents = swizzle_contents; +} + +void TileDrawQuad::IterateResources( + const ResourceIteratorCallback& callback) { + resource_id = callback.Run(resource_id); +} + +const TileDrawQuad* TileDrawQuad::MaterialCast( + const DrawQuad* quad) { + DCHECK(quad->material == DrawQuad::TILED_CONTENT); + return static_cast<const TileDrawQuad*>(quad); +} + +} // namespace cc diff --git a/cc/quads/tile_draw_quad.h b/cc/quads/tile_draw_quad.h new file mode 100644 index 0000000..74c3698 --- /dev/null +++ b/cc/quads/tile_draw_quad.h @@ -0,0 +1,54 @@ +// 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. + +#ifndef CC_QUADS_TILE_DRAW_QUAD_H_ +#define CC_QUADS_TILE_DRAW_QUAD_H_ + +#include "base/memory/scoped_ptr.h" +#include "cc/base/cc_export.h" +#include "cc/quads/draw_quad.h" +#include "third_party/khronos/GLES2/gl2.h" +#include "ui/gfx/point.h" +#include "ui/gfx/size.h" + +namespace cc { + +class CC_EXPORT TileDrawQuad : public DrawQuad { + public: + static scoped_ptr<TileDrawQuad> Create(); + + void SetNew(const SharedQuadState* shared_quad_state, + gfx::Rect rect, + gfx::Rect opaque_rect, + unsigned resource_id, + const gfx::RectF& tex_coord_rect, + gfx::Size texture_size, + bool swizzle_contents); + + void SetAll(const SharedQuadState* shared_quad_state, + gfx::Rect rect, + gfx::Rect opaque_rect, + gfx::Rect visible_rect, + bool needs_blending, + unsigned resource_id, + const gfx::RectF& tex_coord_rect, + gfx::Size texture_size, + bool swizzle_contents); + + unsigned resource_id; + gfx::RectF tex_coord_rect; + gfx::Size texture_size; + bool swizzle_contents; + + virtual void IterateResources(const ResourceIteratorCallback& callback) + OVERRIDE; + + static const TileDrawQuad* MaterialCast(const DrawQuad*); + private: + TileDrawQuad(); +}; + +} + +#endif // CC_QUADS_TILE_DRAW_QUAD_H_ diff --git a/cc/quads/yuv_video_draw_quad.cc b/cc/quads/yuv_video_draw_quad.cc new file mode 100644 index 0000000..361935a --- /dev/null +++ b/cc/quads/yuv_video_draw_quad.cc @@ -0,0 +1,65 @@ +// 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/yuv_video_draw_quad.h" + +#include "base/logging.h" + +namespace cc { + +YUVVideoDrawQuad::YUVVideoDrawQuad() {} +YUVVideoDrawQuad::~YUVVideoDrawQuad() {} + +scoped_ptr<YUVVideoDrawQuad> YUVVideoDrawQuad::Create() { + return make_scoped_ptr(new YUVVideoDrawQuad); +} + +void YUVVideoDrawQuad::SetNew(const SharedQuadState* shared_quad_state, + gfx::Rect rect, + gfx::Rect opaque_rect, + gfx::SizeF tex_scale, + const VideoLayerImpl::FramePlane& y_plane, + const VideoLayerImpl::FramePlane& u_plane, + const VideoLayerImpl::FramePlane& v_plane) { + gfx::Rect visible_rect = rect; + bool needs_blending = false; + DrawQuad::SetAll(shared_quad_state, DrawQuad::YUV_VIDEO_CONTENT, rect, + opaque_rect, visible_rect, needs_blending); + this->tex_scale = tex_scale; + this->y_plane = y_plane; + this->u_plane = u_plane; + this->v_plane = v_plane; +} + +void YUVVideoDrawQuad::SetAll(const SharedQuadState* shared_quad_state, + gfx::Rect rect, + gfx::Rect opaque_rect, + gfx::Rect visible_rect, + bool needs_blending, + gfx::SizeF tex_scale, + const VideoLayerImpl::FramePlane& y_plane, + const VideoLayerImpl::FramePlane& u_plane, + const VideoLayerImpl::FramePlane& v_plane) { + DrawQuad::SetAll(shared_quad_state, DrawQuad::YUV_VIDEO_CONTENT, rect, + opaque_rect, visible_rect, needs_blending); + this->tex_scale = tex_scale; + this->y_plane = y_plane; + this->u_plane = u_plane; + this->v_plane = v_plane; +} + +void YUVVideoDrawQuad::IterateResources( + const ResourceIteratorCallback& callback) { + y_plane.resource_id = callback.Run(y_plane.resource_id); + u_plane.resource_id = callback.Run(u_plane.resource_id); + v_plane.resource_id = callback.Run(v_plane.resource_id); +} + +const YUVVideoDrawQuad* YUVVideoDrawQuad::MaterialCast( + const DrawQuad* quad) { + DCHECK(quad->material == DrawQuad::YUV_VIDEO_CONTENT); + return static_cast<const YUVVideoDrawQuad*>(quad); +} + +} // namespace cc diff --git a/cc/quads/yuv_video_draw_quad.h b/cc/quads/yuv_video_draw_quad.h new file mode 100644 index 0000000..34f99be --- /dev/null +++ b/cc/quads/yuv_video_draw_quad.h @@ -0,0 +1,55 @@ +// 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. + +#ifndef CC_QUADS_YUV_VIDEO_DRAW_QUAD_H_ +#define CC_QUADS_YUV_VIDEO_DRAW_QUAD_H_ + +#include "base/basictypes.h" +#include "base/memory/scoped_ptr.h" +#include "cc/base/cc_export.h" +#include "cc/quads/draw_quad.h" +#include "cc/video_layer_impl.h" + +namespace cc { + +class CC_EXPORT YUVVideoDrawQuad : public DrawQuad { + public: + virtual ~YUVVideoDrawQuad(); + + static scoped_ptr<YUVVideoDrawQuad> Create(); + + void SetNew(const SharedQuadState* shared_quad_state, + gfx::Rect rect, + gfx::Rect opaque_rect, + gfx::SizeF tex_scale, + const VideoLayerImpl::FramePlane& y_plane, + const VideoLayerImpl::FramePlane& u_plane, + const VideoLayerImpl::FramePlane& v_plane); + + void SetAll(const SharedQuadState* shared_quad_state, + gfx::Rect rect, + gfx::Rect opaque_rect, + gfx::Rect visible_rect, + bool needs_blending, + gfx::SizeF tex_scale, + const VideoLayerImpl::FramePlane& y_plane, + const VideoLayerImpl::FramePlane& u_plane, + const VideoLayerImpl::FramePlane& v_plane); + + gfx::SizeF tex_scale; + VideoLayerImpl::FramePlane y_plane; + VideoLayerImpl::FramePlane u_plane; + VideoLayerImpl::FramePlane v_plane; + + virtual void IterateResources(const ResourceIteratorCallback& callback) + OVERRIDE; + + static const YUVVideoDrawQuad* MaterialCast(const DrawQuad*); + private: + YUVVideoDrawQuad(); +}; + +} + +#endif // CC_QUADS_YUV_VIDEO_DRAW_QUAD_H_ |