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

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

Issue 168653002: Change device factories to take SkImageInfo instead of SkBitmap::Config (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: fix PdfViewer Created 6 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 | Annotate | Revision Log
« no previous file with comments | « include/pdf/SkPDFDevice.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 "SkDraw.h" 10 #include "SkDraw.h"
11 #include "SkRasterClip.h" 11 #include "SkRasterClip.h"
12 #include "SkShader.h" 12 #include "SkShader.h"
13 #include "SkSurface.h" 13 #include "SkSurface.h"
14 14
15 #define CHECK_FOR_ANNOTATION(paint) \ 15 #define CHECK_FOR_ANNOTATION(paint) \
16 do { if (paint.getAnnotation()) { return; } } while (0) 16 do { if (paint.getAnnotation()) { return; } } while (0)
17 17
18 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap) 18 static bool valid_for_bitmap_device(const SkImageInfo& info,
19 : fBitmap(bitmap) { 19 SkAlphaType* newAlphaType) {
20 SkASSERT(SkBitmap::kARGB_4444_Config != bitmap.config()); 20 if (info.width() < 0 || info.height() < 0) {
21 return false;
22 }
23
24 // TODO: can we stop supporting kUnknown in SkBitmkapDevice?
25 if (kUnknown_SkColorType == info.colorType()) {
26 if (newAlphaType) {
27 *newAlphaType = kIgnore_SkAlphaType;
28 }
29 return true;
30 }
31
32 switch (info.alphaType()) {
33 case kPremul_SkAlphaType:
34 case kOpaque_SkAlphaType:
35 break;
36 default:
37 return false;
38 }
39
40 SkAlphaType canonicalAlphaType = info.alphaType();
41
42 switch (info.colorType()) {
43 case kAlpha_8_SkColorType:
44 break;
45 case kRGB_565_SkColorType:
46 canonicalAlphaType = kOpaque_SkAlphaType;
47 break;
48 case kPMColor_SkColorType:
49 break;
50 default:
51 return false;
52 }
53
54 if (newAlphaType) {
55 *newAlphaType = canonicalAlphaType;
56 }
57 return true;
58 }
59
60 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap) : fBitmap(bitmap) {
61 SkASSERT(valid_for_bitmap_device(bitmap.info(), NULL));
21 } 62 }
22 63
23 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkDeviceProperties& deviceProperties) 64 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkDeviceProperties& deviceProperties)
24 : SkBaseDevice(deviceProperties) 65 : SkBaseDevice(deviceProperties)
25 , fBitmap(bitmap) { 66 , fBitmap(bitmap)
67 {
68 SkASSERT(valid_for_bitmap_device(bitmap.info(), NULL));
26 } 69 }
27 70
71 #ifdef SK_SUPPORT_LEGACY_COMPATIBLEDEVICE_CONFIG
28 void SkBitmapDevice::init(SkBitmap::Config config, int width, int height, bool i sOpaque) { 72 void SkBitmapDevice::init(SkBitmap::Config config, int width, int height, bool i sOpaque) {
29 fBitmap.setConfig(config, width, height, 0, isOpaque ? 73 fBitmap.setConfig(config, width, height, 0, isOpaque ?
30 kOpaque_SkAlphaType : kPremul_SkAlphaType); 74 kOpaque_SkAlphaType : kPremul_SkAlphaType);
31 75
32 if (SkBitmap::kNo_Config != config) { 76 if (SkBitmap::kNo_Config != config) {
33 if (!fBitmap.allocPixels()) { 77 if (!fBitmap.allocPixels()) {
34 // indicate failure by zeroing our bitmap 78 // indicate failure by zeroing our bitmap
35 fBitmap.setConfig(config, 0, 0, 0, isOpaque ? 79 fBitmap.setConfig(config, 0, 0, 0, isOpaque ?
36 kOpaque_SkAlphaType : kPremul_SkAlphaType); 80 kOpaque_SkAlphaType : kPremul_SkAlphaType);
37 } else if (!isOpaque) { 81 } else if (!isOpaque) {
38 fBitmap.eraseColor(SK_ColorTRANSPARENT); 82 fBitmap.eraseColor(SK_ColorTRANSPARENT);
39 } 83 }
40 } 84 }
41 } 85 }
42 86
43 SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, b ool isOpaque) { 87 SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, b ool isOpaque) {
44 this->init(config, width, height, isOpaque); 88 this->init(config, width, height, isOpaque);
45 } 89 }
46 90
47 SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, b ool isOpaque, 91 SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, b ool isOpaque,
48 const SkDeviceProperties& deviceProperties) 92 const SkDeviceProperties& deviceProperties)
49 : SkBaseDevice(deviceProperties) 93 : SkBaseDevice(deviceProperties)
50 { 94 {
51 this->init(config, width, height, isOpaque); 95 this->init(config, width, height, isOpaque);
52 } 96 }
97 #endif
98 SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& origInfo,
99 const SkDeviceProperties* props) {
100 SkImageInfo info = origInfo;
101 if (!valid_for_bitmap_device(info, &info.fAlphaType)) {
102 return NULL;
103 }
53 104
54 SkBitmapDevice::~SkBitmapDevice() { 105 SkBitmap bitmap;
106
107 if (kUnknown_SkColorType == info.colorType()) {
108 if (!bitmap.setConfig(info)) {
109 return NULL;
110 }
111 } else {
112 if (!bitmap.allocPixels(info)) {
113 return NULL;
114 }
115 if (!bitmap.info().isOpaque()) {
116 bitmap.eraseColor(SK_ColorTRANSPARENT);
117 }
118 }
119
120 if (props) {
121 return SkNEW_ARGS(SkBitmapDevice, (bitmap, *props));
122 } else {
123 return SkNEW_ARGS(SkBitmapDevice, (bitmap));
124 }
55 } 125 }
56 126
57 SkImageInfo SkBitmapDevice::imageInfo() const { 127 SkImageInfo SkBitmapDevice::imageInfo() const {
58 return fBitmap.info(); 128 return fBitmap.info();
59 } 129 }
60 130
61 void SkBitmapDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) { 131 void SkBitmapDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) {
62 SkASSERT(bm.width() == fBitmap.width()); 132 SkASSERT(bm.width() == fBitmap.width());
63 SkASSERT(bm.height() == fBitmap.height()); 133 SkASSERT(bm.height() == fBitmap.height());
64 fBitmap = bm; // intent is to use bm's pixelRef (and rowbytes/config) 134 fBitmap = bm; // intent is to use bm's pixelRef (and rowbytes/config)
65 fBitmap.lockPixels(); 135 fBitmap.lockPixels();
66 } 136 }
67 137
68 SkBaseDevice* SkBitmapDevice::onCreateCompatibleDevice(SkBitmap::Config config, 138 SkBaseDevice* SkBitmapDevice::onCreateDevice(const SkImageInfo& info, Usage usag e) {
69 int width, int height, 139 return SkBitmapDevice::Create(info, &this->getDeviceProperties());
70 bool isOpaque,
71 Usage usage) {
72 SkBitmapDevice* device = SkNEW_ARGS(SkBitmapDevice,(config, width, height,
73 isOpaque, this->getDeviceProperties()));
74 // Check if allocation failed and delete device if it did fail
75 if ((device->width() != width) || (device->height() != height)) {
76 SkDELETE(device);
77 device = NULL;
78 }
79 return device;
80 } 140 }
81 141
82 void SkBitmapDevice::lockPixels() { 142 void SkBitmapDevice::lockPixels() {
83 if (fBitmap.lockPixelsAreWritable()) { 143 if (fBitmap.lockPixelsAreWritable()) {
84 fBitmap.lockPixels(); 144 fBitmap.lockPixels();
85 } 145 }
86 } 146 }
87 147
88 void SkBitmapDevice::unlockPixels() { 148 void SkBitmapDevice::unlockPixels() {
89 if (fBitmap.lockPixelsAreWritable()) { 149 if (fBitmap.lockPixelsAreWritable()) {
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 paint.getStyle() != SkPaint::kFill_Style || 475 paint.getStyle() != SkPaint::kFill_Style ||
416 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) { 476 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) {
417 // turn off lcd 477 // turn off lcd
418 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag; 478 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag;
419 flags->fHinting = paint.getHinting(); 479 flags->fHinting = paint.getHinting();
420 return true; 480 return true;
421 } 481 }
422 // we're cool with the paint as is 482 // we're cool with the paint as is
423 return false; 483 return false;
424 } 484 }
OLDNEW
« no previous file with comments | « include/pdf/SkPDFDevice.h ('k') | src/core/SkCanvas.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698