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" |
10 #include "SkDraw.h" | 11 #include "SkDraw.h" |
11 #include "SkRasterClip.h" | 12 #include "SkRasterClip.h" |
12 #include "SkShader.h" | 13 #include "SkShader.h" |
13 #include "SkSurface.h" | 14 #include "SkSurface.h" |
14 | 15 |
15 #define CHECK_FOR_ANNOTATION(paint) \ | 16 #define CHECK_FOR_ANNOTATION(paint) \ |
16 do { if (paint.getAnnotation()) { return; } } while (0) | 17 do { if (paint.getAnnotation()) { return; } } while (0) |
17 | 18 |
18 static bool valid_for_bitmap_device(const SkImageInfo& info, | 19 static bool valid_for_bitmap_device(const SkImageInfo& info, |
19 SkAlphaType* newAlphaType) { | 20 SkAlphaType* newAlphaType) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 if (newAlphaType) { | 55 if (newAlphaType) { |
55 *newAlphaType = canonicalAlphaType; | 56 *newAlphaType = canonicalAlphaType; |
56 } | 57 } |
57 return true; | 58 return true; |
58 } | 59 } |
59 | 60 |
60 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap) : fBitmap(bitmap) { | 61 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap) : fBitmap(bitmap) { |
61 SkASSERT(valid_for_bitmap_device(bitmap.info(), NULL)); | 62 SkASSERT(valid_for_bitmap_device(bitmap.info(), NULL)); |
62 } | 63 } |
63 | 64 |
64 #if 0 | |
65 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkDeviceProperties&
deviceProperties) | 65 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkDeviceProperties&
deviceProperties) |
66 : SkBaseDevice(deviceProperties) | 66 : SkBaseDevice(deviceProperties) |
67 , fBitmap(bitmap) | 67 , fBitmap(bitmap) |
68 { | 68 { |
69 SkASSERT(valid_for_bitmap_device(bitmap.info(), NULL)); | 69 SkASSERT(valid_for_bitmap_device(bitmap.info(), NULL)); |
70 } | 70 } |
71 #endif | |
72 | 71 |
73 SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& origInfo, | 72 SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& origInfo, |
74 const SkDeviceProperties* props) { | 73 const SkDeviceProperties* props) { |
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 && false) { | 95 if (props) { |
97 // return SkNEW_ARGS(SkBitmapDevice, (bitmap, *props)); | 96 return SkNEW_ARGS(SkBitmapDevice, (bitmap, *props)); |
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::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) { | 106 void SkBitmapDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) { |
108 SkASSERT(bm.width() == fBitmap.width()); | 107 SkASSERT(bm.width() == fBitmap.width()); |
109 SkASSERT(bm.height() == fBitmap.height()); | 108 SkASSERT(bm.height() == fBitmap.height()); |
110 fBitmap = bm; // intent is to use bm's pixelRef (and rowbytes/config) | 109 fBitmap = bm; // intent is to use bm's pixelRef (and rowbytes/config) |
111 fBitmap.lockPixels(); | 110 fBitmap.lockPixels(); |
112 } | 111 } |
113 | 112 |
114 SkBaseDevice* SkBitmapDevice::onCreateCompatibleDevice(const CreateInfo& cinfo)
{ | 113 SkBaseDevice* SkBitmapDevice::onCreateCompatibleDevice(const CreateInfo& cinfo)
{ |
115 return SkBitmapDevice::Create(cinfo.fInfo);// &this->getDeviceProperties()); | 114 SkDeviceProperties leaky(cinfo.fPixelGeometry); |
| 115 return SkBitmapDevice::Create(cinfo.fInfo, &leaky); |
116 } | 116 } |
117 | 117 |
118 void SkBitmapDevice::lockPixels() { | 118 void SkBitmapDevice::lockPixels() { |
119 if (fBitmap.lockPixelsAreWritable()) { | 119 if (fBitmap.lockPixelsAreWritable()) { |
120 fBitmap.lockPixels(); | 120 fBitmap.lockPixels(); |
121 } | 121 } |
122 } | 122 } |
123 | 123 |
124 void SkBitmapDevice::unlockPixels() { | 124 void SkBitmapDevice::unlockPixels() { |
125 if (fBitmap.lockPixelsAreWritable()) { | 125 if (fBitmap.lockPixelsAreWritable()) { |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 } | 376 } |
377 | 377 |
378 SkImageFilter::Cache* SkBitmapDevice::getImageFilterCache() { | 378 SkImageFilter::Cache* SkBitmapDevice::getImageFilterCache() { |
379 SkImageFilter::Cache* cache = SkImageFilter::Cache::Get(); | 379 SkImageFilter::Cache* cache = SkImageFilter::Cache::Get(); |
380 cache->ref(); | 380 cache->ref(); |
381 return cache; | 381 return cache; |
382 } | 382 } |
383 | 383 |
384 /////////////////////////////////////////////////////////////////////////////// | 384 /////////////////////////////////////////////////////////////////////////////// |
385 | 385 |
386 bool SkBitmapDevice::filterTextFlags(const SkPaint& paint, TextFlags* flags) { | 386 bool SkBitmapDevice::onShouldDisableLCD(const SkPaint& paint) const { |
387 if (!paint.isLCDRenderText() || !paint.isAntiAlias()) { | |
388 // we're cool with the paint as is | |
389 return false; | |
390 } | |
391 | |
392 if (kN32_SkColorType != fBitmap.colorType() || | 387 if (kN32_SkColorType != fBitmap.colorType() || |
393 paint.getRasterizer() || | 388 paint.getRasterizer() || |
394 paint.getPathEffect() || | 389 paint.getPathEffect() || |
395 paint.isFakeBoldText() || | 390 paint.isFakeBoldText() || |
396 paint.getStyle() != SkPaint::kFill_Style || | 391 paint.getStyle() != SkPaint::kFill_Style || |
397 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) { | 392 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) |
398 // turn off lcd, but turn on kGenA8 | 393 { |
399 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag; | |
400 flags->fFlags |= SkPaint::kGenA8FromLCD_Flag; | |
401 return true; | 394 return true; |
402 } | 395 } |
403 // we're cool with the paint as is | |
404 return false; | 396 return false; |
405 } | 397 } |
OLD | NEW |