| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 |
| 7 #include "CCDrawQuad.h" |
| 8 |
| 9 #include "CCCheckerboardDrawQuad.h" |
| 10 #include "CCDebugBorderDrawQuad.h" |
| 11 #include "CCGeometryTestUtils.h" |
| 12 #include "CCIOSurfaceDrawQuad.h" |
| 13 #include "CCRenderPassDrawQuad.h" |
| 14 #include "CCSolidColorDrawQuad.h" |
| 15 #include "CCStreamVideoDrawQuad.h" |
| 16 #include "CCTextureDrawQuad.h" |
| 17 #include "CCTileDrawQuad.h" |
| 18 #include "CCYUVVideoDrawQuad.h" |
| 19 #include <gtest/gtest.h> |
| 20 #include <public/WebTransformationMatrix.h> |
| 21 |
| 22 using WebKit::WebTransformationMatrix; |
| 23 |
| 24 using namespace cc; |
| 25 |
| 26 namespace { |
| 27 |
| 28 TEST(CCDrawQuadTest, copySharedQuadState) |
| 29 { |
| 30 WebTransformationMatrix quadTransform(1, 0.5, 0, 1, 0.5, 0); |
| 31 IntRect visibleContentRect(10, 12, 14, 16); |
| 32 IntRect clippedRectInTarget(19, 21, 23, 25); |
| 33 float opacity = 0.25; |
| 34 bool opaque = true; |
| 35 int id = 3; |
| 36 |
| 37 OwnPtr<CCSharedQuadState> state(CCSharedQuadState::create(quadTransform, vis
ibleContentRect, clippedRectInTarget, opacity, opaque)); |
| 38 state->id = id; |
| 39 |
| 40 OwnPtr<CCSharedQuadState> copy(state->copy()); |
| 41 EXPECT_EQ(id, copy->id); |
| 42 EXPECT_EQ(quadTransform, copy->quadTransform); |
| 43 EXPECT_RECT_EQ(visibleContentRect, copy->visibleContentRect); |
| 44 EXPECT_RECT_EQ(clippedRectInTarget, copy->clippedRectInTarget); |
| 45 EXPECT_EQ(opacity, copy->opacity); |
| 46 EXPECT_EQ(opaque, copy->opaque); |
| 47 } |
| 48 |
| 49 PassOwnPtr<CCSharedQuadState> createSharedQuadState() |
| 50 { |
| 51 WebTransformationMatrix quadTransform(1, 0.5, 0, 1, 0.5, 0); |
| 52 IntRect visibleContentRect(10, 12, 14, 16); |
| 53 IntRect clippedRectInTarget(19, 21, 23, 25); |
| 54 float opacity = 1; |
| 55 bool opaque = false; |
| 56 int id = 3; |
| 57 |
| 58 OwnPtr<CCSharedQuadState> state(CCSharedQuadState::create(quadTransform, vis
ibleContentRect, clippedRectInTarget, opacity, opaque)); |
| 59 state->id = id; |
| 60 return state.release(); |
| 61 } |
| 62 |
| 63 void compareDrawQuad(CCDrawQuad* quad, CCDrawQuad* copy, CCSharedQuadState* copy
SharedState) |
| 64 { |
| 65 EXPECT_EQ(quad->size(), copy->size()); |
| 66 EXPECT_EQ(quad->material(), copy->material()); |
| 67 EXPECT_EQ(quad->isDebugQuad(), copy->isDebugQuad()); |
| 68 EXPECT_RECT_EQ(quad->quadRect(), copy->quadRect()); |
| 69 EXPECT_RECT_EQ(quad->quadVisibleRect(), copy->quadVisibleRect()); |
| 70 EXPECT_EQ(quad->opaqueRect(), copy->opaqueRect()); |
| 71 EXPECT_EQ(quad->needsBlending(), copy->needsBlending()); |
| 72 |
| 73 EXPECT_EQ(copySharedState, copy->sharedQuadState()); |
| 74 EXPECT_EQ(copySharedState->id, copy->sharedQuadStateId()); |
| 75 |
| 76 EXPECT_EQ(quad->sharedQuadStateId(), quad->sharedQuadState()->id); |
| 77 EXPECT_EQ(copy->sharedQuadStateId(), copy->sharedQuadState()->id); |
| 78 } |
| 79 |
| 80 #define CREATE_SHARED_STATE() \ |
| 81 OwnPtr<CCSharedQuadState> sharedState(createSharedQuadState()); \ |
| 82 OwnPtr<CCSharedQuadState> copySharedState(sharedState->copy()); \ |
| 83 copySharedState->id = 5; |
| 84 |
| 85 #define QUAD_DATA \ |
| 86 IntRect quadRect(30, 40, 50, 60); \ |
| 87 IntRect quadVisibleRect(40, 50, 30, 20); \ |
| 88 |
| 89 #define SETUP_AND_COPY_QUAD(Type, quad) \ |
| 90 quad->setQuadVisibleRect(quadVisibleRect); \ |
| 91 OwnPtr<CCDrawQuad> copy(quad->copy(copySharedState.get())); \ |
| 92 compareDrawQuad(quad.get(), copy.get(), copySharedState.get()); \ |
| 93 const Type* copyQuad = Type::materialCast(copy.get()); |
| 94 |
| 95 #define SETUP_AND_COPY_QUAD_1(Type, quad, a) \ |
| 96 quad->setQuadVisibleRect(quadVisibleRect); \ |
| 97 OwnPtr<CCDrawQuad> copy(quad->copy(copySharedState.get(), a)); \ |
| 98 compareDrawQuad(quad.get(), copy.get(), copySharedState.get()); \ |
| 99 const Type* copyQuad = Type::materialCast(copy.get()); |
| 100 |
| 101 #define CREATE_QUAD_0(Type) \ |
| 102 QUAD_DATA \ |
| 103 OwnPtr<Type> quad(Type::create(sharedState.get(), quadRect)); \ |
| 104 SETUP_AND_COPY_QUAD(Type, quad); \ |
| 105 UNUSED_PARAM(copyQuad); |
| 106 |
| 107 #define CREATE_QUAD_1(Type, a) \ |
| 108 QUAD_DATA \ |
| 109 OwnPtr<Type> quad(Type::create(sharedState.get(), quadRect, a)); \ |
| 110 SETUP_AND_COPY_QUAD(Type, quad); |
| 111 |
| 112 #define CREATE_QUAD_2(Type, a, b) \ |
| 113 QUAD_DATA \ |
| 114 OwnPtr<Type> quad(Type::create(sharedState.get(), quadRect, a, b)); \ |
| 115 SETUP_AND_COPY_QUAD(Type, quad); |
| 116 |
| 117 #define CREATE_QUAD_3(Type, a, b, c) \ |
| 118 QUAD_DATA \ |
| 119 OwnPtr<Type> quad(Type::create(sharedState.get(), quadRect, a, b, c)); \ |
| 120 SETUP_AND_COPY_QUAD(Type, quad); |
| 121 |
| 122 #define CREATE_QUAD_4(Type, a, b, c, d) \ |
| 123 QUAD_DATA \ |
| 124 OwnPtr<Type> quad(Type::create(sharedState.get(), quadRect, a, b, c, d)); \ |
| 125 SETUP_AND_COPY_QUAD(Type, quad); |
| 126 |
| 127 #define CREATE_QUAD_5(Type, a, b, c, d, e) \ |
| 128 QUAD_DATA \ |
| 129 OwnPtr<Type> quad(Type::create(sharedState.get(), quadRect, a, b, c, d, e));
\ |
| 130 SETUP_AND_COPY_QUAD(Type, quad); |
| 131 |
| 132 #define CREATE_QUAD_6(Type, a, b, c, d, e, f) \ |
| 133 QUAD_DATA \ |
| 134 OwnPtr<Type> quad(Type::create(sharedState.get(), quadRect, a, b, c, d, e, f
)); \ |
| 135 SETUP_AND_COPY_QUAD(Type, quad); |
| 136 |
| 137 #define CREATE_QUAD_7(Type, a, b, c, d, e, f, g) \ |
| 138 QUAD_DATA \ |
| 139 OwnPtr<Type> quad(Type::create(sharedState.get(), quadRect, a, b, c, d, e, f
, g)); \ |
| 140 SETUP_AND_COPY_QUAD(Type, quad); |
| 141 |
| 142 #define CREATE_QUAD_8(Type, a, b, c, d, e, f, g, h) \ |
| 143 QUAD_DATA \ |
| 144 OwnPtr<Type> quad(Type::create(sharedState.get(), quadRect, a, b, c, d, e, f
, g, h)); \ |
| 145 SETUP_AND_COPY_QUAD(Type, quad); |
| 146 |
| 147 #define CREATE_QUAD_8_1(Type, a, b, c, d, e, f, g, h, copyA) \ |
| 148 QUAD_DATA \ |
| 149 OwnPtr<Type> quad(Type::create(sharedState.get(), quadRect, a, b, c, d, e, f
, g, h)); \ |
| 150 SETUP_AND_COPY_QUAD_1(Type, quad, copyA); |
| 151 |
| 152 #define CREATE_QUAD_9(Type, a, b, c, d, e, f, g, h, i) \ |
| 153 QUAD_DATA \ |
| 154 OwnPtr<Type> quad(Type::create(sharedState.get(), quadRect, a, b, c, d, e, f
, g, h, i)); \ |
| 155 SETUP_AND_COPY_QUAD(Type, quad); |
| 156 |
| 157 #define CREATE_QUAD_10(Type, a, b, c, d, e, f, g, h, i, j) \ |
| 158 QUAD_DATA \ |
| 159 OwnPtr<Type> quad(Type::create(sharedState.get(), quadRect, a, b, c, d, e, f
, g, h, i, j)); \ |
| 160 SETUP_AND_COPY_QUAD(Type, quad); |
| 161 |
| 162 TEST(CCDrawQuadTest, copyCheckerboardDrawQuad) |
| 163 { |
| 164 CREATE_SHARED_STATE(); |
| 165 CREATE_QUAD_0(CCCheckerboardDrawQuad); |
| 166 } |
| 167 |
| 168 TEST(CCDrawQuadTest, copyDebugBorderDrawQuad) |
| 169 { |
| 170 SkColor color = 0xfabb0011; |
| 171 int width = 99; |
| 172 CREATE_SHARED_STATE(); |
| 173 CREATE_QUAD_2(CCDebugBorderDrawQuad, color, width); |
| 174 EXPECT_EQ(color, copyQuad->color()); |
| 175 EXPECT_EQ(width, copyQuad->width()); |
| 176 } |
| 177 |
| 178 TEST(CCDrawQuadTest, copyIOSurfaceDrawQuad) |
| 179 { |
| 180 IntSize size(58, 95); |
| 181 unsigned textureId = 72; |
| 182 CCIOSurfaceDrawQuad::Orientation orientation = CCIOSurfaceDrawQuad::Unflippe
d; |
| 183 |
| 184 CREATE_SHARED_STATE(); |
| 185 CREATE_QUAD_3(CCIOSurfaceDrawQuad, size, textureId, orientation); |
| 186 EXPECT_EQ(size, copyQuad->ioSurfaceSize()); |
| 187 EXPECT_EQ(textureId, copyQuad->ioSurfaceTextureId()); |
| 188 EXPECT_EQ(orientation, copyQuad->orientation()); |
| 189 } |
| 190 |
| 191 TEST(CCDrawQuadTest, copyRenderPassDrawQuad) |
| 192 { |
| 193 CCRenderPass::Id renderPassId(22, 64); |
| 194 bool isReplica = true; |
| 195 CCResourceProvider::ResourceId maskResourceId = 78; |
| 196 IntRect contentsChangedSinceLastFrame(42, 11, 74, 24); |
| 197 float maskTexCoordScaleX = 33; |
| 198 float maskTexCoordScaleY = 19; |
| 199 float maskTexCoordOffsetX = -45; |
| 200 float maskTexCoordOffsetY = -21; |
| 201 |
| 202 CCRenderPass::Id copiedRenderPassId(235, 11); |
| 203 |
| 204 CREATE_SHARED_STATE(); |
| 205 CREATE_QUAD_8_1(CCRenderPassDrawQuad, renderPassId, isReplica, maskResourceI
d, contentsChangedSinceLastFrame, maskTexCoordScaleX, maskTexCoordScaleY, maskTe
xCoordOffsetX, maskTexCoordOffsetY, copiedRenderPassId); |
| 206 EXPECT_EQ(copiedRenderPassId, copyQuad->renderPassId()); |
| 207 EXPECT_EQ(isReplica, copyQuad->isReplica()); |
| 208 EXPECT_EQ(maskResourceId, copyQuad->maskResourceId()); |
| 209 EXPECT_RECT_EQ(contentsChangedSinceLastFrame, copyQuad->contentsChangedSince
LastFrame()); |
| 210 EXPECT_EQ(maskTexCoordScaleX, copyQuad->maskTexCoordScaleX()); |
| 211 EXPECT_EQ(maskTexCoordScaleY, copyQuad->maskTexCoordScaleY()); |
| 212 EXPECT_EQ(maskTexCoordOffsetX, copyQuad->maskTexCoordOffsetX()); |
| 213 EXPECT_EQ(maskTexCoordOffsetY, copyQuad->maskTexCoordOffsetY()); |
| 214 } |
| 215 |
| 216 TEST(CCDrawQuadTest, copySolidColorDrawQuad) |
| 217 { |
| 218 SkColor color = 0x49494949; |
| 219 |
| 220 CREATE_SHARED_STATE(); |
| 221 CREATE_QUAD_1(CCSolidColorDrawQuad, color); |
| 222 EXPECT_EQ(color, copyQuad->color()); |
| 223 } |
| 224 |
| 225 TEST(CCDrawQuadTest, copyStreamVideoDrawQuad) |
| 226 { |
| 227 unsigned textureId = 64; |
| 228 WebTransformationMatrix matrix(0.5, 1, 0.25, 0.75, 0, 1); |
| 229 |
| 230 CREATE_SHARED_STATE(); |
| 231 CREATE_QUAD_2(CCStreamVideoDrawQuad, textureId, matrix); |
| 232 EXPECT_EQ(textureId, copyQuad->textureId()); |
| 233 EXPECT_EQ(matrix, copyQuad->matrix()); |
| 234 } |
| 235 |
| 236 TEST(CCDrawQuadTest, copyTextureDrawQuad) |
| 237 { |
| 238 unsigned resourceId = 82; |
| 239 bool premultipliedAlpha = true; |
| 240 FloatRect uvRect(0.5, 224, -51, 36); |
| 241 bool flipped = true; |
| 242 |
| 243 CREATE_SHARED_STATE(); |
| 244 CREATE_QUAD_4(CCTextureDrawQuad, resourceId, premultipliedAlpha, uvRect, fli
pped); |
| 245 EXPECT_EQ(resourceId, copyQuad->resourceId()); |
| 246 EXPECT_EQ(premultipliedAlpha, copyQuad->premultipliedAlpha()); |
| 247 EXPECT_EQ(uvRect, copyQuad->uvRect()); |
| 248 EXPECT_EQ(flipped, copyQuad->flipped()); |
| 249 } |
| 250 |
| 251 TEST(CCDrawQuadTest, copyTileDrawQuad) |
| 252 { |
| 253 IntRect opaqueRect(33, 44, 22, 33); |
| 254 unsigned resourceId = 104; |
| 255 IntPoint textureOffset(-31, 47); |
| 256 IntSize textureSize(85, 32); |
| 257 GC3Dint textureFilter = 82; |
| 258 bool swizzleContents = true; |
| 259 bool leftEdgeAA = true; |
| 260 bool topEdgeAA = true; |
| 261 bool rightEdgeAA = false; |
| 262 bool bottomEdgeAA = true; |
| 263 |
| 264 CREATE_SHARED_STATE(); |
| 265 CREATE_QUAD_10(CCTileDrawQuad, opaqueRect, resourceId, textureOffset, textur
eSize, textureFilter, swizzleContents, leftEdgeAA, topEdgeAA, rightEdgeAA, botto
mEdgeAA); |
| 266 EXPECT_RECT_EQ(opaqueRect, copyQuad->opaqueRect()); |
| 267 EXPECT_EQ(resourceId, copyQuad->resourceId()); |
| 268 EXPECT_EQ(textureOffset, copyQuad->textureOffset()); |
| 269 EXPECT_EQ(textureSize, copyQuad->textureSize()); |
| 270 EXPECT_EQ(textureFilter, copyQuad->textureFilter()); |
| 271 EXPECT_EQ(swizzleContents, copyQuad->swizzleContents()); |
| 272 EXPECT_EQ(leftEdgeAA, copyQuad->leftEdgeAA()); |
| 273 EXPECT_EQ(topEdgeAA, copyQuad->topEdgeAA()); |
| 274 EXPECT_EQ(rightEdgeAA, copyQuad->rightEdgeAA()); |
| 275 EXPECT_EQ(bottomEdgeAA, copyQuad->bottomEdgeAA()); |
| 276 } |
| 277 |
| 278 TEST(CCDrawQuadTest, copyYUVVideoDrawQuad) |
| 279 { |
| 280 CCVideoLayerImpl::FramePlane yPlane; |
| 281 yPlane.resourceId = 45; |
| 282 yPlane.size = IntSize(34, 23); |
| 283 yPlane.format = 8; |
| 284 yPlane.visibleSize = IntSize(623, 235); |
| 285 CCVideoLayerImpl::FramePlane uPlane; |
| 286 uPlane.resourceId = 532; |
| 287 uPlane.size = IntSize(134, 16); |
| 288 uPlane.format = 2; |
| 289 uPlane.visibleSize = IntSize(126, 27); |
| 290 CCVideoLayerImpl::FramePlane vPlane; |
| 291 vPlane.resourceId = 4; |
| 292 vPlane.size = IntSize(456, 486); |
| 293 vPlane.format = 46; |
| 294 vPlane.visibleSize = IntSize(19, 45); |
| 295 |
| 296 CREATE_SHARED_STATE(); |
| 297 CREATE_QUAD_3(CCYUVVideoDrawQuad, yPlane, uPlane, vPlane); |
| 298 EXPECT_EQ(yPlane.resourceId, copyQuad->yPlane().resourceId); |
| 299 EXPECT_EQ(yPlane.size, copyQuad->yPlane().size); |
| 300 EXPECT_EQ(yPlane.format, copyQuad->yPlane().format); |
| 301 EXPECT_EQ(yPlane.visibleSize, copyQuad->yPlane().visibleSize); |
| 302 EXPECT_EQ(uPlane.resourceId, copyQuad->uPlane().resourceId); |
| 303 EXPECT_EQ(uPlane.size, copyQuad->uPlane().size); |
| 304 EXPECT_EQ(uPlane.format, copyQuad->uPlane().format); |
| 305 EXPECT_EQ(uPlane.visibleSize, copyQuad->uPlane().visibleSize); |
| 306 EXPECT_EQ(vPlane.resourceId, copyQuad->vPlane().resourceId); |
| 307 EXPECT_EQ(vPlane.size, copyQuad->vPlane().size); |
| 308 EXPECT_EQ(vPlane.format, copyQuad->vPlane().format); |
| 309 EXPECT_EQ(vPlane.visibleSize, copyQuad->vPlane().visibleSize); |
| 310 } |
| 311 |
| 312 } // namespace |
| OLD | NEW |