Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
| 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 "SkEmptyShader.h" | 9 #include "SkEmptyShader.h" |
| 10 #include "SkReadBuffer.h" | 10 #include "SkReadBuffer.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 } | 68 } |
| 69 | 69 |
| 70 SkShader::Context* SkShader::onCreateContext(const ContextRec& rec, void*) const { | 70 SkShader::Context* SkShader::onCreateContext(const ContextRec& rec, void*) const { |
| 71 return NULL; | 71 return NULL; |
| 72 } | 72 } |
| 73 | 73 |
| 74 size_t SkShader::contextSize() const { | 74 size_t SkShader::contextSize() const { |
| 75 return 0; | 75 return 0; |
| 76 } | 76 } |
| 77 | 77 |
| 78 SkShader* SkShader::refLocalMatrixShader(SkMatrix*) const { | |
| 79 return false; | |
| 80 } | |
| 81 | |
| 78 SkShader::Context::Context(const SkShader& shader, const ContextRec& rec) | 82 SkShader::Context::Context(const SkShader& shader, const ContextRec& rec) |
| 79 : fShader(shader), fCTM(*rec.fMatrix) | 83 : fShader(shader), fCTM(*rec.fMatrix) |
| 80 { | 84 { |
| 81 // Because the context parameters must be valid at this point, we know that the matrix is | 85 // Because the context parameters must be valid at this point, we know that the matrix is |
| 82 // invertible. | 86 // invertible. |
| 83 SkAssertResult(fShader.computeTotalInverse(rec, &fTotalInverse)); | 87 SkAssertResult(fShader.computeTotalInverse(rec, &fTotalInverse)); |
| 84 fTotalInverseClass = (uint8_t)ComputeMatrixClass(fTotalInverse); | 88 fTotalInverseClass = (uint8_t)ComputeMatrixClass(fTotalInverse); |
| 85 | 89 |
| 86 fPaintAlpha = rec.fPaint->getAlpha(); | 90 fPaintAlpha = rec.fPaint->getAlpha(); |
| 87 } | 91 } |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 337 #include "SkEmptyShader.h" | 341 #include "SkEmptyShader.h" |
| 338 | 342 |
| 339 void SkEmptyShader::toString(SkString* str) const { | 343 void SkEmptyShader::toString(SkString* str) const { |
| 340 str->append("SkEmptyShader: ("); | 344 str->append("SkEmptyShader: ("); |
| 341 | 345 |
| 342 this->INHERITED::toString(str); | 346 this->INHERITED::toString(str); |
| 343 | 347 |
| 344 str->append(")"); | 348 str->append(")"); |
| 345 } | 349 } |
| 346 #endif | 350 #endif |
| 351 | |
| 352 //////////////////////////////////////////////////////////////////////////////// // | |
| 353 | |
| 354 class SkLocalMatrixShader : public SkShader { | |
|
scroggo
2014/05/07 14:15:41
Would it make sense to put this in its own file?
reed1
2014/05/07 20:37:31
If it get big enough, yes. When I begin, it was pr
| |
| 355 public: | |
| 356 SkLocalMatrixShader(SkShader* proxy, const SkMatrix& localMatrix) | |
| 357 : fProxyShader(SkRef(proxy)) | |
| 358 , fProxyLocalMatrix(localMatrix) | |
| 359 {} | |
| 360 | |
| 361 virtual size_t contextSize() const SK_OVERRIDE { | |
| 362 return fProxyShader->contextSize(); | |
| 363 } | |
| 364 | |
| 365 virtual SkShader* refLocalMatrixShader(SkMatrix* localMatrix) const SK_OVERR IDE { | |
| 366 if (localMatrix) { | |
| 367 *localMatrix = fProxyLocalMatrix; | |
| 368 } | |
| 369 return SkRef(fProxyShader.get()); | |
| 370 } | |
| 371 | |
| 372 SK_TO_STRING_OVERRIDE() | |
| 373 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLocalMatrixShader) | |
| 374 | |
| 375 protected: | |
| 376 SkLocalMatrixShader(SkReadBuffer&); | |
| 377 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; | |
| 378 virtual Context* onCreateContext(const ContextRec&, void*) const SK_OVERRIDE ; | |
| 379 | |
| 380 private: | |
| 381 SkAutoTUnref<SkShader> fProxyShader; | |
| 382 SkMatrix fProxyLocalMatrix; | |
| 383 | |
| 384 typedef SkShader INHERITED; | |
| 385 }; | |
| 386 | |
| 387 SkLocalMatrixShader::SkLocalMatrixShader(SkReadBuffer& buffer) : INHERITED(buffe r) { | |
| 388 buffer.readMatrix(&fProxyLocalMatrix); | |
| 389 fProxyShader.reset(buffer.readFlattenable<SkShader>()); | |
| 390 if (NULL == fProxyShader.get()) { | |
| 391 sk_throw(); | |
| 392 } | |
| 393 } | |
| 394 | |
| 395 void SkLocalMatrixShader::flatten(SkWriteBuffer& buffer) const { | |
| 396 this->INHERITED::flatten(buffer); | |
| 397 buffer.writeMatrix(fProxyLocalMatrix); | |
| 398 buffer.writeFlattenable(fProxyShader.get()); | |
| 399 } | |
| 400 | |
| 401 SkShader::Context* SkLocalMatrixShader::onCreateContext(const ContextRec& rec, | |
|
scroggo
2014/05/07 14:15:41
Doesn't this class need to also override asNewEffe
reed1
2014/05/07 20:37:31
Indeed, I need to forward all of those guys. Maybe
| |
| 402 void* storage) const { | |
| 403 ContextRec newRec(rec); | |
| 404 SkMatrix tmp; | |
| 405 if (rec.fLocalMatrix) { | |
| 406 tmp.setConcat(*rec.fLocalMatrix, fProxyLocalMatrix); | |
|
scroggo
2014/05/07 14:15:41
This ordering seems backwards to me. It appears to
reed1
2014/05/07 20:37:31
Good catch. Done.
| |
| 407 newRec.fLocalMatrix = &tmp; | |
| 408 } else { | |
| 409 newRec.fLocalMatrix = &fProxyLocalMatrix; | |
| 410 } | |
| 411 return fProxyShader->createContext(newRec, storage); | |
| 412 } | |
| 413 | |
| 414 #ifndef SK_IGNORE_TO_STRING | |
| 415 void SkLocalMatrixShader::toString(SkString* str) const { | |
| 416 str->append("SkLocalMatrixShader: ("); | |
| 417 | |
| 418 fProxyShader->toString(str); | |
| 419 | |
| 420 this->INHERITED::toString(str); | |
| 421 | |
| 422 str->append(")"); | |
| 423 } | |
| 424 #endif | |
| 425 | |
| 426 SkShader* SkShader::CreateLocalMatrixShader(SkShader* proxy, const SkMatrix& loc alMatrix) { | |
| 427 if (localMatrix.isIdentity()) { | |
| 428 return SkRef(proxy); | |
| 429 } | |
| 430 | |
| 431 const SkMatrix* lm = &localMatrix; | |
| 432 | |
| 433 SkMatrix otherLocalMatrix; | |
| 434 SkAutoTUnref<SkShader> otherProxy(proxy->refLocalMatrixShader(&otherLocalMat rix)); | |
| 435 if (otherProxy.get()) { | |
| 436 otherLocalMatrix.postConcat(localMatrix); | |
| 437 lm = &otherLocalMatrix; | |
| 438 proxy = otherProxy.get(); | |
| 439 } | |
| 440 | |
| 441 return SkNEW_ARGS(SkLocalMatrixShader, (proxy, *lm)); | |
| 442 } | |
| 443 | |
| OLD | NEW |