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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 } | 63 } |
64 | 64 |
65 if (newAlphaType) { | 65 if (newAlphaType) { |
66 *newAlphaType = canonicalAlphaType; | 66 *newAlphaType = canonicalAlphaType; |
67 } | 67 } |
68 return true; | 68 return true; |
69 } | 69 } |
70 | 70 |
71 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap) | 71 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap) |
72 : INHERITED(SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)) | 72 : INHERITED(SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)) |
73 , fBitmap(bitmap) { | 73 , fBitmap(bitmap) |
| 74 { |
74 SkASSERT(valid_for_bitmap_device(bitmap.info(), nullptr)); | 75 SkASSERT(valid_for_bitmap_device(bitmap.info(), nullptr)); |
| 76 fBitmap.lockPixels(); |
75 } | 77 } |
76 | 78 |
77 SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& info) { | 79 SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& info) { |
78 return Create(info, SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)
); | 80 return Create(info, SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)
); |
79 } | 81 } |
80 | 82 |
81 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkSurfaceProps& sur
faceProps) | 83 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkSurfaceProps& sur
faceProps) |
82 : INHERITED(surfaceProps) | 84 : INHERITED(surfaceProps) |
83 , fBitmap(bitmap) { | 85 , fBitmap(bitmap) |
| 86 { |
84 SkASSERT(valid_for_bitmap_device(bitmap.info(), nullptr)); | 87 SkASSERT(valid_for_bitmap_device(bitmap.info(), nullptr)); |
| 88 fBitmap.lockPixels(); |
85 } | 89 } |
86 | 90 |
87 SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& origInfo, | 91 SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& origInfo, |
88 const SkSurfaceProps& surfaceProps) { | 92 const SkSurfaceProps& surfaceProps) { |
89 SkAlphaType newAT = origInfo.alphaType(); | 93 SkAlphaType newAT = origInfo.alphaType(); |
90 if (!valid_for_bitmap_device(origInfo, &newAT)) { | 94 if (!valid_for_bitmap_device(origInfo, &newAT)) { |
91 return nullptr; | 95 return nullptr; |
92 } | 96 } |
93 | 97 |
94 const SkImageInfo info = origInfo.makeAlphaType(newAT); | 98 const SkImageInfo info = origInfo.makeAlphaType(newAT); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 return true; | 180 return true; |
177 } | 181 } |
178 return false; | 182 return false; |
179 } | 183 } |
180 | 184 |
181 bool SkBitmapDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, s
ize_t dstRowBytes, | 185 bool SkBitmapDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, s
ize_t dstRowBytes, |
182 int x, int y) { | 186 int x, int y) { |
183 return fBitmap.readPixels(dstInfo, dstPixels, dstRowBytes, x, y); | 187 return fBitmap.readPixels(dstInfo, dstPixels, dstRowBytes, x, y); |
184 } | 188 } |
185 | 189 |
186 void SkBitmapDevice::onAttachToCanvas(SkCanvas* canvas) { | |
187 INHERITED::onAttachToCanvas(canvas); | |
188 fBitmap.lockPixels(); | |
189 } | |
190 | |
191 void SkBitmapDevice::onDetachFromCanvas() { | |
192 INHERITED::onDetachFromCanvas(); | |
193 fBitmap.unlockPixels(); | |
194 } | |
195 | |
196 /////////////////////////////////////////////////////////////////////////////// | 190 /////////////////////////////////////////////////////////////////////////////// |
197 | 191 |
198 void SkBitmapDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { | 192 void SkBitmapDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { |
199 draw.drawPaint(paint); | 193 draw.drawPaint(paint); |
200 } | 194 } |
201 | 195 |
202 void SkBitmapDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, si
ze_t count, | 196 void SkBitmapDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, si
ze_t count, |
203 const SkPoint pts[], const SkPaint& paint) { | 197 const SkPoint pts[], const SkPaint& paint) { |
204 draw.drawPoints(mode, count, pts, paint); | 198 draw.drawPoints(mode, count, pts, paint); |
205 } | 199 } |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 paint.getRasterizer() || | 422 paint.getRasterizer() || |
429 paint.getPathEffect() || | 423 paint.getPathEffect() || |
430 paint.isFakeBoldText() || | 424 paint.isFakeBoldText() || |
431 paint.getStyle() != SkPaint::kFill_Style || | 425 paint.getStyle() != SkPaint::kFill_Style || |
432 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) | 426 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) |
433 { | 427 { |
434 return true; | 428 return true; |
435 } | 429 } |
436 return false; | 430 return false; |
437 } | 431 } |
OLD | NEW |