| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | 2 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
| 3 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved. | 3 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "platform/Length.h" | 29 #include "platform/Length.h" |
| 30 #include "platform/PlatformInstrumentation.h" | 30 #include "platform/PlatformInstrumentation.h" |
| 31 #include "platform/RuntimeEnabledFeatures.h" | 31 #include "platform/RuntimeEnabledFeatures.h" |
| 32 #include "platform/SharedBuffer.h" | 32 #include "platform/SharedBuffer.h" |
| 33 #include "platform/geometry/FloatPoint.h" | 33 #include "platform/geometry/FloatPoint.h" |
| 34 #include "platform/geometry/FloatRect.h" | 34 #include "platform/geometry/FloatRect.h" |
| 35 #include "platform/geometry/FloatSize.h" | 35 #include "platform/geometry/FloatSize.h" |
| 36 #include "platform/graphics/BitmapImage.h" | 36 #include "platform/graphics/BitmapImage.h" |
| 37 #include "platform/graphics/DeferredImageDecoder.h" | 37 #include "platform/graphics/DeferredImageDecoder.h" |
| 38 #include "platform/graphics/GraphicsContext.h" | 38 #include "platform/graphics/GraphicsContext.h" |
| 39 #include "platform/graphics/paint/PaintRecorder.h" |
| 40 #include "platform/graphics/paint/PaintShader.h" |
| 39 #include "platform/instrumentation/tracing/TraceEvent.h" | 41 #include "platform/instrumentation/tracing/TraceEvent.h" |
| 40 #include "platform/network/mime/MIMETypeRegistry.h" | 42 #include "platform/network/mime/MIMETypeRegistry.h" |
| 41 #include "public/platform/Platform.h" | 43 #include "public/platform/Platform.h" |
| 42 #include "public/platform/WebData.h" | 44 #include "public/platform/WebData.h" |
| 43 #include "third_party/skia/include/core/SkCanvas.h" | |
| 44 #include "third_party/skia/include/core/SkImage.h" | 45 #include "third_party/skia/include/core/SkImage.h" |
| 45 #include "third_party/skia/include/core/SkPictureRecorder.h" | |
| 46 #include "wtf/StdLibExtras.h" | 46 #include "wtf/StdLibExtras.h" |
| 47 | 47 |
| 48 #include <math.h> | 48 #include <math.h> |
| 49 #include <tuple> | 49 #include <tuple> |
| 50 | 50 |
| 51 namespace blink { | 51 namespace blink { |
| 52 | 52 |
| 53 Image::Image(ImageObserver* observer) | 53 Image::Image(ImageObserver* observer) |
| 54 : m_imageObserver(observer), m_imageObserverDisabled(false) {} | 54 : m_imageObserver(observer), m_imageObserverDisabled(false) {} |
| 55 | 55 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 } else { | 215 } else { |
| 216 drawPattern(ctxt, srcRect, tileScaleFactor, patternPhase, op, dstRect, | 216 drawPattern(ctxt, srcRect, tileScaleFactor, patternPhase, op, dstRect, |
| 217 spacing); | 217 spacing); |
| 218 } | 218 } |
| 219 | 219 |
| 220 startAnimation(); | 220 startAnimation(); |
| 221 } | 221 } |
| 222 | 222 |
| 223 namespace { | 223 namespace { |
| 224 | 224 |
| 225 sk_sp<SkShader> createPatternShader(const SkImage* image, | 225 sk_sp<PaintShader> createPatternShader(const SkImage* image, |
| 226 const SkMatrix& shaderMatrix, | 226 const SkMatrix& shaderMatrix, |
| 227 const SkPaint& paint, | 227 const SkPaint& paint, |
| 228 const FloatSize& spacing, | 228 const FloatSize& spacing, |
| 229 SkShader::TileMode tmx, | 229 SkShader::TileMode tmx, |
| 230 SkShader::TileMode tmy) { | 230 SkShader::TileMode tmy) { |
| 231 if (spacing.isZero()) | 231 if (spacing.isZero()) |
| 232 return image->makeShader(tmx, tmy, &shaderMatrix); | 232 return MakePaintShaderImage(image, tmx, tmy, &shaderMatrix); |
| 233 | 233 |
| 234 // Arbitrary tiling is currently only supported for SkPictureShader, so we use | 234 // Arbitrary tiling is currently only supported for SkPictureShader, so we use |
| 235 // that instead of a plain bitmap shader to implement spacing. | 235 // that instead of a plain bitmap shader to implement spacing. |
| 236 const SkRect tileRect = SkRect::MakeWH(image->width() + spacing.width(), | 236 const SkRect tileRect = SkRect::MakeWH(image->width() + spacing.width(), |
| 237 image->height() + spacing.height()); | 237 image->height() + spacing.height()); |
| 238 | 238 |
| 239 SkPictureRecorder recorder; | 239 PaintRecorder recorder; |
| 240 SkCanvas* canvas = recorder.beginRecording(tileRect); | 240 PaintCanvas* canvas = recorder.beginRecording(tileRect); |
| 241 canvas->drawImage(image, 0, 0, &paint); | 241 canvas->drawImage(image, 0, 0, &paint); |
| 242 | 242 |
| 243 return SkShader::MakePictureShader(recorder.finishRecordingAsPicture(), tmx, | 243 return MakePaintShaderRecord(recorder.finishRecordingAsPicture(), tmx, tmy, |
| 244 tmy, &shaderMatrix, nullptr); | 244 &shaderMatrix, nullptr); |
| 245 } | 245 } |
| 246 | 246 |
| 247 SkShader::TileMode computeTileMode(float left, | 247 SkShader::TileMode computeTileMode(float left, |
| 248 float right, | 248 float right, |
| 249 float min, | 249 float min, |
| 250 float max) { | 250 float max) { |
| 251 DCHECK(left < right); | 251 DCHECK(left < right); |
| 252 return left >= min && right <= max ? SkShader::kClamp_TileMode | 252 return left >= min && right <= max ? SkShader::kClamp_TileMode |
| 253 : SkShader::kRepeat_TileMode; | 253 : SkShader::kRepeat_TileMode; |
| 254 } | 254 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 | 297 |
| 298 const FloatSize tileSize( | 298 const FloatSize tileSize( |
| 299 image->width() * scale.width() + repeatSpacing.width(), | 299 image->width() * scale.width() + repeatSpacing.width(), |
| 300 image->height() * scale.height() + repeatSpacing.height()); | 300 image->height() * scale.height() + repeatSpacing.height()); |
| 301 const auto tmx = computeTileMode(destRect.x(), destRect.maxX(), adjustedX, | 301 const auto tmx = computeTileMode(destRect.x(), destRect.maxX(), adjustedX, |
| 302 adjustedX + tileSize.width()); | 302 adjustedX + tileSize.width()); |
| 303 const auto tmy = computeTileMode(destRect.y(), destRect.maxY(), adjustedY, | 303 const auto tmy = computeTileMode(destRect.y(), destRect.maxY(), adjustedY, |
| 304 adjustedY + tileSize.height()); | 304 adjustedY + tileSize.height()); |
| 305 | 305 |
| 306 { | 306 { |
| 307 SkPaint paint = context.fillPaint(); | 307 PaintFlags paint = context.fillPaint(); |
| 308 paint.setColor(SK_ColorBLACK); | 308 paint.setColor(SK_ColorBLACK); |
| 309 paint.setBlendMode(compositeOp); | 309 paint.setBlendMode(compositeOp); |
| 310 paint.setFilterQuality( | 310 paint.setFilterQuality( |
| 311 context.computeFilterQuality(this, destRect, normSrcRect)); | 311 context.computeFilterQuality(this, destRect, normSrcRect)); |
| 312 paint.setAntiAlias(context.shouldAntialias()); | 312 paint.setAntiAlias(context.shouldAntialias()); |
| 313 paint.setShader( | 313 paint.setShader( |
| 314 createPatternShader(image.get(), localMatrix, paint, | 314 createPatternShader(image.get(), localMatrix, paint, |
| 315 FloatSize(repeatSpacing.width() / scale.width(), | 315 FloatSize(repeatSpacing.width() / scale.width(), |
| 316 repeatSpacing.height() / scale.height()), | 316 repeatSpacing.height() / scale.height()), |
| 317 tmx, tmy)); | 317 tmx, tmy)); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 FloatRect subset = dest; | 374 FloatRect subset = dest; |
| 375 subset.setX((dest.x() - tile.x()) / scale.width()); | 375 subset.setX((dest.x() - tile.x()) / scale.width()); |
| 376 subset.setY((dest.y() - tile.y()) / scale.height()); | 376 subset.setY((dest.y() - tile.y()) / scale.height()); |
| 377 subset.setWidth(dest.width() / scale.width()); | 377 subset.setWidth(dest.width() / scale.width()); |
| 378 subset.setHeight(dest.height() / scale.height()); | 378 subset.setHeight(dest.height() / scale.height()); |
| 379 | 379 |
| 380 return subset; | 380 return subset; |
| 381 } | 381 } |
| 382 | 382 |
| 383 } // namespace blink | 383 } // namespace blink |
| OLD | NEW |