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

Side by Side Diff: src/effects/gradients/SkTwoPointConicalGradient.cpp

Issue 395603002: Simplify flattening to just write enough to call the factory (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 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
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 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 "SkTwoPointConicalGradient.h" 8 #include "SkTwoPointConicalGradient.h"
9 #include "SkTwoPointConicalGradient_gpu.h" 9 #include "SkTwoPointConicalGradient_gpu.h"
10 10
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 info->fRadius[0] = fRadius1; 336 info->fRadius[0] = fRadius1;
337 info->fRadius[1] = fRadius2; 337 info->fRadius[1] = fRadius2;
338 if (fFlippedGrad) { 338 if (fFlippedGrad) {
339 SkTSwap(info->fPoint[0], info->fPoint[1]); 339 SkTSwap(info->fPoint[0], info->fPoint[1]);
340 SkTSwap(info->fRadius[0], info->fRadius[1]); 340 SkTSwap(info->fRadius[0], info->fRadius[1]);
341 } 341 }
342 } 342 }
343 return kConical_GradientType; 343 return kConical_GradientType;
344 } 344 }
345 345
346 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
346 SkTwoPointConicalGradient::SkTwoPointConicalGradient( 347 SkTwoPointConicalGradient::SkTwoPointConicalGradient(
347 SkReadBuffer& buffer) 348 SkReadBuffer& buffer)
348 : INHERITED(buffer), 349 : INHERITED(buffer),
349 fCenter1(buffer.readPoint()), 350 fCenter1(buffer.readPoint()),
350 fCenter2(buffer.readPoint()), 351 fCenter2(buffer.readPoint()),
351 fRadius1(buffer.readScalar()), 352 fRadius1(buffer.readScalar()),
352 fRadius2(buffer.readScalar()) { 353 fRadius2(buffer.readScalar()) {
353 if (buffer.isVersionLT(SkReadBuffer::kGradientFlippedFlag_Version)) { 354 if (buffer.isVersionLT(SkReadBuffer::kGradientFlippedFlag_Version)) {
354 // V23_COMPATIBILITY_CODE 355 // V23_COMPATIBILITY_CODE
355 // Sort gradient by radius size for old pictures 356 // Sort gradient by radius size for old pictures
356 if (fRadius2 < fRadius1) { 357 if (fRadius2 < fRadius1) {
357 SkTSwap(fCenter1, fCenter2); 358 SkTSwap(fCenter1, fCenter2);
358 SkTSwap(fRadius1, fRadius2); 359 SkTSwap(fRadius1, fRadius2);
359 this->flipGradientColors(); 360 this->flipGradientColors();
360 fFlippedGrad = true; 361 fFlippedGrad = true;
361 } else { 362 } else {
362 fFlippedGrad = false; 363 fFlippedGrad = false;
363 } 364 }
364 } else { 365 } else {
365 fFlippedGrad = buffer.readBool(); 366 fFlippedGrad = buffer.readBool();
366 } 367 }
367 this->init(); 368 this->init();
368 }; 369 };
370 #endif
369 371
370 void SkTwoPointConicalGradient::flatten( 372 SkFlattenable* SkTwoPointConicalGradient::CreateProc(SkReadBuffer& buffer) {
371 SkWriteBuffer& buffer) const { 373 DescriptorScope desc;
374 if (!desc.unflatten(buffer)) {
375 return NULL;
376 }
377 SkPoint c1 = buffer.readPoint();
378 SkPoint c2 = buffer.readPoint();
379 SkScalar r1 = buffer.readScalar();
380 SkScalar r2 = buffer.readScalar();
381
382 if (buffer.readBool()) { // flipped
383 SkTSwap(c1, c2);
384 SkTSwap(r1, r2);
385
386 SkColor* colors = desc.mutableColors();
387 SkScalar* pos = desc.mutablePos();
388 const int last = desc.fCount - 1;
389 const int half = desc.fCount >> 1;
390 for (int i = 0; i < half; ++i) {
391 SkTSwap(colors[i], colors[last - i]);
392 if (pos) {
393 SkScalar tmp = pos[i];
394 pos[i] = SK_Scalar1 - pos[last - i];
395 pos[last - i] = SK_Scalar1 - tmp;
396 }
397 }
398 if (pos) {
399 if (desc.fCount & 1) {
400 pos[half] = SK_Scalar1 - pos[half];
401 }
402 }
403 }
404
405 return SkGradientShader::CreateTwoPointConical(c1, r1, c2, r2, desc.fColors, desc.fPos,
406 desc.fCount, desc.fTileMode, desc.fGradFlags,
407 desc.fLocalMatrix);
408 }
409
410 void SkTwoPointConicalGradient::flatten(SkWriteBuffer& buffer) const {
372 this->INHERITED::flatten(buffer); 411 this->INHERITED::flatten(buffer);
373 buffer.writePoint(fCenter1); 412 buffer.writePoint(fCenter1);
374 buffer.writePoint(fCenter2); 413 buffer.writePoint(fCenter2);
375 buffer.writeScalar(fRadius1); 414 buffer.writeScalar(fRadius1);
376 buffer.writeScalar(fRadius2); 415 buffer.writeScalar(fRadius2);
377 buffer.writeBool(fFlippedGrad); 416 buffer.writeBool(fFlippedGrad);
378 } 417 }
379 418
380 #if SK_SUPPORT_GPU 419 #if SK_SUPPORT_GPU
381 420
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 str->appendScalar(fCenter2.fY); 460 str->appendScalar(fCenter2.fY);
422 str->append(") radius2: "); 461 str->append(") radius2: ");
423 str->appendScalar(fRadius2); 462 str->appendScalar(fRadius2);
424 str->append(" "); 463 str->append(" ");
425 464
426 this->INHERITED::toString(str); 465 this->INHERITED::toString(str);
427 466
428 str->append(")"); 467 str->append(")");
429 } 468 }
430 #endif 469 #endif
OLDNEW
« no previous file with comments | « src/effects/gradients/SkTwoPointConicalGradient.h ('k') | src/effects/gradients/SkTwoPointRadialGradient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698