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" |
11 #include "SkMallocPixelRef.h" | 11 #include "SkMallocPixelRef.h" |
12 #include "SkMatrix.h" | 12 #include "SkMatrix.h" |
13 #include "SkPaint.h" | 13 #include "SkPaint.h" |
14 #include "SkPath.h" | 14 #include "SkPath.h" |
15 #include "SkPixelRef.h" | 15 #include "SkPixelRef.h" |
16 #include "SkPixmap.h" | 16 #include "SkPixmap.h" |
| 17 #include "SkRasterCanvasLayerAllocator.h" |
17 #include "SkShader.h" | 18 #include "SkShader.h" |
18 #include "SkSurface.h" | 19 #include "SkSurface.h" |
19 #include "SkXfermode.h" | 20 #include "SkXfermode.h" |
20 | 21 |
21 class SkColorTable; | 22 class SkColorTable; |
22 | 23 |
23 static bool valid_for_bitmap_device(const SkImageInfo& info, | 24 static bool valid_for_bitmap_device(const SkImageInfo& info, |
24 SkAlphaType* newAlphaType) { | 25 SkAlphaType* newAlphaType) { |
25 if (info.width() < 0 || info.height() < 0) { | 26 if (info.width() < 0 || info.height() < 0) { |
26 return false; | 27 return false; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 fBitmap.setInfo(fBitmap.info().makeWH(size.fWidth, size.fHeight)); | 122 fBitmap.setInfo(fBitmap.info().makeWH(size.fWidth, size.fHeight)); |
122 } | 123 } |
123 | 124 |
124 void SkBitmapDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) { | 125 void SkBitmapDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) { |
125 SkASSERT(bm.width() == fBitmap.width()); | 126 SkASSERT(bm.width() == fBitmap.width()); |
126 SkASSERT(bm.height() == fBitmap.height()); | 127 SkASSERT(bm.height() == fBitmap.height()); |
127 fBitmap = bm; // intent is to use bm's pixelRef (and rowbytes/config) | 128 fBitmap = bm; // intent is to use bm's pixelRef (and rowbytes/config) |
128 fBitmap.lockPixels(); | 129 fBitmap.lockPixels(); |
129 } | 130 } |
130 | 131 |
131 SkBaseDevice* SkBitmapDevice::onCreateDevice(const CreateInfo& cinfo, const SkPa
int*) { | 132 SkBaseDevice* SkBitmapDevice::onCreateDevice(const CreateInfo& cinfo, const SkPa
int*, |
| 133 SkRasterCanvasLayerAllocator* alloc
) { |
132 const SkSurfaceProps surfaceProps(this->surfaceProps().flags(), cinfo.fPixel
Geometry); | 134 const SkSurfaceProps surfaceProps(this->surfaceProps().flags(), cinfo.fPixel
Geometry); |
133 return SkBitmapDevice::Create(cinfo.fInfo, surfaceProps); | 135 SkBitmapDevice* dev = nullptr; |
| 136 if (alloc) { |
| 137 SkBitmap bitmap; |
| 138 size_t rowBytes; |
| 139 void* layer = alloc->allocateLayer(cinfo.fInfo, &rowBytes); |
| 140 if (layer && |
| 141 bitmap.installPixels(cinfo.fInfo, layer, rowBytes)) { |
| 142 dev = new SkBitmapDevice(bitmap); |
| 143 } |
| 144 } else { |
| 145 dev = SkBitmapDevice::Create(cinfo.fInfo, surfaceProps); |
| 146 } |
| 147 return dev; |
134 } | 148 } |
135 | 149 |
136 const SkBitmap& SkBitmapDevice::onAccessBitmap() { | 150 const SkBitmap& SkBitmapDevice::onAccessBitmap() { |
137 return fBitmap; | 151 return fBitmap; |
138 } | 152 } |
139 | 153 |
140 bool SkBitmapDevice::onAccessPixels(SkPixmap* pmap) { | 154 bool SkBitmapDevice::onAccessPixels(SkPixmap* pmap) { |
141 if (fBitmap.lockPixelsAreWritable() && this->onPeekPixels(pmap)) { | 155 if (fBitmap.lockPixelsAreWritable() && this->onPeekPixels(pmap)) { |
142 fBitmap.notifyPixelsChanged(); | 156 fBitmap.notifyPixelsChanged(); |
143 return true; | 157 return true; |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 paint.getRasterizer() || | 391 paint.getRasterizer() || |
378 paint.getPathEffect() || | 392 paint.getPathEffect() || |
379 paint.isFakeBoldText() || | 393 paint.isFakeBoldText() || |
380 paint.getStyle() != SkPaint::kFill_Style || | 394 paint.getStyle() != SkPaint::kFill_Style || |
381 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) | 395 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) |
382 { | 396 { |
383 return true; | 397 return true; |
384 } | 398 } |
385 return false; | 399 return false; |
386 } | 400 } |
OLD | NEW |