OLD | NEW |
1 #include "DMSrcSink.h" | 1 #include "DMSrcSink.h" |
2 #include "SamplePipeControllers.h" | 2 #include "SamplePipeControllers.h" |
3 #include "SkCommonFlags.h" | 3 #include "SkCommonFlags.h" |
4 #include "SkDocument.h" | 4 #include "SkDocument.h" |
5 #include "SkMultiPictureDraw.h" | 5 #include "SkMultiPictureDraw.h" |
6 #include "SkNullCanvas.h" | 6 #include "SkNullCanvas.h" |
7 #include "SkOSFile.h" | 7 #include "SkOSFile.h" |
8 #include "SkPictureRecorder.h" | 8 #include "SkPictureRecorder.h" |
9 #include "SkRandom.h" | 9 #include "SkRandom.h" |
10 #include "SkSVGCanvas.h" | 10 #include "SkSVGCanvas.h" |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 (void)SkColorTypeValidateAlphaType(fColorType, alphaType, &alphaType); | 264 (void)SkColorTypeValidateAlphaType(fColorType, alphaType, &alphaType); |
265 | 265 |
266 dst->allocPixels(SkImageInfo::Make(size.width(), size.height(), fColorType,
alphaType)); | 266 dst->allocPixels(SkImageInfo::Make(size.width(), size.height(), fColorType,
alphaType)); |
267 dst->eraseColor(SK_ColorTRANSPARENT); | 267 dst->eraseColor(SK_ColorTRANSPARENT); |
268 SkCanvas canvas(*dst); | 268 SkCanvas canvas(*dst); |
269 return src.draw(&canvas); | 269 return src.draw(&canvas); |
270 } | 270 } |
271 | 271 |
272 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ | 272 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
273 | 273 |
| 274 static SkISize auto_compute_translate(SkMatrix* matrix, int srcW, int srcH) { |
| 275 SkRect bounds = SkRect::MakeIWH(srcW, srcH); |
| 276 matrix->mapRect(&bounds); |
| 277 matrix->postTranslate(-bounds.x(), -bounds.y()); |
| 278 return SkISize::Make(SkScalarRoundToInt(bounds.width()), SkScalarRoundToInt(
bounds.height())); |
| 279 } |
| 280 |
274 ViaMatrix::ViaMatrix(SkMatrix matrix, Sink* sink) : fMatrix(matrix), fSink(sink)
{} | 281 ViaMatrix::ViaMatrix(SkMatrix matrix, Sink* sink) : fMatrix(matrix), fSink(sink)
{} |
275 | 282 |
276 Error ViaMatrix::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStr
ing* log) const { | 283 Error ViaMatrix::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStr
ing* log) const { |
277 // We turn our arguments into a Src, then draw that Src into our Sink to fil
l bitmap or stream. | 284 // We turn our arguments into a Src, then draw that Src into our Sink to fil
l bitmap or stream. |
278 struct ProxySrc : public Src { | 285 struct ProxySrc : public Src { |
279 const Src& fSrc; | 286 const Src& fSrc; |
280 SkMatrix fMatrix; | 287 SkMatrix fMatrix; |
281 ProxySrc(const Src& src, SkMatrix matrix) : fSrc(src), fMatrix(matrix) {
} | 288 SkISize fSize; |
| 289 |
| 290 ProxySrc(const Src& src, SkMatrix matrix) : fSrc(src), fMatrix(matrix) { |
| 291 fSize = auto_compute_translate(&fMatrix, src.size().width(), src.siz
e().height()); |
| 292 } |
282 | 293 |
283 Error draw(SkCanvas* canvas) const SK_OVERRIDE { | 294 Error draw(SkCanvas* canvas) const SK_OVERRIDE { |
284 canvas->concat(fMatrix); | 295 canvas->concat(fMatrix); |
285 return fSrc.draw(canvas); | 296 return fSrc.draw(canvas); |
286 } | 297 } |
287 SkISize size() const SK_OVERRIDE { return fSrc.size(); } | 298 SkISize size() const SK_OVERRIDE { return fSize; } |
288 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou
ld be calling this. | 299 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou
ld be calling this. |
289 } proxy(src, fMatrix); | 300 } proxy(src, fMatrix); |
290 return fSink->draw(proxy, bitmap, stream, log); | 301 return fSink->draw(proxy, bitmap, stream, log); |
291 } | 302 } |
292 | 303 |
| 304 // Undoes any flip or 90 degree rotate without changing the scale of the bitmap. |
| 305 // This should be pixel-preserving. |
| 306 ViaUpright::ViaUpright(SkMatrix matrix, Sink* sink) : fMatrix(matrix), fSink(sin
k) {} |
| 307 |
| 308 Error ViaUpright::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkSt
ring* log) const { |
| 309 Error err = fSink->draw(src, bitmap, stream, log); |
| 310 if (!err.isEmpty()) { |
| 311 return err; |
| 312 } |
| 313 |
| 314 SkMatrix inverse; |
| 315 if (!fMatrix.rectStaysRect() || !fMatrix.invert(&inverse)) { |
| 316 return "Cannot upright --matrix."; |
| 317 } |
| 318 SkMatrix upright = SkMatrix::I(); |
| 319 upright.setScaleX(SkScalarSignAsScalar(inverse.getScaleX())); |
| 320 upright.setScaleY(SkScalarSignAsScalar(inverse.getScaleY())); |
| 321 upright.setSkewX(SkScalarSignAsScalar(inverse.getSkewX())); |
| 322 upright.setSkewY(SkScalarSignAsScalar(inverse.getSkewY())); |
| 323 |
| 324 SkBitmap uprighted; |
| 325 SkISize size = auto_compute_translate(&upright, bitmap->width(), bitmap->hei
ght()); |
| 326 uprighted.allocPixels(bitmap->info().makeWH(size.width(), size.height())); |
| 327 |
| 328 SkCanvas canvas(uprighted); |
| 329 canvas.concat(upright); |
| 330 SkPaint paint; |
| 331 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 332 canvas.drawBitmap(*bitmap, 0, 0, &paint); |
| 333 |
| 334 *bitmap = uprighted; |
| 335 bitmap->lockPixels(); |
| 336 return ""; |
| 337 } |
| 338 |
293 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ | 339 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
294 | 340 |
295 ViaPipe::ViaPipe(Sink* sink) : fSink(sink) {} | 341 ViaPipe::ViaPipe(Sink* sink) : fSink(sink) {} |
296 | 342 |
297 Error ViaPipe::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStrin
g* log) const { | 343 Error ViaPipe::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStrin
g* log) const { |
298 // We turn ourselves into another Src that draws our argument into bitmap/st
ream via pipe. | 344 // We turn ourselves into another Src that draws our argument into bitmap/st
ream via pipe. |
299 struct ProxySrc : public Src { | 345 struct ProxySrc : public Src { |
300 const Src& fSrc; | 346 const Src& fSrc; |
301 ProxySrc(const Src& src) : fSrc(src) {} | 347 ProxySrc(const Src& src) : fSrc(src) {} |
302 | 348 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 surfaces.unrefAll(); | 457 surfaces.unrefAll(); |
412 return ""; | 458 return ""; |
413 } | 459 } |
414 SkISize size() const SK_OVERRIDE { return fSize; } | 460 SkISize size() const SK_OVERRIDE { return fSize; } |
415 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou
ld be calling this. | 461 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou
ld be calling this. |
416 } proxy(fW, fH, pic, src.size()); | 462 } proxy(fW, fH, pic, src.size()); |
417 return fSink->draw(proxy, bitmap, stream, log); | 463 return fSink->draw(proxy, bitmap, stream, log); |
418 } | 464 } |
419 | 465 |
420 } // namespace DM | 466 } // namespace DM |
OLD | NEW |