Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Side by Side Diff: src/core/SkLightingShader.cpp

Issue 2237493002: Added PointLights to SkLights::Light (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: fixed serialization bug Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkCanvas.cpp ('k') | src/core/SkLights.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkBitmapProcShader.h" 8 #include "SkBitmapProcShader.h"
9 #include "SkBitmapProcState.h" 9 #include "SkBitmapProcState.h"
10 #include "SkColor.h" 10 #include "SkColor.h"
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 str->appendf("LightingShader: ()"); 409 str->appendf("LightingShader: ()");
410 } 410 }
411 #endif 411 #endif
412 412
413 sk_sp<SkFlattenable> SkLightingShaderImpl::CreateProc(SkReadBuffer& buf) { 413 sk_sp<SkFlattenable> SkLightingShaderImpl::CreateProc(SkReadBuffer& buf) {
414 414
415 // Discarding SkShader flattenable params 415 // Discarding SkShader flattenable params
416 bool hasLocalMatrix = buf.readBool(); 416 bool hasLocalMatrix = buf.readBool();
417 SkAssertResult(!hasLocalMatrix); 417 SkAssertResult(!hasLocalMatrix);
418 418
419 int numLights = buf.readInt(); 419 sk_sp<SkLights> lights = SkLights::MakeFromBuffer(buf);
420
421 SkLights::Builder builder;
422
423 for (int l = 0; l < numLights; ++l) {
424 bool isAmbient = buf.readBool();
425
426 SkColor3f color;
427 if (!buf.readScalarArray(&color.fX, 3)) {
428 return nullptr;
429 }
430
431 if (isAmbient) {
432 builder.add(SkLights::Light(color));
433 } else {
434 SkVector3 dir;
435 if (!buf.readScalarArray(&dir.fX, 3)) {
436 return nullptr;
437 }
438 builder.add(SkLights::Light(color, dir));
439 }
440 }
441
442 sk_sp<SkLights> lights(builder.finish());
443 420
444 sk_sp<SkNormalSource> normalSource(buf.readFlattenable<SkNormalSource>()); 421 sk_sp<SkNormalSource> normalSource(buf.readFlattenable<SkNormalSource>());
445 422
446 bool hasDiffuse = buf.readBool(); 423 bool hasDiffuse = buf.readBool();
447 sk_sp<SkShader> diffuseShader = nullptr; 424 sk_sp<SkShader> diffuseShader = nullptr;
448 if (hasDiffuse) { 425 if (hasDiffuse) {
449 diffuseShader = buf.readFlattenable<SkShader>(); 426 diffuseShader = buf.readFlattenable<SkShader>();
450 } 427 }
451 428
452 return sk_make_sp<SkLightingShaderImpl>(std::move(diffuseShader), std::move( normalSource), 429 return sk_make_sp<SkLightingShaderImpl>(std::move(diffuseShader), std::move( normalSource),
453 std::move(lights)); 430 std::move(lights));
454 } 431 }
455 432
456 void SkLightingShaderImpl::flatten(SkWriteBuffer& buf) const { 433 void SkLightingShaderImpl::flatten(SkWriteBuffer& buf) const {
457 this->INHERITED::flatten(buf); 434 this->INHERITED::flatten(buf);
458 435
459 buf.writeInt(fLights->numLights()); 436 fLights->flatten(buf);
460 for (int l = 0; l < fLights->numLights(); ++l) {
461 const SkLights::Light& light = fLights->light(l);
462
463 bool isAmbient = SkLights::Light::kAmbient_LightType == light.type();
464
465 buf.writeBool(isAmbient);
466 buf.writeScalarArray(&light.color().fX, 3);
467 if (!isAmbient) {
468 buf.writeScalarArray(&light.dir().fX, 3);
469 }
470 }
471 437
472 buf.writeFlattenable(fNormalSource.get()); 438 buf.writeFlattenable(fNormalSource.get());
473 buf.writeBool(fDiffuseShader); 439 buf.writeBool(fDiffuseShader);
474 if (fDiffuseShader) { 440 if (fDiffuseShader) {
475 buf.writeFlattenable(fDiffuseShader.get()); 441 buf.writeFlattenable(fDiffuseShader.get());
476 } 442 }
477 } 443 }
478 444
479 size_t SkLightingShaderImpl::onContextSize(const ContextRec& rec) const { 445 size_t SkLightingShaderImpl::onContextSize(const ContextRec& rec) const {
480 return sizeof(LightingShaderContext); 446 return sizeof(LightingShaderContext);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 std::move(lights)); 490 std::move(lights));
525 } 491 }
526 492
527 /////////////////////////////////////////////////////////////////////////////// 493 ///////////////////////////////////////////////////////////////////////////////
528 494
529 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) 495 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader)
530 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) 496 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl)
531 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 497 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
532 498
533 /////////////////////////////////////////////////////////////////////////////// 499 ///////////////////////////////////////////////////////////////////////////////
OLDNEW
« no previous file with comments | « src/core/SkCanvas.cpp ('k') | src/core/SkLights.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698