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