OLD | NEW |
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" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 if (newAlphaType) { | 54 if (newAlphaType) { |
55 *newAlphaType = canonicalAlphaType; | 55 *newAlphaType = canonicalAlphaType; |
56 } | 56 } |
57 return true; | 57 return true; |
58 } | 58 } |
59 | 59 |
60 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap) : fBitmap(bitmap) { | 60 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap) : fBitmap(bitmap) { |
61 SkASSERT(valid_for_bitmap_device(bitmap.info(), NULL)); | 61 SkASSERT(valid_for_bitmap_device(bitmap.info(), NULL)); |
62 } | 62 } |
63 | 63 |
| 64 #if 0 |
64 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkDeviceProperties&
deviceProperties) | 65 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkDeviceProperties&
deviceProperties) |
65 : SkBaseDevice(deviceProperties) | 66 : SkBaseDevice(deviceProperties) |
66 , fBitmap(bitmap) | 67 , fBitmap(bitmap) |
67 { | 68 { |
68 SkASSERT(valid_for_bitmap_device(bitmap.info(), NULL)); | 69 SkASSERT(valid_for_bitmap_device(bitmap.info(), NULL)); |
69 } | 70 } |
| 71 #endif |
70 | 72 |
71 SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& origInfo, | 73 SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& origInfo, |
72 const SkDeviceProperties* props) { | 74 const SkDeviceProperties* props) { |
73 SkAlphaType newAT = origInfo.alphaType(); | 75 SkAlphaType newAT = origInfo.alphaType(); |
74 if (!valid_for_bitmap_device(origInfo, &newAT)) { | 76 if (!valid_for_bitmap_device(origInfo, &newAT)) { |
75 return NULL; | 77 return NULL; |
76 } | 78 } |
77 | 79 |
78 const SkImageInfo info = origInfo.makeAlphaType(newAT); | 80 const SkImageInfo info = origInfo.makeAlphaType(newAT); |
79 SkBitmap bitmap; | 81 SkBitmap bitmap; |
80 | 82 |
81 if (kUnknown_SkColorType == info.colorType()) { | 83 if (kUnknown_SkColorType == info.colorType()) { |
82 if (!bitmap.setInfo(info)) { | 84 if (!bitmap.setInfo(info)) { |
83 return NULL; | 85 return NULL; |
84 } | 86 } |
85 } else { | 87 } else { |
86 if (!bitmap.tryAllocPixels(info)) { | 88 if (!bitmap.tryAllocPixels(info)) { |
87 return NULL; | 89 return NULL; |
88 } | 90 } |
89 if (!bitmap.info().isOpaque()) { | 91 if (!bitmap.info().isOpaque()) { |
90 bitmap.eraseColor(SK_ColorTRANSPARENT); | 92 bitmap.eraseColor(SK_ColorTRANSPARENT); |
91 } | 93 } |
92 } | 94 } |
93 | 95 |
94 if (props) { | 96 if (props && false) { |
95 return SkNEW_ARGS(SkBitmapDevice, (bitmap, *props)); | 97 // return SkNEW_ARGS(SkBitmapDevice, (bitmap, *props)); |
96 } else { | 98 } else { |
97 return SkNEW_ARGS(SkBitmapDevice, (bitmap)); | 99 return SkNEW_ARGS(SkBitmapDevice, (bitmap)); |
98 } | 100 } |
99 } | 101 } |
100 | 102 |
101 SkImageInfo SkBitmapDevice::imageInfo() const { | 103 SkImageInfo SkBitmapDevice::imageInfo() const { |
102 return fBitmap.info(); | 104 return fBitmap.info(); |
103 } | 105 } |
104 | 106 |
105 void SkBitmapDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) { | 107 void SkBitmapDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) { |
106 SkASSERT(bm.width() == fBitmap.width()); | 108 SkASSERT(bm.width() == fBitmap.width()); |
107 SkASSERT(bm.height() == fBitmap.height()); | 109 SkASSERT(bm.height() == fBitmap.height()); |
108 fBitmap = bm; // intent is to use bm's pixelRef (and rowbytes/config) | 110 fBitmap = bm; // intent is to use bm's pixelRef (and rowbytes/config) |
109 fBitmap.lockPixels(); | 111 fBitmap.lockPixels(); |
110 } | 112 } |
111 | 113 |
112 SkBaseDevice* SkBitmapDevice::onCreateDevice(const SkImageInfo& info, Usage usag
e) { | 114 SkBaseDevice* SkBitmapDevice::onCreateDevice(const SkImageInfo& info, Usage usag
e) { |
113 return SkBitmapDevice::Create(info, &this->getDeviceProperties()); | 115 return SkBitmapDevice::Create(info);// &this->getDeviceProperties()); |
114 } | 116 } |
115 | 117 |
116 void SkBitmapDevice::lockPixels() { | 118 void SkBitmapDevice::lockPixels() { |
117 if (fBitmap.lockPixelsAreWritable()) { | 119 if (fBitmap.lockPixelsAreWritable()) { |
118 fBitmap.lockPixels(); | 120 fBitmap.lockPixels(); |
119 } | 121 } |
120 } | 122 } |
121 | 123 |
122 void SkBitmapDevice::unlockPixels() { | 124 void SkBitmapDevice::unlockPixels() { |
123 if (fBitmap.lockPixelsAreWritable()) { | 125 if (fBitmap.lockPixelsAreWritable()) { |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 paint.getStyle() != SkPaint::kFill_Style || | 389 paint.getStyle() != SkPaint::kFill_Style || |
388 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) { | 390 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) { |
389 // turn off lcd, but turn on kGenA8 | 391 // turn off lcd, but turn on kGenA8 |
390 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag; | 392 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag; |
391 flags->fFlags |= SkPaint::kGenA8FromLCD_Flag; | 393 flags->fFlags |= SkPaint::kGenA8FromLCD_Flag; |
392 return true; | 394 return true; |
393 } | 395 } |
394 // we're cool with the paint as is | 396 // we're cool with the paint as is |
395 return false; | 397 return false; |
396 } | 398 } |
OLD | NEW |