Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "SkError.h" | 8 #include "SkError.h" |
| 9 #include "SkErrorInternals.h" | 9 #include "SkErrorInternals.h" |
| 10 #include "SkLightingShader.h" | 10 #include "SkLightingShader.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 bool computeNormTotalInverse(const SkShader::ContextRec& rec, SkMatrix* norm TotalInverse) const; | 44 bool computeNormTotalInverse(const SkShader::ContextRec& rec, SkMatrix* norm TotalInverse) const; |
| 45 | 45 |
| 46 private: | 46 private: |
| 47 class Provider : public SkNormalSource::Provider { | 47 class Provider : public SkNormalSource::Provider { |
| 48 public: | 48 public: |
| 49 Provider(const NormalMapSourceImpl& source, SkShader::Context* fMapConte xt); | 49 Provider(const NormalMapSourceImpl& source, SkShader::Context* fMapConte xt); |
| 50 | 50 |
| 51 virtual ~Provider() override; | 51 virtual ~Provider() override; |
| 52 | 52 |
| 53 void fillScanLine(int x, int y, SkPoint3 output[], int count) const over ride; | 53 void fillScanLine(int x, int y, SkPoint3 output[], int count) const over ride; |
| 54 | |
| 54 private: | 55 private: |
| 55 const NormalMapSourceImpl& fSource; | 56 const NormalMapSourceImpl& fSource; |
| 56 SkShader::Context* fMapContext; | 57 SkShader::Context* fMapContext; |
| 57 | 58 |
| 58 typedef SkNormalSource::Provider INHERITED; | 59 typedef SkNormalSource::Provider INHERITED; |
| 59 }; | 60 }; |
| 60 | 61 |
| 61 sk_sp<SkShader> fMapShader; | 62 sk_sp<SkShader> fMapShader; |
| 62 SkMatrix fInvCTM; // Inverse of the canvas total matrix, used for rot ating normals. | 63 SkMatrix fInvCTM; // Inverse of the canvas total matrix, used for rot ating normals. |
| 63 | 64 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 return sk_make_sp<NormalMapFP>(std::move(mapFP), fInvCTM); | 191 return sk_make_sp<NormalMapFP>(std::move(mapFP), fInvCTM); |
| 191 } | 192 } |
| 192 | 193 |
| 193 #endif // SK_SUPPORT_GPU | 194 #endif // SK_SUPPORT_GPU |
| 194 | 195 |
| 195 //////////////////////////////////////////////////////////////////////////// | 196 //////////////////////////////////////////////////////////////////////////// |
| 196 | 197 |
| 197 NormalMapSourceImpl::Provider::Provider(const NormalMapSourceImpl& source, | 198 NormalMapSourceImpl::Provider::Provider(const NormalMapSourceImpl& source, |
| 198 SkShader::Context* mapContext) | 199 SkShader::Context* mapContext) |
| 199 : fSource(source) | 200 : fSource(source) |
| 200 , fMapContext(mapContext) { | 201 , fMapContext(mapContext) {} |
| 201 } | |
| 202 | 202 |
| 203 NormalMapSourceImpl::Provider::~Provider() { | 203 NormalMapSourceImpl::Provider::~Provider() { |
| 204 fMapContext->~Context(); | 204 fMapContext->~Context(); |
| 205 } | 205 } |
| 206 | 206 |
| 207 SkNormalSource::Provider* NormalMapSourceImpl::asProvider( | 207 SkNormalSource::Provider* NormalMapSourceImpl::asProvider( |
| 208 const SkShader::ContextRec &rec, void *storage) const { | 208 const SkShader::ContextRec &rec, void *storage) const { |
| 209 SkMatrix normTotalInv; | 209 SkMatrix normTotalInv; |
| 210 if (!this->computeNormTotalInverse(rec, &normTotalInv)) { | 210 if (!this->computeNormTotalInverse(rec, &normTotalInv)) { |
| 211 return nullptr; | 211 return nullptr; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 sk_sp<SkNormalSource> SkNormalSource::MakeFromNormalMap(sk_sp<SkShader> map, con st SkMatrix& ctm) { | 309 sk_sp<SkNormalSource> SkNormalSource::MakeFromNormalMap(sk_sp<SkShader> map, con st SkMatrix& ctm) { |
| 310 SkMatrix invCTM; | 310 SkMatrix invCTM; |
| 311 | 311 |
| 312 if (!ctm.invert(&invCTM) || !map) { | 312 if (!ctm.invert(&invCTM) || !map) { |
| 313 return nullptr; | 313 return nullptr; |
| 314 } | 314 } |
| 315 | 315 |
| 316 return sk_make_sp<NormalMapSourceImpl>(std::move(map), invCTM); | 316 return sk_make_sp<NormalMapSourceImpl>(std::move(map), invCTM); |
| 317 } | 317 } |
| 318 | 318 |
| 319 /////////////////////////////////////////////////////////////////////////////// | |
| 320 | |
| 321 class SK_API NormalFlatSourceImpl : public SkNormalSource { | |
| 322 public: | |
| 323 NormalFlatSourceImpl(){} | |
| 324 | |
| 325 #if SK_SUPPORT_GPU | |
| 326 sk_sp<GrFragmentProcessor> asFragmentProcessor(GrContext*, | |
| 327 const SkMatrix& viewM, | |
| 328 const SkMatrix* localMatrix, | |
| 329 SkFilterQuality, | |
| 330 SkSourceGammaTreatment) const override; | |
| 331 #endif | |
| 332 | |
| 333 SkNormalSource::Provider* asProvider(const SkShader::ContextRec& rec, void* storage) const | |
|
robertphillips
2016/07/11 14:02:04
Hmm, can this be differently indented to not orpha
dvonbeck
2016/07/11 19:37:29
Done.
| |
| 334 override; | |
| 335 size_t providerSize(const SkShader::ContextRec& rec) const override; | |
| 336 | |
| 337 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(NormalFlatSourceImpl) | |
| 338 | |
| 339 protected: | |
| 340 void flatten(SkWriteBuffer& buf) const override; | |
| 341 | |
| 342 private: | |
| 343 class Provider : public SkNormalSource::Provider { | |
| 344 public: | |
| 345 Provider(const NormalFlatSourceImpl& source); | |
| 346 | |
| 347 virtual ~Provider(); | |
| 348 | |
| 349 void fillScanLine(int x, int y, SkPoint3 output[], int count) const over ride; | |
| 350 | |
| 351 private: | |
| 352 const NormalFlatSourceImpl& fSource; | |
| 353 | |
| 354 typedef SkNormalSource::Provider INHERITED; | |
| 355 }; | |
| 356 | |
| 357 friend class SkNormalSource; | |
| 358 | |
| 359 typedef SkNormalSource INHERITED; | |
| 360 }; | |
| 361 | |
| 362 //////////////////////////////////////////////////////////////////////////// | |
| 363 | |
| 364 #if SK_SUPPORT_GPU | |
| 365 | |
|
robertphillips
2016/07/11 14:02:04
??
dvonbeck
2016/07/11 19:37:29
I left the includes there but guarded out so that
robertphillips
2016/07/11 20:51:42
I think so. You can always find the include list e
dvonbeck
2016/07/12 21:01:44
Done.
| |
| 366 #if 0 // Keeping here for reference in case code gets refactored into another fi le | |
| 367 #include "GrCoordTransform.h" | |
| 368 #include "GrInvariantOutput.h" | |
| 369 #include "GrTextureParams.h" | |
| 370 #include "glsl/GrGLSLFragmentProcessor.h" | |
| 371 #include "glsl/GrGLSLFragmentShaderBuilder.h" | |
| 372 #include "SkGr.h" | |
| 373 #endif | |
| 374 | |
| 375 class NormalFlatFP : public GrFragmentProcessor { | |
| 376 public: | |
| 377 NormalFlatFP() { | |
| 378 this->initClassID<NormalFlatFP>(); | |
| 379 } | |
| 380 | |
| 381 class GLSLNormalFlatFP : public GrGLSLFragmentProcessor { | |
| 382 public: | |
| 383 GLSLNormalFlatFP() {} | |
| 384 | |
| 385 void emitCode(EmitArgs& args) override { | |
| 386 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; | |
| 387 | |
| 388 fragBuilder->codeAppendf("%s = vec4(0, 0, 1, 0);", args.fOutputColor ); | |
| 389 } | |
| 390 | |
| 391 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, | |
| 392 GrProcessorKeyBuilder* b) { | |
|
robertphillips
2016/07/11 14:02:04
Is the class ID automatically added ?
egdaniel
2016/07/11 18:00:59
yes.
dvonbeck
2016/07/11 19:37:29
Acknowledged.
| |
| 393 b->add32(0x0); | |
| 394 } | |
| 395 | |
| 396 protected: | |
| 397 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) override {} | |
| 398 }; | |
| 399 | |
| 400 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override { | |
| 401 GLSLNormalFlatFP::GenKey(*this, caps, b); | |
| 402 } | |
| 403 | |
| 404 const char* name() const override { return "NormalFlatFP"; } | |
| 405 | |
| 406 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { | |
| 407 inout->setToUnknown(GrInvariantOutput::ReadInput::kWillNot_ReadInput); | |
| 408 } | |
| 409 | |
| 410 private: | |
| 411 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return new GLSLNormalFlatFP; } | |
| 412 | |
| 413 bool onIsEqual(const GrFragmentProcessor& proc) const override { | |
| 414 return true; | |
| 415 } | |
| 416 }; | |
| 417 | |
| 418 sk_sp<GrFragmentProcessor> NormalFlatSourceImpl::asFragmentProcessor( | |
| 419 GrContext *context, | |
| 420 const SkMatrix &viewM, | |
| 421 const SkMatrix *localMatrix , | |
| 422 SkFilterQuality filterQuali ty, | |
| 423 SkSourceGammaTreatment gamm aTreatment) const { | |
| 424 | |
| 425 return sk_make_sp<NormalFlatFP>(); | |
| 426 } | |
| 427 | |
| 428 #endif // SK_SUPPORT_GPU | |
| 429 | |
| 430 //////////////////////////////////////////////////////////////////////////// | |
| 431 | |
| 432 NormalFlatSourceImpl::Provider::Provider(const NormalFlatSourceImpl& source) | |
| 433 : fSource(source) {} | |
| 434 | |
| 435 NormalFlatSourceImpl::Provider::~Provider() {} | |
| 436 | |
| 437 SkNormalSource::Provider* NormalFlatSourceImpl::asProvider(const SkShader::Conte xtRec &rec, | |
| 438 void *storage) const { | |
| 439 return new (storage) Provider(*this); | |
| 440 } | |
| 441 | |
| 442 size_t NormalFlatSourceImpl::providerSize(const SkShader::ContextRec&) const { | |
| 443 return sizeof(Provider); | |
| 444 } | |
| 445 | |
| 446 void NormalFlatSourceImpl::Provider::fillScanLine(int x, int y, SkPoint3 output[ ], int count) | |
|
robertphillips
2016/07/11 14:02:04
odd identing
dvonbeck
2016/07/11 19:37:29
Done?
| |
| 447 const { | |
| 448 for (int i = 0; i < count; i++) { | |
| 449 output[i] = {0.0f, 0.0f, 1.0f}; | |
| 450 } | |
| 451 } | |
| 452 | |
| 453 //////////////////////////////////////////////////////////////////////////////// | |
| 454 | |
| 455 sk_sp<SkFlattenable> NormalFlatSourceImpl::CreateProc(SkReadBuffer& buf) { | |
| 456 return sk_make_sp<NormalFlatSourceImpl>(); | |
| 457 } | |
| 458 | |
| 459 void NormalFlatSourceImpl::flatten(SkWriteBuffer& buf) const { | |
| 460 this->INHERITED::flatten(buf); | |
| 461 } | |
| 462 | |
| 463 //////////////////////////////////////////////////////////////////////////// | |
| 464 | |
| 465 sk_sp<SkNormalSource> SkNormalSource::MakeFlat() { | |
| 466 return sk_make_sp<NormalFlatSourceImpl>(); | |
| 467 } | |
| 468 | |
| 469 //////////////////////////////////////////////////////////////////////////// | |
| 470 | |
| 319 //////////////////////////////////////////////////////////////////////////// | 471 //////////////////////////////////////////////////////////////////////////// |
| 320 | 472 |
| 321 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkNormalSource) | 473 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkNormalSource) |
| 322 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(NormalMapSourceImpl) | 474 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(NormalMapSourceImpl) |
| 475 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(NormalFlatSourceImpl) | |
| 323 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 476 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| 324 | 477 |
| 325 //////////////////////////////////////////////////////////////////////////// | 478 //////////////////////////////////////////////////////////////////////////// |
| OLD | NEW |