Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 University of Szeged | 2 * Copyright (C) 2010 University of Szeged |
| 3 * Copyright (C) 2010 Zoltan Herczeg | 3 * Copyright (C) 2010 Zoltan Herczeg |
| 4 * Copyright (C) 2013 Google Inc. All rights reserved. | 4 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 offset -= widthMultipliedByPixelSize; | 180 offset -= widthMultipliedByPixelSize; |
| 181 int topLeft = static_cast<int>(pixels->item(offset - cPixelSize + cAlphaChan nelOffset)); | 181 int topLeft = static_cast<int>(pixels->item(offset - cPixelSize + cAlphaChan nelOffset)); |
| 182 int top = static_cast<int>(pixels->item(offset + cAlphaChannelOffset)); | 182 int top = static_cast<int>(pixels->item(offset + cAlphaChannelOffset)); |
| 183 normalVector.setX(-topLeft + top - (left << 1) + (center << 1)); | 183 normalVector.setX(-topLeft + top - (left << 1) + (center << 1)); |
| 184 normalVector.setY(-topLeft - (top << 1) + left + (center << 1)); | 184 normalVector.setY(-topLeft - (top << 1) + left + (center << 1)); |
| 185 } | 185 } |
| 186 | 186 |
| 187 inline void FELighting::inlineSetPixel(int offset, LightingData& data, LightSour ce::PaintingData& paintingData, | 187 inline void FELighting::inlineSetPixel(int offset, LightingData& data, LightSour ce::PaintingData& paintingData, |
| 188 int lightX, int lightY, float factorX, fl oat factorY, IntPoint& normal2DVector) | 188 int lightX, int lightY, float factorX, fl oat factorY, IntPoint& normal2DVector) |
| 189 { | 189 { |
| 190 m_lightSource->updatePaintingData(paintingData, lightX, lightY, static_cast< float>(data.pixels->item(offset + cAlphaChannelOffset)) * data.surfaceScale); | 190 float transformedLightX = (static_cast<float>(lightX) + data.originOffset.wi dth()) / data.worldScale.x(); |
| 191 float transformedLightY = (static_cast<float>(lightY) + data.originOffset.he ight()) / data.worldScale.y(); | |
| 192 m_lightSource->updatePaintingData(paintingData, transformedLightX, transform edLightY, static_cast<float>(data.pixels->item(offset + cAlphaChannelOffset)) * data.surfaceScale * data.worldScale.z()); | |
| 191 | 193 |
| 192 float lightStrength; | 194 float lightStrength; |
| 193 if (!normal2DVector.x() && !normal2DVector.y()) { | 195 if (!normal2DVector.x() && !normal2DVector.y()) { |
| 194 // Normal vector is (0, 0, 1). This is a quite frequent case. | 196 // Normal vector is (0, 0, 1). This is a quite frequent case. |
| 195 if (m_lightingType == FELighting::DiffuseLighting) { | 197 if (m_lightingType == FELighting::DiffuseLighting) { |
| 196 lightStrength = m_diffuseConstant * paintingData.lightVector.z() / p aintingData.lightVectorLength; | 198 lightStrength = m_diffuseConstant * paintingData.lightVector.z() / p aintingData.lightVectorLength; |
| 197 } else { | 199 } else { |
| 198 FloatPoint3D halfwayVector = paintingData.lightVector; | 200 FloatPoint3D halfwayVector = paintingData.lightVector; |
| 199 halfwayVector.setZ(halfwayVector.z() + paintingData.lightVectorLengt h); | 201 halfwayVector.setZ(halfwayVector.z() + paintingData.lightVectorLengt h); |
| 200 float halfwayVectorLength = halfwayVector.length(); | 202 float halfwayVectorLength = halfwayVector.length(); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 inline void FELighting::platformApply(LightingData& data, LightSource::PaintingD ata& paintingData) | 297 inline void FELighting::platformApply(LightingData& data, LightSource::PaintingD ata& paintingData) |
| 296 { | 298 { |
| 297 // The selection here eventually should happen dynamically on some platforms . | 299 // The selection here eventually should happen dynamically on some platforms . |
| 298 #if CPU(ARM_NEON) && CPU(ARM_TRADITIONAL) && COMPILER(GCC) | 300 #if CPU(ARM_NEON) && CPU(ARM_TRADITIONAL) && COMPILER(GCC) |
| 299 platformApplyNeon(data, paintingData); | 301 platformApplyNeon(data, paintingData); |
| 300 #else | 302 #else |
| 301 platformApplyGeneric(data, paintingData); | 303 platformApplyGeneric(data, paintingData); |
| 302 #endif | 304 #endif |
| 303 } | 305 } |
| 304 | 306 |
| 307 void FELighting::getTransform(FloatSize* offset, FloatPoint3D* scale) const | |
| 308 { | |
| 309 FloatRect initialEffectRect = effectBoundaries(); | |
| 310 FloatRect absoluteEffectRect = filter()->mapLocalRectToAbsoluteRect(initialE ffectRect); | |
| 311 FloatPoint absoluteLocation(absolutePaintRect().location()); | |
| 312 FloatSize positionOffset(absoluteLocation - absoluteEffectRect.location()); | |
| 313 offset->setWidth(positionOffset.width()); | |
| 314 offset->setHeight(positionOffset.height()); | |
| 315 scale->setX(initialEffectRect.width() > 0.0f && initialEffectRect.width() > 0.0f ? absoluteEffectRect.width() / initialEffectRect.width() : 1.0f); | |
| 316 scale->setY(initialEffectRect.height() > 0.0f && initialEffectRect.height() > 0.0f ? absoluteEffectRect.height() / initialEffectRect.height() : 1.0f); | |
| 317 // X and Y scale should be the same, but, if not, do a best effort by averag ing the 2 for Z scale | |
| 318 scale->setZ(0.5f * (scale->x() + scale->y())); | |
| 319 } | |
| 320 | |
| 305 bool FELighting::drawLighting(Uint8ClampedArray* pixels, int width, int height) | 321 bool FELighting::drawLighting(Uint8ClampedArray* pixels, int width, int height) |
| 306 { | 322 { |
| 307 LightSource::PaintingData paintingData; | 323 LightSource::PaintingData paintingData; |
| 308 LightingData data; | 324 LightingData data; |
| 309 | 325 |
| 310 if (!m_lightSource) | 326 if (!m_lightSource) |
| 311 return false; | 327 return false; |
| 312 | 328 |
| 313 // FIXME: do something if width or height (or both) is 1 pixel. | 329 // FIXME: do something if width or height (or both) is 1 pixel. |
| 314 // The W3 spec does not define this case. Now the filter just returns. | 330 // The W3 spec does not define this case. Now the filter just returns. |
| 315 if (width <= 2 || height <= 2) | 331 if (width <= 2 || height <= 2) |
| 316 return false; | 332 return false; |
| 317 | 333 |
| 318 data.pixels = pixels; | 334 data.pixels = pixels; |
| 319 data.surfaceScale = m_surfaceScale / 255.0f; | 335 data.surfaceScale = m_surfaceScale / 255.0f; |
| 320 data.widthMultipliedByPixelSize = width * cPixelSize; | 336 data.widthMultipliedByPixelSize = width * cPixelSize; |
| 321 data.widthDecreasedByOne = width - 1; | 337 data.widthDecreasedByOne = width - 1; |
| 322 data.heightDecreasedByOne = height - 1; | 338 data.heightDecreasedByOne = height - 1; |
| 339 getTransform(&data.originOffset, &data.worldScale); | |
| 323 Color lightColor = adaptColorToOperatingColorSpace(m_lightingColor); | 340 Color lightColor = adaptColorToOperatingColorSpace(m_lightingColor); |
| 324 paintingData.colorVector = FloatPoint3D(lightColor.red(), lightColor.green() , lightColor.blue()); | 341 paintingData.colorVector = FloatPoint3D(lightColor.red(), lightColor.green() , lightColor.blue()); |
| 325 m_lightSource->initPaintingData(paintingData); | 342 m_lightSource->initPaintingData(paintingData); |
| 326 | 343 |
| 327 // Top/Left corner. | 344 // Top/Left corner. |
| 328 IntPoint normalVector; | 345 IntPoint normalVector; |
| 329 int offset = 0; | 346 int offset = 0; |
| 330 data.topLeft(offset, normalVector); | 347 data.topLeft(offset, normalVector); |
| 331 setPixel(offset, data, paintingData, 0, 0, cFactor2div3, cFactor2div3, norma lVector); | 348 setPixel(offset, data, paintingData, 0, 0, cFactor2div3, cFactor2div3, norma lVector); |
| 332 | 349 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 432 SkPoint3 direction(cosf(azimuthRad) * cosf(elevationRad), | 449 SkPoint3 direction(cosf(azimuthRad) * cosf(elevationRad), |
| 433 sinf(azimuthRad) * cosf(elevationRad), | 450 sinf(azimuthRad) * cosf(elevationRad), |
| 434 sinf(elevationRad)); | 451 sinf(elevationRad)); |
| 435 if (m_specularConstant > 0) | 452 if (m_specularConstant > 0) |
| 436 return adoptRef(SkLightingImageFilter::CreateDistantLitSpecular(dire ction, lightColor.rgb(), m_surfaceScale, m_specularConstant, m_specularExponent, input.get(), &rect)); | 453 return adoptRef(SkLightingImageFilter::CreateDistantLitSpecular(dire ction, lightColor.rgb(), m_surfaceScale, m_specularConstant, m_specularExponent, input.get(), &rect)); |
| 437 return adoptRef(SkLightingImageFilter::CreateDistantLitDiffuse(direction , lightColor.rgb(), m_surfaceScale, m_diffuseConstant, input.get(), &rect)); | 454 return adoptRef(SkLightingImageFilter::CreateDistantLitDiffuse(direction , lightColor.rgb(), m_surfaceScale, m_diffuseConstant, input.get(), &rect)); |
| 438 } | 455 } |
| 439 case LS_POINT: { | 456 case LS_POINT: { |
| 440 PointLightSource* pointLightSource = static_cast<PointLightSource*>(m_li ghtSource.get()); | 457 PointLightSource* pointLightSource = static_cast<PointLightSource*>(m_li ghtSource.get()); |
| 441 FloatPoint3D position = pointLightSource->position(); | 458 FloatPoint3D position = pointLightSource->position(); |
| 442 SkPoint3 skPosition(position.x(), position.y(), position.z()); | 459 FloatSize offset; |
| 460 FloatPoint3D scale; | |
| 461 getTransform(&offset, &scale); | |
| 462 SkPoint3 skPosition(position.x() * scale.x() - offset.width(), position. y() * scale.y() - offset.height(), position.z() * scale.z()); | |
|
Stephen White
2014/03/03 17:55:09
I don't think we should do this. I think we should
sugoi1
2014/03/03 20:29:30
Done.
| |
| 443 if (m_specularConstant > 0) | 463 if (m_specularConstant > 0) |
| 444 return adoptRef(SkLightingImageFilter::CreatePointLitSpecular(skPosi tion, lightColor.rgb(), m_surfaceScale, m_specularConstant, m_specularExponent, input.get(), &rect)); | 464 return adoptRef(SkLightingImageFilter::CreatePointLitSpecular(skPosi tion, lightColor.rgb(), m_surfaceScale, m_specularConstant, m_specularExponent, input.get(), &rect)); |
| 445 return adoptRef(SkLightingImageFilter::CreatePointLitDiffuse(skPosition, lightColor.rgb(), m_surfaceScale, m_diffuseConstant, input.get(), &rect)); | 465 return adoptRef(SkLightingImageFilter::CreatePointLitDiffuse(skPosition, lightColor.rgb(), m_surfaceScale, m_diffuseConstant, input.get(), &rect)); |
| 446 } | 466 } |
| 447 case LS_SPOT: { | 467 case LS_SPOT: { |
| 448 SpotLightSource* spotLightSource = static_cast<SpotLightSource*>(m_light Source.get()); | 468 SpotLightSource* spotLightSource = static_cast<SpotLightSource*>(m_light Source.get()); |
| 449 SkPoint3 location(spotLightSource->position().x(), spotLightSource->posi tion().y(), spotLightSource->position().z()); | 469 FloatSize offset; |
| 450 SkPoint3 target(spotLightSource->direction().x(), spotLightSource->direc tion().y(), spotLightSource->direction().z()); | 470 FloatPoint3D scale; |
| 471 getTransform(&offset, &scale); | |
| 472 SkPoint3 location(spotLightSource->position().x() * scale.x() - offset.w idth(), spotLightSource->position().y() * scale.y() - offset.height(), spotLight Source->position().z() * scale.z()); | |
| 473 SkPoint3 target(spotLightSource->direction().x() * scale.x() - offset.wi dth(), spotLightSource->direction().y() * scale.y() - offset.height(), spotLight Source->direction().z() * scale.z()); | |
|
Stephen White
2014/03/03 17:55:09
Same here.
sugoi1
2014/03/03 20:29:30
Done.
| |
| 451 float specularExponent = spotLightSource->specularExponent(); | 474 float specularExponent = spotLightSource->specularExponent(); |
| 452 float limitingConeAngle = spotLightSource->limitingConeAngle(); | 475 float limitingConeAngle = spotLightSource->limitingConeAngle(); |
| 453 if (!limitingConeAngle || limitingConeAngle > 90 || limitingConeAngle < -90) | 476 if (!limitingConeAngle || limitingConeAngle > 90 || limitingConeAngle < -90) |
| 454 limitingConeAngle = 90; | 477 limitingConeAngle = 90; |
| 455 if (m_specularConstant > 0) | 478 if (m_specularConstant > 0) |
| 456 return adoptRef(SkLightingImageFilter::CreateSpotLitSpecular(locatio n, target, specularExponent, limitingConeAngle, lightColor.rgb(), m_surfaceScale , m_specularConstant, m_specularExponent, input.get(), &rect)); | 479 return adoptRef(SkLightingImageFilter::CreateSpotLitSpecular(locatio n, target, specularExponent, limitingConeAngle, lightColor.rgb(), m_surfaceScale , m_specularConstant, m_specularExponent, input.get(), &rect)); |
| 457 return adoptRef(SkLightingImageFilter::CreateSpotLitDiffuse(location, ta rget, specularExponent, limitingConeAngle, lightColor.rgb(), m_surfaceScale, m_d iffuseConstant, input.get(), &rect)); | 480 return adoptRef(SkLightingImageFilter::CreateSpotLitDiffuse(location, ta rget, specularExponent, limitingConeAngle, lightColor.rgb(), m_surfaceScale, m_d iffuseConstant, input.get(), &rect)); |
| 458 } | 481 } |
| 459 default: | 482 default: |
| 460 ASSERT_NOT_REACHED(); | 483 ASSERT_NOT_REACHED(); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 486 GraphicsContext* dstContext = resultImage->context(); | 509 GraphicsContext* dstContext = resultImage->context(); |
| 487 | 510 |
| 488 SkPaint paint; | 511 SkPaint paint; |
| 489 RefPtr<SkImageFilter> filter = createImageFilter(0); | 512 RefPtr<SkImageFilter> filter = createImageFilter(0); |
| 490 paint.setImageFilter(filter.get()); | 513 paint.setImageFilter(filter.get()); |
| 491 dstContext->drawBitmap(nativeImage->bitmap(), drawingRegion.location().x(), drawingRegion.location().y(), &paint); | 514 dstContext->drawBitmap(nativeImage->bitmap(), drawingRegion.location().x(), drawingRegion.location().y(), &paint); |
| 492 return true; | 515 return true; |
| 493 } | 516 } |
| 494 | 517 |
| 495 } // namespace WebCore | 518 } // namespace WebCore |
| OLD | NEW |