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

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

Issue 1196683003: remove SkDeviceProperties (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Clean up Created 5 years, 6 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 2008 The Android Open Source Project 2 * Copyright 2008 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 "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkCanvasPriv.h" 9 #include "SkCanvasPriv.h"
10 #include "SkBitmapDevice.h" 10 #include "SkBitmapDevice.h"
11 #include "SkColorFilter.h" 11 #include "SkColorFilter.h"
12 #include "SkDeviceProperties.h"
13 #include "SkDraw.h" 12 #include "SkDraw.h"
14 #include "SkDrawable.h" 13 #include "SkDrawable.h"
15 #include "SkDrawFilter.h" 14 #include "SkDrawFilter.h"
16 #include "SkDrawLooper.h" 15 #include "SkDrawLooper.h"
17 #include "SkErrorInternals.h" 16 #include "SkErrorInternals.h"
18 #include "SkImage.h" 17 #include "SkImage.h"
19 #include "SkMetaData.h" 18 #include "SkMetaData.h"
20 #include "SkPathOps.h" 19 #include "SkPathOps.h"
21 #include "SkPatchUtils.h" 20 #include "SkPatchUtils.h"
22 #include "SkPicture.h" 21 #include "SkPicture.h"
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 529
531 SkASSERT(sizeof(DeviceCM) <= sizeof(fDeviceCMStorage)); 530 SkASSERT(sizeof(DeviceCM) <= sizeof(fDeviceCMStorage));
532 fMCRec->fLayer = (DeviceCM*)fDeviceCMStorage; 531 fMCRec->fLayer = (DeviceCM*)fDeviceCMStorage;
533 new (fDeviceCMStorage) DeviceCM(NULL, NULL, NULL, fConservativeRasterClip, f alse); 532 new (fDeviceCMStorage) DeviceCM(NULL, NULL, NULL, fConservativeRasterClip, f alse);
534 533
535 fMCRec->fTopLayer = fMCRec->fLayer; 534 fMCRec->fTopLayer = fMCRec->fLayer;
536 535
537 fSurfaceBase = NULL; 536 fSurfaceBase = NULL;
538 537
539 if (device) { 538 if (device) {
539 // TODO: remove this - the root device & canvas should always have same surfaceProps
540 device->initForRootLayer(fProps.pixelGeometry()); 540 device->initForRootLayer(fProps.pixelGeometry());
541 if (device->forceConservativeRasterClip()) { 541 if (device->forceConservativeRasterClip()) {
542 fConservativeRasterClip = true; 542 fConservativeRasterClip = true;
543 } 543 }
544 device->onAttachToCanvas(this); 544 device->onAttachToCanvas(this);
545 fMCRec->fLayer->fDevice = SkRef(device); 545 fMCRec->fLayer->fDevice = SkRef(device);
546 fMCRec->fRasterClip.setRect(device->getGlobalBounds()); 546 fMCRec->fRasterClip.setRect(device->getGlobalBounds());
547 } 547 }
548 return device; 548 return device;
549 } 549 }
550 550
551 SkCanvas::SkCanvas() 551 SkCanvas::SkCanvas()
552 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) 552 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
553 , fProps(SkSurfaceProps::kLegacyFontHost_InitType) 553 , fProps(SkSurfaceProps::kLegacyFontHost_InitType)
554 { 554 {
555 inc_canvas(); 555 inc_canvas();
556 556
557 this->init(NULL, kDefault_InitFlags); 557 this->init(NULL, kDefault_InitFlags);
558 } 558 }
559 559
560 static SkBitmap make_nopixels(int width, int height) { 560 static SkBitmap make_nopixels(int width, int height) {
561 SkBitmap bitmap; 561 SkBitmap bitmap;
562 bitmap.setInfo(SkImageInfo::MakeUnknown(width, height)); 562 bitmap.setInfo(SkImageInfo::MakeUnknown(width, height));
563 return bitmap; 563 return bitmap;
564 } 564 }
565 565
566 class SkNoPixelsBitmapDevice : public SkBitmapDevice { 566 class SkNoPixelsBitmapDevice : public SkBitmapDevice {
567 public: 567 public:
568 SkNoPixelsBitmapDevice(const SkIRect& bounds) 568 SkNoPixelsBitmapDevice(const SkIRect& bounds, const SkSurfaceProps& surfaceP rops)
569 : INHERITED(make_nopixels(bounds.width(), bounds.height())) 569 : INHERITED(make_nopixels(bounds.width(), bounds.height()), surfaceProps )
570 { 570 {
571 this->setOrigin(bounds.x(), bounds.y()); 571 this->setOrigin(bounds.x(), bounds.y());
572 } 572 }
573 573
574 private: 574 private:
575 575
576 typedef SkBitmapDevice INHERITED; 576 typedef SkBitmapDevice INHERITED;
577 }; 577 };
578 578
579 SkCanvas::SkCanvas(int width, int height, const SkSurfaceProps* props) 579 SkCanvas::SkCanvas(int width, int height, const SkSurfaceProps* props)
580 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) 580 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
581 , fProps(SkSurfacePropsCopyOrDefault(props)) 581 , fProps(SkSurfacePropsCopyOrDefault(props))
582 { 582 {
583 inc_canvas(); 583 inc_canvas();
584 584
585 this->init(SkNEW_ARGS(SkNoPixelsBitmapDevice, 585 this->init(SkNEW_ARGS(SkNoPixelsBitmapDevice,
586 (SkIRect::MakeWH(width, height))), kDefault_InitFlags) ->unref(); 586 (SkIRect::MakeWH(width, height), fProps)), kDefault_In itFlags)->unref();
587 } 587 }
588 588
589 SkCanvas::SkCanvas(const SkIRect& bounds, InitFlags flags) 589 SkCanvas::SkCanvas(const SkIRect& bounds, InitFlags flags)
590 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) 590 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
591 , fProps(SkSurfaceProps::kLegacyFontHost_InitType) 591 , fProps(SkSurfaceProps::kLegacyFontHost_InitType)
592 { 592 {
593 inc_canvas(); 593 inc_canvas();
594 594
595 this->init(SkNEW_ARGS(SkNoPixelsBitmapDevice, (bounds)), flags)->unref(); 595 this->init(SkNEW_ARGS(SkNoPixelsBitmapDevice, (bounds, fProps)), flags)->unr ef();
596 } 596 }
597 597
598 // TODO: remove this ctor
598 SkCanvas::SkCanvas(SkBaseDevice* device, const SkSurfaceProps* props, InitFlags flags) 599 SkCanvas::SkCanvas(SkBaseDevice* device, const SkSurfaceProps* props, InitFlags flags)
599 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) 600 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
600 , fProps(SkSurfacePropsCopyOrDefault(props)) 601 , fProps(SkSurfacePropsCopyOrDefault(props))
601 { 602 {
602 inc_canvas(); 603 inc_canvas();
603 604
604 this->init(device, flags); 605 this->init(device, flags);
605 } 606 }
606 607
607 SkCanvas::SkCanvas(SkBaseDevice* device) 608 SkCanvas::SkCanvas(SkBaseDevice* device)
608 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) 609 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
609 , fProps(SkSurfaceProps::kLegacyFontHost_InitType) 610 , fProps(device->getLeakyProperties())
610 { 611 {
611 inc_canvas(); 612 inc_canvas();
612 613
613 this->init(device, kDefault_InitFlags); 614 this->init(device, kDefault_InitFlags);
614 } 615 }
615 616
617 SkCanvas::SkCanvas(SkBaseDevice* device, InitFlags flags)
618 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
619 , fProps(device->getLeakyProperties())
620 {
621 inc_canvas();
622
623 this->init(device, flags);
624 }
625
616 SkCanvas::SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props) 626 SkCanvas::SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props)
617 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) 627 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
618 , fProps(props) 628 , fProps(props)
619 { 629 {
620 inc_canvas(); 630 inc_canvas();
621 631
622 SkAutoTUnref<SkBaseDevice> device(SkNEW_ARGS(SkBitmapDevice, (bitmap))); 632 SkAutoTUnref<SkBaseDevice> device(SkNEW_ARGS(SkBitmapDevice, (bitmap, fProps )));
623 this->init(device, kDefault_InitFlags); 633 this->init(device, kDefault_InitFlags);
624 } 634 }
625 635
626 SkCanvas::SkCanvas(const SkBitmap& bitmap) 636 SkCanvas::SkCanvas(const SkBitmap& bitmap)
627 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) 637 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
628 , fProps(SkSurfaceProps::kLegacyFontHost_InitType) 638 , fProps(SkSurfaceProps::kLegacyFontHost_InitType)
629 { 639 {
630 inc_canvas(); 640 inc_canvas();
631 641
632 SkAutoTUnref<SkBaseDevice> device(SkNEW_ARGS(SkBitmapDevice, (bitmap))); 642 SkAutoTUnref<SkBaseDevice> device(SkNEW_ARGS(SkBitmapDevice, (bitmap, fProps )));
633 this->init(device, kDefault_InitFlags); 643 this->init(device, kDefault_InitFlags);
634 } 644 }
635 645
636 SkCanvas::~SkCanvas() { 646 SkCanvas::~SkCanvas() {
637 // free up the contents of our deque 647 // free up the contents of our deque
638 this->restoreToCount(1); // restore everything but the last 648 this->restoreToCount(1); // restore everything but the last
639 649
640 this->internalRestore(); // restore the last, since we're going away 650 this->internalRestore(); // restore the last, since we're going away
641 651
642 SkDELETE(fMetaData); 652 SkDELETE(fMetaData);
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 return; 1042 return;
1033 } 1043 }
1034 1044
1035 bool forceSpriteOnRestore = false; 1045 bool forceSpriteOnRestore = false;
1036 { 1046 {
1037 const SkBaseDevice::TileUsage usage = SkBaseDevice::kNever_TileUsage; 1047 const SkBaseDevice::TileUsage usage = SkBaseDevice::kNever_TileUsage;
1038 const SkBaseDevice::CreateInfo createInfo = SkBaseDevice::CreateInfo(inf o, usage, geo); 1048 const SkBaseDevice::CreateInfo createInfo = SkBaseDevice::CreateInfo(inf o, usage, geo);
1039 SkBaseDevice* newDev = device->onCreateDevice(createInfo, paint); 1049 SkBaseDevice* newDev = device->onCreateDevice(createInfo, paint);
1040 if (NULL == newDev) { 1050 if (NULL == newDev) {
1041 // If onCreateDevice didn't succeed, try raster (e.g. PDF couldn't h andle the paint) 1051 // If onCreateDevice didn't succeed, try raster (e.g. PDF couldn't h andle the paint)
1042 const SkDeviceProperties deviceProps(createInfo.fPixelGeometry); 1052 const SkSurfaceProps surfaceProps(0, createInfo.fPixelGeometry);
1043 newDev = SkBitmapDevice::Create(createInfo.fInfo, &deviceProps); 1053 newDev = SkBitmapDevice::Create(createInfo.fInfo, &surfaceProps);
1044 if (NULL == newDev) { 1054 if (NULL == newDev) {
1045 SkErrorInternals::SetError(kInternalError_SkError, 1055 SkErrorInternals::SetError(kInternalError_SkError,
1046 "Unable to create device for layer.") ; 1056 "Unable to create device for layer.") ;
1047 return; 1057 return;
1048 } 1058 }
1049 forceSpriteOnRestore = true; 1059 forceSpriteOnRestore = true;
1050 } 1060 }
1051 device = newDev; 1061 device = newDev;
1052 } 1062 }
1053 1063
(...skipping 1658 matching lines...) Expand 10 before | Expand all | Expand 10 after
2712 } 2722 }
2713 2723
2714 if (matrix) { 2724 if (matrix) {
2715 canvas->concat(*matrix); 2725 canvas->concat(*matrix);
2716 } 2726 }
2717 } 2727 }
2718 2728
2719 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { 2729 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() {
2720 fCanvas->restoreToCount(fSaveCount); 2730 fCanvas->restoreToCount(fSaveCount);
2721 } 2731 }
OLDNEW
« no previous file with comments | « src/core/SkBitmapDevice.cpp ('k') | src/core/SkDevice.cpp » ('j') | src/gpu/SkGpuDevice.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698