| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkDevice.h" | 8 #include "SkDevice.h" |
| 9 #include "SkMetaData.h" | 9 #include "SkMetaData.h" |
| 10 | 10 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 } | 105 } |
| 106 | 106 |
| 107 const SkBitmap& SkBaseDevice::accessBitmap(bool changePixels) { | 107 const SkBitmap& SkBaseDevice::accessBitmap(bool changePixels) { |
| 108 const SkBitmap& bitmap = this->onAccessBitmap(); | 108 const SkBitmap& bitmap = this->onAccessBitmap(); |
| 109 if (changePixels) { | 109 if (changePixels) { |
| 110 bitmap.notifyPixelsChanged(); | 110 bitmap.notifyPixelsChanged(); |
| 111 } | 111 } |
| 112 return bitmap; | 112 return bitmap; |
| 113 } | 113 } |
| 114 | 114 |
| 115 #ifdef SK_SUPPORT_LEGACY_READPIXELSCONFIG |
| 115 bool SkBaseDevice::readPixels(SkBitmap* bitmap, int x, int y, | 116 bool SkBaseDevice::readPixels(SkBitmap* bitmap, int x, int y, |
| 116 SkCanvas::Config8888 config8888) { | 117 SkCanvas::Config8888 config8888) { |
| 117 if (SkBitmap::kARGB_8888_Config != bitmap->config() || | 118 if (SkBitmap::kARGB_8888_Config != bitmap->config() || |
| 118 NULL != bitmap->getTexture()) { | 119 NULL != bitmap->getTexture()) { |
| 119 return false; | 120 return false; |
| 120 } | 121 } |
| 121 | 122 |
| 122 const SkBitmap& src = this->accessBitmap(false); | 123 const SkBitmap& src = this->accessBitmap(false); |
| 123 | 124 |
| 124 SkIRect srcRect = SkIRect::MakeXYWH(x, y, bitmap->width(), | 125 SkIRect srcRect = SkIRect::MakeXYWH(x, y, bitmap->width(), |
| (...skipping 22 matching lines...) Expand all Loading... |
| 147 | 148 |
| 148 bool result = this->onReadPixels(bmpSubset, | 149 bool result = this->onReadPixels(bmpSubset, |
| 149 srcRect.fLeft, | 150 srcRect.fLeft, |
| 150 srcRect.fTop, | 151 srcRect.fTop, |
| 151 config8888); | 152 config8888); |
| 152 if (result && bmp == &tmp) { | 153 if (result && bmp == &tmp) { |
| 153 tmp.swap(*bitmap); | 154 tmp.swap(*bitmap); |
| 154 } | 155 } |
| 155 return result; | 156 return result; |
| 156 } | 157 } |
| 158 bool SkBaseDevice::onReadPixels(const SkBitmap&, int x, int y, SkCanvas::Config8
888) { |
| 159 return false; |
| 160 } |
| 161 #endif |
| 157 | 162 |
| 158 SkSurface* SkBaseDevice::newSurface(const SkImageInfo&) { return NULL; } | 163 SkSurface* SkBaseDevice::newSurface(const SkImageInfo&) { return NULL; } |
| 159 | 164 |
| 160 const void* SkBaseDevice::peekPixels(SkImageInfo*, size_t*) { return NULL; } | 165 const void* SkBaseDevice::peekPixels(SkImageInfo*, size_t*) { return NULL; } |
| 161 | 166 |
| 162 void SkBaseDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, | 167 void SkBaseDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, |
| 163 const SkRRect& inner, const SkPaint& paint) { | 168 const SkRRect& inner, const SkPaint& paint) { |
| 164 SkPath path; | 169 SkPath path; |
| 165 path.addRRect(outer); | 170 path.addRRect(outer); |
| 166 path.addRRect(inner); | 171 path.addRRect(inner); |
| 167 path.setFillType(SkPath::kEvenOdd_FillType); | 172 path.setFillType(SkPath::kEvenOdd_FillType); |
| 168 | 173 |
| 169 const SkMatrix* preMatrix = NULL; | 174 const SkMatrix* preMatrix = NULL; |
| 170 const bool pathIsMutable = true; | 175 const bool pathIsMutable = true; |
| 171 this->drawPath(draw, path, paint, preMatrix, pathIsMutable); | 176 this->drawPath(draw, path, paint, preMatrix, pathIsMutable); |
| 172 } | 177 } |
| 173 | 178 |
| 179 bool SkBaseDevice::readPixels(const SkImageInfo& info, void* dstP, size_t rowByt
es, int x, int y) { |
| 180 #ifdef SK_DEBUG |
| 181 SkASSERT(info.width() > 0 && info.height() > 0); |
| 182 SkASSERT(dstP); |
| 183 SkASSERT(rowBytes >= info.minRowBytes()); |
| 184 SkASSERT(x >= 0 && y >= 0); |
| 185 |
| 186 const SkImageInfo& srcInfo = this->imageInfo(); |
| 187 SkASSERT(x + info.width() <= srcInfo.width()); |
| 188 SkASSERT(y + info.height() <= srcInfo.height()); |
| 189 #endif |
| 190 return this->onReadPixels(info, dstP, rowBytes, x, y); |
| 191 } |
| 192 |
| 174 bool SkBaseDevice::writePixels(const SkImageInfo& info, const void* pixels, size
_t rowBytes, | 193 bool SkBaseDevice::writePixels(const SkImageInfo& info, const void* pixels, size
_t rowBytes, |
| 175 int x, int y) { | 194 int x, int y) { |
| 176 #ifdef SK_DEBUG | 195 #ifdef SK_DEBUG |
| 177 SkASSERT(info.width() > 0 && info.height() > 0); | 196 SkASSERT(info.width() > 0 && info.height() > 0); |
| 178 SkASSERT(pixels); | 197 SkASSERT(pixels); |
| 179 SkASSERT(rowBytes >= info.minRowBytes()); | 198 SkASSERT(rowBytes >= info.minRowBytes()); |
| 180 SkASSERT(x >= 0 && y >= 0); | 199 SkASSERT(x >= 0 && y >= 0); |
| 181 | 200 |
| 182 const SkImageInfo& dstInfo = this->imageInfo(); | 201 const SkImageInfo& dstInfo = this->imageInfo(); |
| 183 SkASSERT(x + info.width() <= dstInfo.width()); | 202 SkASSERT(x + info.width() <= dstInfo.width()); |
| 184 SkASSERT(y + info.height() <= dstInfo.height()); | 203 SkASSERT(y + info.height() <= dstInfo.height()); |
| 185 #endif | 204 #endif |
| 186 return this->onWritePixels(info, pixels, rowBytes, x, y); | 205 return this->onWritePixels(info, pixels, rowBytes, x, y); |
| 187 } | 206 } |
| 188 | 207 |
| 189 bool SkBaseDevice::onWritePixels(const SkImageInfo&, const void*, size_t, int, i
nt) { | 208 bool SkBaseDevice::onWritePixels(const SkImageInfo&, const void*, size_t, int, i
nt) { |
| 190 return false; | 209 return false; |
| 191 } | 210 } |
| 192 | 211 |
| 193 bool SkBaseDevice::onReadPixels(const SkBitmap&, int x, int y, SkCanvas::Config8
888) { | 212 bool SkBaseDevice::onReadPixels(const SkImageInfo&, void*, size_t, int x, int y)
{ |
| 194 return false; | 213 return false; |
| 195 } | 214 } |
| 196 | 215 |
| 197 void* SkBaseDevice::accessPixels(SkImageInfo* info, size_t* rowBytes) { | 216 void* SkBaseDevice::accessPixels(SkImageInfo* info, size_t* rowBytes) { |
| 198 SkImageInfo tmpInfo; | 217 SkImageInfo tmpInfo; |
| 199 size_t tmpRowBytes; | 218 size_t tmpRowBytes; |
| 200 if (NULL == info) { | 219 if (NULL == info) { |
| 201 info = &tmpInfo; | 220 info = &tmpInfo; |
| 202 } | 221 } |
| 203 if (NULL == rowBytes) { | 222 if (NULL == rowBytes) { |
| 204 rowBytes = &tmpRowBytes; | 223 rowBytes = &tmpRowBytes; |
| 205 } | 224 } |
| 206 return this->onAccessPixels(info, rowBytes); | 225 return this->onAccessPixels(info, rowBytes); |
| 207 } | 226 } |
| 208 | 227 |
| 209 void* SkBaseDevice::onAccessPixels(SkImageInfo* info, size_t* rowBytes) { | 228 void* SkBaseDevice::onAccessPixels(SkImageInfo* info, size_t* rowBytes) { |
| 210 return NULL; | 229 return NULL; |
| 211 } | 230 } |
| 212 | 231 |
| 213 void SkBaseDevice::EXPERIMENTAL_optimize(SkPicture* picture) { | 232 void SkBaseDevice::EXPERIMENTAL_optimize(SkPicture* picture) { |
| 214 // The base class doesn't perform any analysis but derived classes may | 233 // The base class doesn't perform any analysis but derived classes may |
| 215 } | 234 } |
| 216 | 235 |
| 217 bool SkBaseDevice::EXPERIMENTAL_drawPicture(const SkPicture& picture) { | 236 bool SkBaseDevice::EXPERIMENTAL_drawPicture(const SkPicture& picture) { |
| 218 // The base class doesn't perform any accelerated picture rendering | 237 // The base class doesn't perform any accelerated picture rendering |
| 219 return false; | 238 return false; |
| 220 } | 239 } |
| OLD | NEW |