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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 default: | 51 default: |
52 return false; | 52 return false; |
53 } | 53 } |
54 | 54 |
55 if (newAlphaType) { | 55 if (newAlphaType) { |
56 *newAlphaType = canonicalAlphaType; | 56 *newAlphaType = canonicalAlphaType; |
57 } | 57 } |
58 return true; | 58 return true; |
59 } | 59 } |
60 | 60 |
61 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap) : fBitmap(bitmap) { | 61 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap) |
| 62 : INHERITED(SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)) |
| 63 , fBitmap(bitmap) { |
62 SkASSERT(valid_for_bitmap_device(bitmap.info(), NULL)); | 64 SkASSERT(valid_for_bitmap_device(bitmap.info(), NULL)); |
63 } | 65 } |
64 | 66 |
| 67 SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& info) { |
| 68 return Create(info, SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)
); |
| 69 } |
| 70 |
65 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkSurfaceProps& sur
faceProps) | 71 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkSurfaceProps& sur
faceProps) |
66 : SkBaseDevice(surfaceProps) | 72 : INHERITED(surfaceProps) |
67 , fBitmap(bitmap) | 73 , fBitmap(bitmap) { |
68 { | |
69 SkASSERT(valid_for_bitmap_device(bitmap.info(), NULL)); | 74 SkASSERT(valid_for_bitmap_device(bitmap.info(), NULL)); |
70 } | 75 } |
71 | 76 |
72 SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& origInfo, | 77 SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& origInfo, |
73 const SkSurfaceProps* surfaceProps) { | 78 const SkSurfaceProps& surfaceProps) { |
74 SkAlphaType newAT = origInfo.alphaType(); | 79 SkAlphaType newAT = origInfo.alphaType(); |
75 if (!valid_for_bitmap_device(origInfo, &newAT)) { | 80 if (!valid_for_bitmap_device(origInfo, &newAT)) { |
76 return NULL; | 81 return NULL; |
77 } | 82 } |
78 | 83 |
79 const SkImageInfo info = origInfo.makeAlphaType(newAT); | 84 const SkImageInfo info = origInfo.makeAlphaType(newAT); |
80 SkBitmap bitmap; | 85 SkBitmap bitmap; |
81 | 86 |
82 if (kUnknown_SkColorType == info.colorType()) { | 87 if (kUnknown_SkColorType == info.colorType()) { |
83 if (!bitmap.setInfo(info)) { | 88 if (!bitmap.setInfo(info)) { |
84 return NULL; | 89 return NULL; |
85 } | 90 } |
86 } else { | 91 } else { |
87 if (!bitmap.tryAllocPixels(info)) { | 92 if (!bitmap.tryAllocPixels(info)) { |
88 return NULL; | 93 return NULL; |
89 } | 94 } |
90 if (!bitmap.info().isOpaque()) { | 95 if (!bitmap.info().isOpaque()) { |
91 bitmap.eraseColor(SK_ColorTRANSPARENT); | 96 bitmap.eraseColor(SK_ColorTRANSPARENT); |
92 } | 97 } |
93 } | 98 } |
94 | 99 |
95 if (surfaceProps) { | 100 return SkNEW_ARGS(SkBitmapDevice, (bitmap, surfaceProps)); |
96 return SkNEW_ARGS(SkBitmapDevice, (bitmap, *surfaceProps)); | |
97 } else { | |
98 return SkNEW_ARGS(SkBitmapDevice, (bitmap)); | |
99 } | |
100 } | 101 } |
101 | 102 |
102 SkImageInfo SkBitmapDevice::imageInfo() const { | 103 SkImageInfo SkBitmapDevice::imageInfo() const { |
103 return fBitmap.info(); | 104 return fBitmap.info(); |
104 } | 105 } |
105 | 106 |
106 void SkBitmapDevice::setNewSize(const SkISize& size) { | 107 void SkBitmapDevice::setNewSize(const SkISize& size) { |
107 SkASSERT(!fBitmap.pixelRef()); | 108 SkASSERT(!fBitmap.pixelRef()); |
108 fBitmap.setInfo(fBitmap.info().makeWH(size.fWidth, size.fHeight)); | 109 fBitmap.setInfo(fBitmap.info().makeWH(size.fWidth, size.fHeight)); |
109 } | 110 } |
110 | 111 |
111 void SkBitmapDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) { | 112 void SkBitmapDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) { |
112 SkASSERT(bm.width() == fBitmap.width()); | 113 SkASSERT(bm.width() == fBitmap.width()); |
113 SkASSERT(bm.height() == fBitmap.height()); | 114 SkASSERT(bm.height() == fBitmap.height()); |
114 fBitmap = bm; // intent is to use bm's pixelRef (and rowbytes/config) | 115 fBitmap = bm; // intent is to use bm's pixelRef (and rowbytes/config) |
115 fBitmap.lockPixels(); | 116 fBitmap.lockPixels(); |
116 } | 117 } |
117 | 118 |
118 SkBaseDevice* SkBitmapDevice::onCreateDevice(const CreateInfo& cinfo, const SkPa
int*) { | 119 SkBaseDevice* SkBitmapDevice::onCreateDevice(const CreateInfo& cinfo, const SkPa
int*) { |
119 const SkSurfaceProps surfaceProps(0, cinfo.fPixelGeometry); | 120 const SkSurfaceProps surfaceProps(this->surfaceProps().flags(), cinfo.fPixel
Geometry); |
120 return SkBitmapDevice::Create(cinfo.fInfo, &surfaceProps); | 121 return SkBitmapDevice::Create(cinfo.fInfo, surfaceProps); |
121 } | 122 } |
122 | 123 |
123 const SkBitmap& SkBitmapDevice::onAccessBitmap() { | 124 const SkBitmap& SkBitmapDevice::onAccessBitmap() { |
124 return fBitmap; | 125 return fBitmap; |
125 } | 126 } |
126 | 127 |
127 bool SkBitmapDevice::onAccessPixels(SkPixmap* pmap) { | 128 bool SkBitmapDevice::onAccessPixels(SkPixmap* pmap) { |
128 if (fBitmap.lockPixelsAreWritable() && this->onPeekPixels(pmap)) { | 129 if (fBitmap.lockPixelsAreWritable() && this->onPeekPixels(pmap)) { |
129 fBitmap.notifyPixelsChanged(); | 130 fBitmap.notifyPixelsChanged(); |
130 return true; | 131 return true; |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 paint.getRasterizer() || | 375 paint.getRasterizer() || |
375 paint.getPathEffect() || | 376 paint.getPathEffect() || |
376 paint.isFakeBoldText() || | 377 paint.isFakeBoldText() || |
377 paint.getStyle() != SkPaint::kFill_Style || | 378 paint.getStyle() != SkPaint::kFill_Style || |
378 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) | 379 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) |
379 { | 380 { |
380 return true; | 381 return true; |
381 } | 382 } |
382 return false; | 383 return false; |
383 } | 384 } |
OLD | NEW |