Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1342)

Side by Side Diff: src/core/SkDevice.cpp

Issue 22978012: Split SkDevice into SkBaseDevice and SkBitmapDevice (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: update to ToT, re-add SkBaseDevice::config & default parameter Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "SkDevice.h" 8 #include "SkDevice.h"
9 #include "SkDeviceProperties.h" 9 #include "SkDeviceProperties.h"
10 #include "SkDraw.h" 10 #include "SkDraw.h"
11 #include "SkImageFilter.h" 11 #include "SkImageFilter.h"
12 #include "SkMetaData.h" 12 #include "SkMetaData.h"
13 #include "SkRasterClip.h" 13 #include "SkRasterClip.h"
14 #include "SkRect.h" 14 #include "SkRect.h"
15 #include "SkRRect.h" 15 #include "SkRRect.h"
16 #include "SkShader.h" 16 #include "SkShader.h"
17 17
18 SK_DEFINE_INST_COUNT(SkDevice) 18 SK_DEFINE_INST_COUNT(SkBaseDevice)
19 SK_DEFINE_INST_COUNT(SkBitmapDevice)
19 20
20 /////////////////////////////////////////////////////////////////////////////// 21 ///////////////////////////////////////////////////////////////////////////////
21 22
22 #define CHECK_FOR_NODRAW_ANNOTATION(paint) \ 23 #define CHECK_FOR_NODRAW_ANNOTATION(paint) \
23 do { if (paint.isNoDrawAnnotation()) { return; } } while (0) 24 do { if (paint.isNoDrawAnnotation()) { return; } } while (0)
24 25
25 /////////////////////////////////////////////////////////////////////////////// 26 ///////////////////////////////////////////////////////////////////////////////
26 27
27 SkDevice::SkDevice(const SkBitmap& bitmap) 28 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap)
28 : fBitmap(bitmap), fLeakyProperties(SkDeviceProperties::MakeDefault()) 29 : fBitmap(bitmap) {
30 SkASSERT(SkBitmap::kARGB_4444_Config != bitmap.config());
31 }
32
33 SkBaseDevice::SkBaseDevice()
34 : fLeakyProperties(SkDeviceProperties::MakeDefault())
29 #ifdef SK_DEBUG 35 #ifdef SK_DEBUG
30 , fAttachedToCanvas(false) 36 , fAttachedToCanvas(false)
31 #endif 37 #endif
32 {
33 fOrigin.setZero();
34 fMetaData = NULL;
35
36 SkASSERT(SkBitmap::kARGB_4444_Config != bitmap.config());
37 }
38
39 SkDevice::SkDevice(const SkBitmap& bitmap, const SkDeviceProperties& devicePrope rties)
40 : fBitmap(bitmap), fLeakyProperties(deviceProperties)
41 #ifdef SK_DEBUG
42 , fAttachedToCanvas(false)
43 #endif
44 { 38 {
45 fOrigin.setZero(); 39 fOrigin.setZero();
46 fMetaData = NULL; 40 fMetaData = NULL;
47 } 41 }
48 42
49 SkDevice::SkDevice(SkBitmap::Config config, int width, int height, bool isOpaque ) 43 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkDeviceProperties& deviceProperties)
50 : fLeakyProperties(SkDeviceProperties::MakeDefault()) 44 : SkBaseDevice(deviceProperties)
45 , fBitmap(bitmap) {
46 }
47
48 SkBaseDevice::SkBaseDevice(const SkDeviceProperties& deviceProperties)
49 : fLeakyProperties(deviceProperties)
51 #ifdef SK_DEBUG 50 #ifdef SK_DEBUG
52 , fAttachedToCanvas(false) 51 , fAttachedToCanvas(false)
53 #endif 52 #endif
54 { 53 {
55 fOrigin.setZero(); 54 fOrigin.setZero();
56 fMetaData = NULL; 55 fMetaData = NULL;
56 }
57 57
58 SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, b ool isOpaque) {
58 fBitmap.setConfig(config, width, height); 59 fBitmap.setConfig(config, width, height);
59 fBitmap.allocPixels(); 60 fBitmap.allocPixels();
60 fBitmap.setIsOpaque(isOpaque); 61 fBitmap.setIsOpaque(isOpaque);
61 if (!isOpaque) { 62 if (!isOpaque) {
62 fBitmap.eraseColor(SK_ColorTRANSPARENT); 63 fBitmap.eraseColor(SK_ColorTRANSPARENT);
63 } 64 }
64 } 65 }
65 66
66 SkDevice::SkDevice(SkBitmap::Config config, int width, int height, bool isOpaque , 67 SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, b ool isOpaque,
67 const SkDeviceProperties& deviceProperties) 68 const SkDeviceProperties& deviceProperties)
68 : fLeakyProperties(deviceProperties) 69 : SkBaseDevice(deviceProperties) {
69 #ifdef SK_DEBUG
70 , fAttachedToCanvas(false)
71 #endif
72 {
73 fOrigin.setZero();
74 fMetaData = NULL;
75 70
76 fBitmap.setConfig(config, width, height); 71 fBitmap.setConfig(config, width, height);
77 fBitmap.allocPixels(); 72 fBitmap.allocPixels();
78 fBitmap.setIsOpaque(isOpaque); 73 fBitmap.setIsOpaque(isOpaque);
79 if (!isOpaque) { 74 if (!isOpaque) {
80 fBitmap.eraseColor(SK_ColorTRANSPARENT); 75 fBitmap.eraseColor(SK_ColorTRANSPARENT);
81 } 76 }
82 } 77 }
83 78
84 SkDevice::~SkDevice() { 79 SkBaseDevice::~SkBaseDevice() {
85 delete fMetaData; 80 delete fMetaData;
86 } 81 }
87 82
88 void SkDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) { 83 SkBitmapDevice::~SkBitmapDevice() {
84 }
85
86 void SkBitmapDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) {
89 SkASSERT(bm.width() == fBitmap.width()); 87 SkASSERT(bm.width() == fBitmap.width());
90 SkASSERT(bm.height() == fBitmap.height()); 88 SkASSERT(bm.height() == fBitmap.height());
91 fBitmap = bm; // intent is to use bm's pixelRef (and rowbytes/config) 89 fBitmap = bm; // intent is to use bm's pixelRef (and rowbytes/config)
92 fBitmap.lockPixels(); 90 fBitmap.lockPixels();
93 } 91 }
94 92
95 SkDevice* SkDevice::createCompatibleDevice(SkBitmap::Config config, 93 SkBaseDevice* SkBaseDevice::createCompatibleDevice(SkBitmap::Config config,
96 int width, int height, 94 int width, int height,
97 bool isOpaque) { 95 bool isOpaque) {
98 return this->onCreateCompatibleDevice(config, width, height, 96 return this->onCreateCompatibleDevice(config, width, height,
99 isOpaque, kGeneral_Usage); 97 isOpaque, kGeneral_Usage);
100 } 98 }
101 99
102 SkDevice* SkDevice::createCompatibleDeviceForSaveLayer(SkBitmap::Config config, 100 SkBaseDevice* SkBaseDevice::createCompatibleDeviceForSaveLayer(SkBitmap::Config config,
103 int width, int height, 101 int width, int he ight,
104 bool isOpaque) { 102 bool isOpaque) {
105 return this->onCreateCompatibleDevice(config, width, height, 103 return this->onCreateCompatibleDevice(config, width, height,
106 isOpaque, kSaveLayer_Usage); 104 isOpaque, kSaveLayer_Usage);
107 } 105 }
108 106
109 SkDevice* SkDevice::onCreateCompatibleDevice(SkBitmap::Config config, 107 SkBaseDevice* SkBitmapDevice::onCreateCompatibleDevice(SkBitmap::Config config,
110 int width, int height, 108 int width, int height,
111 bool isOpaque, 109 bool isOpaque,
112 Usage usage) { 110 Usage usage) {
113 return SkNEW_ARGS(SkDevice,(config, width, height, isOpaque, fLeakyPropertie s)); 111 return SkNEW_ARGS(SkBitmapDevice,(config, width, height, isOpaque,
112 this->getDeviceProperties()));
114 } 113 }
115 114
116 SkMetaData& SkDevice::getMetaData() { 115 SkMetaData& SkBaseDevice::getMetaData() {
117 // metadata users are rare, so we lazily allocate it. If that changes we 116 // metadata users are rare, so we lazily allocate it. If that changes we
118 // can decide to just make it a field in the device (rather than a ptr) 117 // can decide to just make it a field in the device (rather than a ptr)
119 if (NULL == fMetaData) { 118 if (NULL == fMetaData) {
120 fMetaData = new SkMetaData; 119 fMetaData = new SkMetaData;
121 } 120 }
122 return *fMetaData; 121 return *fMetaData;
123 } 122 }
124 123
125 void SkDevice::lockPixels() { 124 void SkBitmapDevice::lockPixels() {
126 if (fBitmap.lockPixelsAreWritable()) { 125 if (fBitmap.lockPixelsAreWritable()) {
127 fBitmap.lockPixels(); 126 fBitmap.lockPixels();
128 } 127 }
129 } 128 }
130 129
131 void SkDevice::unlockPixels() { 130 void SkBitmapDevice::unlockPixels() {
132 if (fBitmap.lockPixelsAreWritable()) { 131 if (fBitmap.lockPixelsAreWritable()) {
133 fBitmap.unlockPixels(); 132 fBitmap.unlockPixels();
134 } 133 }
135 } 134 }
136 135
137 const SkBitmap& SkDevice::accessBitmap(bool changePixels) { 136 const SkBitmap& SkBaseDevice::accessBitmap(bool changePixels) {
138 const SkBitmap& bitmap = this->onAccessBitmap(&fBitmap); 137 const SkBitmap& bitmap = this->onAccessBitmap();
139 if (changePixels) { 138 if (changePixels) {
140 bitmap.notifyPixelsChanged(); 139 bitmap.notifyPixelsChanged();
141 } 140 }
142 return bitmap; 141 return bitmap;
143 } 142 }
144 143
145 void SkDevice::getGlobalBounds(SkIRect* bounds) const { 144 void SkBitmapDevice::getGlobalBounds(SkIRect* bounds) const {
146 if (bounds) { 145 if (bounds) {
147 bounds->setXYWH(fOrigin.x(), fOrigin.y(), 146 const SkIPoint& origin = this->getOrigin();
147 bounds->setXYWH(origin.x(), origin.y(),
148 fBitmap.width(), fBitmap.height()); 148 fBitmap.width(), fBitmap.height());
149 } 149 }
150 } 150 }
151 151
152 void SkDevice::clear(SkColor color) { 152 void SkBitmapDevice::clear(SkColor color) {
153 fBitmap.eraseColor(color); 153 fBitmap.eraseColor(color);
154 } 154 }
155 155
156 const SkBitmap& SkDevice::onAccessBitmap(SkBitmap* bitmap) {return *bitmap;} 156 const SkBitmap& SkBitmapDevice::onAccessBitmap() {
157 157 return fBitmap;
158 void SkDevice::setMatrixClip(const SkMatrix& matrix, const SkRegion& region,
159 const SkClipStack& clipStack) {
160 } 158 }
161 159
162 bool SkDevice::canHandleImageFilter(SkImageFilter*) { 160 bool SkBitmapDevice::canHandleImageFilter(SkImageFilter*) {
163 return false; 161 return false;
164 } 162 }
165 163
166 bool SkDevice::filterImage(SkImageFilter* filter, const SkBitmap& src, 164 bool SkBitmapDevice::filterImage(SkImageFilter* filter, const SkBitmap& src,
167 const SkMatrix& ctm, SkBitmap* result, 165 const SkMatrix& ctm, SkBitmap* result,
168 SkIPoint* offset) { 166 SkIPoint* offset) {
169 return false; 167 return false;
170 } 168 }
171 169
172 bool SkDevice::allowImageFilter(SkImageFilter*) { 170 bool SkBitmapDevice::allowImageFilter(SkImageFilter*) {
173 return true; 171 return true;
174 } 172 }
175 173
176 /////////////////////////////////////////////////////////////////////////////// 174 ///////////////////////////////////////////////////////////////////////////////
177 175
178 bool SkDevice::readPixels(SkBitmap* bitmap, int x, int y, 176 bool SkBaseDevice::readPixels(SkBitmap* bitmap, int x, int y,
179 SkCanvas::Config8888 config8888) { 177 SkCanvas::Config8888 config8888) {
180 if (SkBitmap::kARGB_8888_Config != bitmap->config() || 178 if (SkBitmap::kARGB_8888_Config != bitmap->config() ||
181 NULL != bitmap->getTexture()) { 179 NULL != bitmap->getTexture()) {
182 return false; 180 return false;
183 } 181 }
184 182
185 const SkBitmap& src = this->accessBitmap(false); 183 const SkBitmap& src = this->accessBitmap(false);
186 184
187 SkIRect srcRect = SkIRect::MakeXYWH(x, y, bitmap->width(), 185 SkIRect srcRect = SkIRect::MakeXYWH(x, y, bitmap->width(),
188 bitmap->height()); 186 bitmap->height());
189 SkIRect devbounds = SkIRect::MakeWH(src.width(), src.height()); 187 SkIRect devbounds = SkIRect::MakeWH(src.width(), src.height());
(...skipping 23 matching lines...) Expand all
213 srcRect.fLeft, 211 srcRect.fLeft,
214 srcRect.fTop, 212 srcRect.fTop,
215 config8888); 213 config8888);
216 if (result && bmp == &tmp) { 214 if (result && bmp == &tmp) {
217 tmp.swap(*bitmap); 215 tmp.swap(*bitmap);
218 } 216 }
219 return result; 217 return result;
220 } 218 }
221 219
222 #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A) 220 #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A)
223 const SkCanvas::Config8888 SkDevice::kPMColorAlias = 221 const SkCanvas::Config8888 SkBaseDevice::kPMColorAlias =
224 SkCanvas::kBGRA_Premul_Config8888; 222 SkCanvas::kBGRA_Premul_Config8888;
225 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A) 223 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A)
226 const SkCanvas::Config8888 SkDevice::kPMColorAlias = 224 const SkCanvas::Config8888 SkBaseDevice::kPMColorAlias =
227 SkCanvas::kRGBA_Premul_Config8888; 225 SkCanvas::kRGBA_Premul_Config8888;
228 #else 226 #else
229 const SkCanvas::Config8888 SkDevice::kPMColorAlias = 227 const SkCanvas::Config8888 SkBaseDevice::kPMColorAlias =
230 (SkCanvas::Config8888) -1; 228 (SkCanvas::Config8888) -1;
231 #endif 229 #endif
232 230
233 #include <SkConfig8888.h> 231 #include <SkConfig8888.h>
234 232
235 bool SkDevice::onReadPixels(const SkBitmap& bitmap, 233 bool SkBitmapDevice::onReadPixels(const SkBitmap& bitmap,
236 int x, int y, 234 int x, int y,
237 SkCanvas::Config8888 config8888) { 235 SkCanvas::Config8888 config8888) {
238 SkASSERT(SkBitmap::kARGB_8888_Config == bitmap.config()); 236 SkASSERT(SkBitmap::kARGB_8888_Config == bitmap.config());
239 SkASSERT(!bitmap.isNull()); 237 SkASSERT(!bitmap.isNull());
240 SkASSERT(SkIRect::MakeWH(this->width(), this->height()).contains(SkIRect::Ma keXYWH(x, y, bitmap.width(), bitmap.height()))); 238 SkASSERT(SkIRect::MakeWH(this->width(), this->height()).contains(SkIRect::Ma keXYWH(x, y, bitmap.width(), bitmap.height())));
241 239
242 SkIRect srcRect = SkIRect::MakeXYWH(x, y, bitmap.width(), 240 SkIRect srcRect = SkIRect::MakeXYWH(x, y, bitmap.width(),
243 bitmap.height()); 241 bitmap.height());
244 const SkBitmap& src = this->accessBitmap(false); 242 const SkBitmap& src = this->accessBitmap(false);
245 243
246 SkBitmap subset; 244 SkBitmap subset;
247 if (!src.extractSubset(&subset, srcRect)) { 245 if (!src.extractSubset(&subset, srcRect)) {
248 return false; 246 return false;
249 } 247 }
250 if (SkBitmap::kARGB_8888_Config != subset.config()) { 248 if (SkBitmap::kARGB_8888_Config != subset.config()) {
251 // It'd be preferable to do this directly to bitmap. 249 // It'd be preferable to do this directly to bitmap.
252 subset.copyTo(&subset, SkBitmap::kARGB_8888_Config); 250 subset.copyTo(&subset, SkBitmap::kARGB_8888_Config);
253 } 251 }
254 SkAutoLockPixels alp(bitmap); 252 SkAutoLockPixels alp(bitmap);
255 uint32_t* bmpPixels = reinterpret_cast<uint32_t*>(bitmap.getPixels()); 253 uint32_t* bmpPixels = reinterpret_cast<uint32_t*>(bitmap.getPixels());
256 SkCopyBitmapToConfig8888(bmpPixels, bitmap.rowBytes(), config8888, subset); 254 SkCopyBitmapToConfig8888(bmpPixels, bitmap.rowBytes(), config8888, subset);
257 return true; 255 return true;
258 } 256 }
259 257
260 void SkDevice::writePixels(const SkBitmap& bitmap, 258 void SkBitmapDevice::writePixels(const SkBitmap& bitmap,
261 int x, int y, 259 int x, int y,
262 SkCanvas::Config8888 config8888) { 260 SkCanvas::Config8888 config8888) {
263 if (bitmap.isNull() || bitmap.getTexture()) { 261 if (bitmap.isNull() || bitmap.getTexture()) {
264 return; 262 return;
265 } 263 }
266 const SkBitmap* sprite = &bitmap; 264 const SkBitmap* sprite = &bitmap;
267 // check whether we have to handle a config8888 that doesn't match SkPMColor 265 // check whether we have to handle a config8888 that doesn't match SkPMColor
268 if (SkBitmap::kARGB_8888_Config == bitmap.config() && 266 if (SkBitmap::kARGB_8888_Config == bitmap.config() &&
269 SkCanvas::kNative_Premul_Config8888 != config8888 && 267 SkCanvas::kNative_Premul_Config8888 != config8888 &&
270 kPMColorAlias != config8888) { 268 kPMColorAlias != config8888) {
271 269
272 // We're going to have to convert from a config8888 to the native config 270 // We're going to have to convert from a config8888 to the native config
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 SkDraw draw; 319 SkDraw draw;
322 draw.fRC = &clip; 320 draw.fRC = &clip;
323 draw.fClip = &clip.bwRgn(); 321 draw.fClip = &clip.bwRgn();
324 draw.fBitmap = &fBitmap; // canvas should have already called accessBitmap 322 draw.fBitmap = &fBitmap; // canvas should have already called accessBitmap
325 draw.fMatrix = &SkMatrix::I(); 323 draw.fMatrix = &SkMatrix::I();
326 this->drawSprite(draw, *sprite, x, y, paint); 324 this->drawSprite(draw, *sprite, x, y, paint);
327 } 325 }
328 326
329 /////////////////////////////////////////////////////////////////////////////// 327 ///////////////////////////////////////////////////////////////////////////////
330 328
331 void SkDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { 329 void SkBitmapDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
332 draw.drawPaint(paint); 330 draw.drawPaint(paint);
333 } 331 }
334 332
335 void SkDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, size_t c ount, 333 void SkBitmapDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, si ze_t count,
336 const SkPoint pts[], const SkPaint& paint) { 334 const SkPoint pts[], const SkPaint& paint) {
337 CHECK_FOR_NODRAW_ANNOTATION(paint); 335 CHECK_FOR_NODRAW_ANNOTATION(paint);
338 draw.drawPoints(mode, count, pts, paint); 336 draw.drawPoints(mode, count, pts, paint);
339 } 337 }
340 338
341 void SkDevice::drawRect(const SkDraw& draw, const SkRect& r, const SkPaint& pain t) { 339 void SkBitmapDevice::drawRect(const SkDraw& draw, const SkRect& r, const SkPaint & paint) {
342 CHECK_FOR_NODRAW_ANNOTATION(paint); 340 CHECK_FOR_NODRAW_ANNOTATION(paint);
343 draw.drawRect(r, paint); 341 draw.drawRect(r, paint);
344 } 342 }
345 343
346 void SkDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPaint& p aint) { 344 void SkBitmapDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPa int& paint) {
347 CHECK_FOR_NODRAW_ANNOTATION(paint); 345 CHECK_FOR_NODRAW_ANNOTATION(paint);
348 346
349 SkPath path; 347 SkPath path;
350 path.addOval(oval); 348 path.addOval(oval);
351 // call the VIRTUAL version, so any subclasses who do handle drawPath aren't 349 // call the VIRTUAL version, so any subclasses who do handle drawPath aren't
352 // required to override drawOval. 350 // required to override drawOval.
353 this->drawPath(draw, path, paint, NULL, true); 351 this->drawPath(draw, path, paint, NULL, true);
354 } 352 }
355 353
356 void SkDevice::drawRRect(const SkDraw& draw, const SkRRect& rrect, const SkPaint & paint) { 354 void SkBitmapDevice::drawRRect(const SkDraw& draw, const SkRRect& rrect, const S kPaint& paint) {
357 CHECK_FOR_NODRAW_ANNOTATION(paint); 355 CHECK_FOR_NODRAW_ANNOTATION(paint);
358 356
359 SkPath path; 357 SkPath path;
360 path.addRRect(rrect); 358 path.addRRect(rrect);
361 // call the VIRTUAL version, so any subclasses who do handle drawPath aren't 359 // call the VIRTUAL version, so any subclasses who do handle drawPath aren't
362 // required to override drawRRect. 360 // required to override drawRRect.
363 this->drawPath(draw, path, paint, NULL, true); 361 this->drawPath(draw, path, paint, NULL, true);
364 } 362 }
365 363
366 void SkDevice::drawPath(const SkDraw& draw, const SkPath& path, 364 void SkBitmapDevice::drawPath(const SkDraw& draw, const SkPath& path,
367 const SkPaint& paint, const SkMatrix* prePathMatrix, 365 const SkPaint& paint, const SkMatrix* prePathMatri x,
368 bool pathIsMutable) { 366 bool pathIsMutable) {
369 CHECK_FOR_NODRAW_ANNOTATION(paint); 367 CHECK_FOR_NODRAW_ANNOTATION(paint);
370 draw.drawPath(path, paint, prePathMatrix, pathIsMutable); 368 draw.drawPath(path, paint, prePathMatrix, pathIsMutable);
371 } 369 }
372 370
373 void SkDevice::drawBitmap(const SkDraw& draw, const SkBitmap& bitmap, 371 void SkBitmapDevice::drawBitmap(const SkDraw& draw, const SkBitmap& bitmap,
374 const SkMatrix& matrix, const SkPaint& paint) { 372 const SkMatrix& matrix, const SkPaint& paint) {
375 draw.drawBitmap(bitmap, matrix, paint); 373 draw.drawBitmap(bitmap, matrix, paint);
376 } 374 }
377 375
378 void SkDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, 376 void SkBitmapDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap,
379 const SkRect* src, const SkRect& dst, 377 const SkRect* src, const SkRect& dst,
380 const SkPaint& paint, 378 const SkPaint& paint,
381 SkCanvas::DrawBitmapRectFlags flags) { 379 SkCanvas::DrawBitmapRectFlags flags) {
382 SkMatrix matrix; 380 SkMatrix matrix;
383 SkRect bitmapBounds, tmpSrc, tmpDst; 381 SkRect bitmapBounds, tmpSrc, tmpDst;
384 SkBitmap tmpBitmap; 382 SkBitmap tmpBitmap;
385 383
386 bitmapBounds.isetWH(bitmap.width(), bitmap.height()); 384 bitmapBounds.isetWH(bitmap.width(), bitmap.height());
387 385
388 // Compute matrix from the two rectangles 386 // Compute matrix from the two rectangles
389 if (src) { 387 if (src) {
390 tmpSrc = *src; 388 tmpSrc = *src;
391 } else { 389 } else {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 453
456 SkPaint paintWithShader(paint); 454 SkPaint paintWithShader(paint);
457 paintWithShader.setStyle(SkPaint::kFill_Style); 455 paintWithShader.setStyle(SkPaint::kFill_Style);
458 paintWithShader.setShader(s)->unref(); 456 paintWithShader.setShader(s)->unref();
459 457
460 // Call ourself, in case the subclass wanted to share this setup code 458 // Call ourself, in case the subclass wanted to share this setup code
461 // but handle the drawRect code themselves. 459 // but handle the drawRect code themselves.
462 this->drawRect(draw, *dstPtr, paintWithShader); 460 this->drawRect(draw, *dstPtr, paintWithShader);
463 } 461 }
464 462
465 void SkDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, 463 void SkBitmapDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
466 int x, int y, const SkPaint& paint) { 464 int x, int y, const SkPaint& paint) {
467 draw.drawSprite(bitmap, x, y, paint); 465 draw.drawSprite(bitmap, x, y, paint);
468 } 466 }
469 467
470 void SkDevice::drawText(const SkDraw& draw, const void* text, size_t len, 468 void SkBitmapDevice::drawText(const SkDraw& draw, const void* text, size_t len,
471 SkScalar x, SkScalar y, const SkPaint& paint) { 469 SkScalar x, SkScalar y, const SkPaint& paint) {
472 draw.drawText((const char*)text, len, x, y, paint); 470 draw.drawText((const char*)text, len, x, y, paint);
473 } 471 }
474 472
475 void SkDevice::drawPosText(const SkDraw& draw, const void* text, size_t len, 473 void SkBitmapDevice::drawPosText(const SkDraw& draw, const void* text, size_t le n,
476 const SkScalar xpos[], SkScalar y, 474 const SkScalar xpos[], SkScalar y,
477 int scalarsPerPos, const SkPaint& paint) { 475 int scalarsPerPos, const SkPaint& paint) {
478 draw.drawPosText((const char*)text, len, xpos, y, scalarsPerPos, paint); 476 draw.drawPosText((const char*)text, len, xpos, y, scalarsPerPos, paint);
479 } 477 }
480 478
481 void SkDevice::drawTextOnPath(const SkDraw& draw, const void* text, 479 void SkBitmapDevice::drawTextOnPath(const SkDraw& draw, const void* text,
482 size_t len, const SkPath& path, 480 size_t len, const SkPath& path,
483 const SkMatrix* matrix, 481 const SkMatrix* matrix,
484 const SkPaint& paint) { 482 const SkPaint& paint) {
485 draw.drawTextOnPath((const char*)text, len, path, matrix, paint); 483 draw.drawTextOnPath((const char*)text, len, path, matrix, paint);
486 } 484 }
487 485
488 #ifdef SK_BUILD_FOR_ANDROID 486 #ifdef SK_BUILD_FOR_ANDROID
489 void SkDevice::drawPosTextOnPath(const SkDraw& draw, const void* text, size_t le n, 487 void SkBitmapDevice::drawPosTextOnPath(const SkDraw& draw, const void* text, siz e_t len,
490 const SkPoint pos[], const SkPaint& paint, 488 const SkPoint pos[], const SkPaint& paint ,
491 const SkPath& path, const SkMatrix* matrix) { 489 const SkPath& path, const SkMatrix* matri x) {
492 draw.drawPosTextOnPath((const char*)text, len, pos, paint, path, matrix); 490 draw.drawPosTextOnPath((const char*)text, len, pos, paint, path, matrix);
493 } 491 }
494 #endif 492 #endif
495 493
496 void SkDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, 494 void SkBitmapDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode ,
497 int vertexCount, 495 int vertexCount,
498 const SkPoint verts[], const SkPoint textures[], 496 const SkPoint verts[], const SkPoint textures[ ],
499 const SkColor colors[], SkXfermode* xmode, 497 const SkColor colors[], SkXfermode* xmode,
500 const uint16_t indices[], int indexCount, 498 const uint16_t indices[], int indexCount,
501 const SkPaint& paint) { 499 const SkPaint& paint) {
502 draw.drawVertices(vmode, vertexCount, verts, textures, colors, xmode, 500 draw.drawVertices(vmode, vertexCount, verts, textures, colors, xmode,
503 indices, indexCount, paint); 501 indices, indexCount, paint);
504 } 502 }
505 503
506 void SkDevice::drawDevice(const SkDraw& draw, SkDevice* device, 504 void SkBitmapDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device,
507 int x, int y, const SkPaint& paint) { 505 int x, int y, const SkPaint& paint) {
508 const SkBitmap& src = device->accessBitmap(false); 506 const SkBitmap& src = device->accessBitmap(false);
509 draw.drawSprite(src, x, y, paint); 507 draw.drawSprite(src, x, y, paint);
510 } 508 }
511 509
512 /////////////////////////////////////////////////////////////////////////////// 510 ///////////////////////////////////////////////////////////////////////////////
513 511
514 bool SkDevice::filterTextFlags(const SkPaint& paint, TextFlags* flags) { 512 bool SkBitmapDevice::filterTextFlags(const SkPaint& paint, TextFlags* flags) {
515 if (!paint.isLCDRenderText() || !paint.isAntiAlias()) { 513 if (!paint.isLCDRenderText() || !paint.isAntiAlias()) {
516 // we're cool with the paint as is 514 // we're cool with the paint as is
517 return false; 515 return false;
518 } 516 }
519 517
520 if (SkBitmap::kARGB_8888_Config != fBitmap.config() || 518 if (SkBitmap::kARGB_8888_Config != fBitmap.config() ||
521 paint.getRasterizer() || 519 paint.getRasterizer() ||
522 paint.getPathEffect() || 520 paint.getPathEffect() ||
523 paint.isFakeBoldText() || 521 paint.isFakeBoldText() ||
524 paint.getStyle() != SkPaint::kFill_Style || 522 paint.getStyle() != SkPaint::kFill_Style ||
525 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) { 523 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) {
526 // turn off lcd 524 // turn off lcd
527 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag; 525 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag;
528 flags->fHinting = paint.getHinting(); 526 flags->fHinting = paint.getHinting();
529 return true; 527 return true;
530 } 528 }
531 // we're cool with the paint as is 529 // we're cool with the paint as is
532 return false; 530 return false;
533 } 531 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698