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

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

Issue 926843003: Move canvas->surface association to the device subclasses (Closed) Base URL: https://skia.googlesource.com/skia.git@skimage-filters-03-sksurface-set-root-device-simple
Patch Set: Created 5 years, 10 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 | « include/core/SkDevice.h ('k') | src/core/SkCanvas.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 2013 Google Inc. 2 * Copyright 2013 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 "SkBitmapDevice.h" 8 #include "SkBitmapDevice.h"
9 #include "SkConfig8888.h" 9 #include "SkConfig8888.h"
10 #include "SkDeviceProperties.h" 10 #include "SkDeviceProperties.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 SkASSERT(valid_for_bitmap_device(bitmap.info(), NULL)); 62 SkASSERT(valid_for_bitmap_device(bitmap.info(), NULL));
63 } 63 }
64 64
65 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkDeviceProperties& deviceProperties) 65 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkDeviceProperties& deviceProperties)
66 : SkBaseDevice(deviceProperties) 66 : SkBaseDevice(deviceProperties)
67 , fBitmap(bitmap) 67 , fBitmap(bitmap)
68 { 68 {
69 SkASSERT(valid_for_bitmap_device(bitmap.info(), NULL)); 69 SkASSERT(valid_for_bitmap_device(bitmap.info(), NULL));
70 } 70 }
71 71
72 SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& origInfo, 72 bool SkBitmapDevice::CreateBackendBitmap(const SkImageInfo& origInfo, SkBitmap* target) {
73 const SkDeviceProperties* props) {
74 SkAlphaType newAT = origInfo.alphaType(); 73 SkAlphaType newAT = origInfo.alphaType();
75 if (!valid_for_bitmap_device(origInfo, &newAT)) { 74 if (!valid_for_bitmap_device(origInfo, &newAT)) {
76 return NULL; 75 return false;
77 } 76 }
78 77
79 const SkImageInfo info = origInfo.makeAlphaType(newAT); 78 const SkImageInfo info = origInfo.makeAlphaType(newAT);
80 SkBitmap bitmap; 79 SkBitmap bitmap;
81 80
82 if (kUnknown_SkColorType == info.colorType()) { 81 if (kUnknown_SkColorType == info.colorType()) {
83 if (!bitmap.setInfo(info)) { 82 if (!bitmap.setInfo(info)) {
84 return NULL; 83 return false;
85 } 84 }
86 } else { 85 } else {
87 if (!bitmap.tryAllocPixels(info)) { 86 if (!bitmap.tryAllocPixels(info)) {
88 return NULL; 87 return false;
89 } 88 }
90 if (!bitmap.info().isOpaque()) { 89 if (!bitmap.info().isOpaque()) {
91 bitmap.eraseColor(SK_ColorTRANSPARENT); 90 bitmap.eraseColor(SK_ColorTRANSPARENT);
92 } 91 }
93 } 92 }
93 target->swap(bitmap);
94 return true;
95 }
94 96
97 SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& info,
98 const SkDeviceProperties* props) {
99 SkBitmap bitmap;
100 if (!CreateBackendBitmap(info, &bitmap)) {
101 return NULL;
102 }
95 if (props) { 103 if (props) {
96 return SkNEW_ARGS(SkBitmapDevice, (bitmap, *props)); 104 return SkNEW_ARGS(SkBitmapDevice, (bitmap, *props));
97 } else { 105 } else {
98 return SkNEW_ARGS(SkBitmapDevice, (bitmap)); 106 return SkNEW_ARGS(SkBitmapDevice, (bitmap));
99 } 107 }
100 } 108 }
101 109
102 SkImageInfo SkBitmapDevice::imageInfo() const { 110 SkImageInfo SkBitmapDevice::imageInfo() const {
103 return fBitmap.info(); 111 return fBitmap.info();
104 } 112 }
105 113
106 void SkBitmapDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) { 114 void SkBitmapDevice::replaceBitmapBackend(const SkBitmap& bm) {
107 SkASSERT(bm.width() == fBitmap.width()); 115 SkASSERT(bm.width() == fBitmap.width());
108 SkASSERT(bm.height() == fBitmap.height()); 116 SkASSERT(bm.height() == fBitmap.height());
109 fBitmap = bm; // intent is to use bm's pixelRef (and rowbytes/config) 117 fBitmap = bm; // intent is to use bm's pixelRef (and rowbytes/config)
110 fBitmap.lockPixels(); 118 fBitmap.lockPixels();
111 } 119 }
112 120
113 SkBaseDevice* SkBitmapDevice::onCreateCompatibleDevice(const CreateInfo& cinfo) { 121 SkBaseDevice* SkBitmapDevice::onCreateCompatibleDevice(const CreateInfo& cinfo) {
114 SkDeviceProperties leaky(cinfo.fPixelGeometry); 122 SkDeviceProperties leaky(cinfo.fPixelGeometry);
115 return SkBitmapDevice::Create(cinfo.fInfo, &leaky); 123 return SkBitmapDevice::Create(cinfo.fInfo, &leaky);
116 } 124 }
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 paint.getRasterizer() || 391 paint.getRasterizer() ||
384 paint.getPathEffect() || 392 paint.getPathEffect() ||
385 paint.isFakeBoldText() || 393 paint.isFakeBoldText() ||
386 paint.getStyle() != SkPaint::kFill_Style || 394 paint.getStyle() != SkPaint::kFill_Style ||
387 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) 395 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode))
388 { 396 {
389 return true; 397 return true;
390 } 398 }
391 return false; 399 return false;
392 } 400 }
OLDNEW
« no previous file with comments | « include/core/SkDevice.h ('k') | src/core/SkCanvas.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698