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 "SkColorFilter.h" |
8 #include "SkDevice.h" | 9 #include "SkDevice.h" |
9 #include "SkDraw.h" | 10 #include "SkDraw.h" |
10 #include "SkDrawFilter.h" | 11 #include "SkDrawFilter.h" |
11 #include "SkImage_Base.h" | 12 #include "SkImage_Base.h" |
12 #include "SkMetaData.h" | 13 #include "SkMetaData.h" |
13 #include "SkPatchUtils.h" | 14 #include "SkPatchUtils.h" |
14 #include "SkPathMeasure.h" | 15 #include "SkPathMeasure.h" |
15 #include "SkRasterClip.h" | 16 #include "SkRasterClip.h" |
| 17 #include "SkRSXform.h" |
16 #include "SkShader.h" | 18 #include "SkShader.h" |
17 #include "SkTextBlob.h" | 19 #include "SkTextBlob.h" |
18 #include "SkTextToPathIter.h" | 20 #include "SkTextToPathIter.h" |
19 | 21 |
20 SkBaseDevice::SkBaseDevice(const SkSurfaceProps& surfaceProps) | 22 SkBaseDevice::SkBaseDevice(const SkSurfaceProps& surfaceProps) |
21 : fSurfaceProps(surfaceProps) | 23 : fSurfaceProps(surfaceProps) |
22 #ifdef SK_DEBUG | 24 #ifdef SK_DEBUG |
23 , fAttachedToCanvas(false) | 25 , fAttachedToCanvas(false) |
24 #endif | 26 #endif |
25 { | 27 { |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 | 154 |
153 void SkBaseDevice::drawImageRect(const SkDraw& draw, const SkImage* image, const
SkRect* src, | 155 void SkBaseDevice::drawImageRect(const SkDraw& draw, const SkImage* image, const
SkRect* src, |
154 const SkRect& dst, const SkPaint& paint) { | 156 const SkRect& dst, const SkPaint& paint) { |
155 // Default impl : turns everything into raster bitmap | 157 // Default impl : turns everything into raster bitmap |
156 SkBitmap bm; | 158 SkBitmap bm; |
157 if (as_IB(image)->getROPixels(&bm)) { | 159 if (as_IB(image)->getROPixels(&bm)) { |
158 this->drawBitmapRect(draw, bm, src, dst, paint, SkCanvas::kNone_DrawBitm
apRectFlag); | 160 this->drawBitmapRect(draw, bm, src, dst, paint, SkCanvas::kNone_DrawBitm
apRectFlag); |
159 } | 161 } |
160 } | 162 } |
161 | 163 |
| 164 void SkBaseDevice::drawAtlas(const SkDraw& draw, const SkImage* atlas, const SkR
SXform xform[], |
| 165 const SkRect tex[], const SkColor colors[], int cou
nt, |
| 166 SkXfermode::Mode mode, const SkPaint& paint) { |
| 167 SkPath path; |
| 168 path.setIsVolatile(true); |
| 169 |
| 170 for (int i = 0; i < count; ++i) { |
| 171 SkPoint quad[4]; |
| 172 xform[i].toQuad(tex[i].width(), tex[i].height(), quad); |
| 173 |
| 174 SkMatrix localM; |
| 175 localM.setRSXform(xform[i]); |
| 176 localM.preTranslate(-tex[i].left(), -tex[i].top()); |
| 177 |
| 178 SkPaint pnt(paint); |
| 179 pnt.setShader(atlas->newShader(SkShader::kClamp_TileMode, SkShader::kCla
mp_TileMode, |
| 180 &localM))->unref(); |
| 181 if (colors && colors[i] != SK_ColorWHITE) { |
| 182 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(color
s[i], mode)); |
| 183 pnt.setColorFilter(cf); |
| 184 } |
| 185 |
| 186 path.rewind(); |
| 187 path.addPoly(quad, 4, true); |
| 188 path.setConvexity(SkPath::kConvex_Convexity); |
| 189 this->drawPath(draw, path, pnt, NULL, true); |
| 190 } |
| 191 } |
| 192 |
| 193 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 194 |
162 bool SkBaseDevice::readPixels(const SkImageInfo& info, void* dstP, size_t rowByt
es, int x, int y) { | 195 bool SkBaseDevice::readPixels(const SkImageInfo& info, void* dstP, size_t rowByt
es, int x, int y) { |
163 #ifdef SK_DEBUG | 196 #ifdef SK_DEBUG |
164 SkASSERT(info.width() > 0 && info.height() > 0); | 197 SkASSERT(info.width() > 0 && info.height() > 0); |
165 SkASSERT(dstP); | 198 SkASSERT(dstP); |
166 SkASSERT(rowBytes >= info.minRowBytes()); | 199 SkASSERT(rowBytes >= info.minRowBytes()); |
167 SkASSERT(x >= 0 && y >= 0); | 200 SkASSERT(x >= 0 && y >= 0); |
168 | 201 |
169 const SkImageInfo& srcInfo = this->imageInfo(); | 202 const SkImageInfo& srcInfo = this->imageInfo(); |
170 SkASSERT(x + info.width() <= srcInfo.width()); | 203 SkASSERT(x + info.width() <= srcInfo.width()); |
171 SkASSERT(y + info.height() <= srcInfo.height()); | 204 SkASSERT(y + info.height() <= srcInfo.height()); |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 if (kUnknown_SkPixelGeometry == fSurfaceProps.pixelGeometry() | 386 if (kUnknown_SkPixelGeometry == fSurfaceProps.pixelGeometry() |
354 || this->onShouldDisableLCD(paint)) { | 387 || this->onShouldDisableLCD(paint)) { |
355 | 388 |
356 flags &= ~SkPaint::kLCDRenderText_Flag; | 389 flags &= ~SkPaint::kLCDRenderText_Flag; |
357 flags |= SkPaint::kGenA8FromLCD_Flag; | 390 flags |= SkPaint::kGenA8FromLCD_Flag; |
358 } | 391 } |
359 | 392 |
360 return flags; | 393 return flags; |
361 } | 394 } |
362 | 395 |
OLD | NEW |