| 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 24 matching lines...) Expand all Loading... |
| 35 #include "platform/geometry/FloatRect.h" | 35 #include "platform/geometry/FloatRect.h" |
| 36 #include "platform/geometry/FloatSize.h" | 36 #include "platform/geometry/FloatSize.h" |
| 37 #include "platform/graphics/BitmapImage.h" | 37 #include "platform/graphics/BitmapImage.h" |
| 38 #include "platform/graphics/DeferredImageDecoder.h" | 38 #include "platform/graphics/DeferredImageDecoder.h" |
| 39 #include "platform/graphics/GraphicsContext.h" | 39 #include "platform/graphics/GraphicsContext.h" |
| 40 #include "platform/tracing/TraceEvent.h" | 40 #include "platform/tracing/TraceEvent.h" |
| 41 #include "public/platform/Platform.h" | 41 #include "public/platform/Platform.h" |
| 42 #include "public/platform/WebData.h" | 42 #include "public/platform/WebData.h" |
| 43 #include "third_party/skia/include/core/SkCanvas.h" | 43 #include "third_party/skia/include/core/SkCanvas.h" |
| 44 #include "third_party/skia/include/core/SkImage.h" | 44 #include "third_party/skia/include/core/SkImage.h" |
| 45 #include "third_party/skia/include/core/SkPictureRecorder.h" | 45 #include "skia/ext/cdl_picture_recorder.h" |
| 46 #include "skia/ext/cdl_shader.h" |
| 46 #include "wtf/StdLibExtras.h" | 47 #include "wtf/StdLibExtras.h" |
| 47 | 48 |
| 48 #include <math.h> | 49 #include <math.h> |
| 49 #include <tuple> | 50 #include <tuple> |
| 50 | 51 |
| 51 namespace blink { | 52 namespace blink { |
| 52 | 53 |
| 53 Image::Image(ImageObserver* observer) | 54 Image::Image(ImageObserver* observer) |
| 54 : m_imageObserver(observer), m_imageObserverDisabled(false) {} | 55 : m_imageObserver(observer), m_imageObserverDisabled(false) {} |
| 55 | 56 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 } else { | 216 } else { |
| 216 drawPattern(ctxt, srcRect, tileScaleFactor, patternPhase, op, dstRect, | 217 drawPattern(ctxt, srcRect, tileScaleFactor, patternPhase, op, dstRect, |
| 217 spacing); | 218 spacing); |
| 218 } | 219 } |
| 219 | 220 |
| 220 startAnimation(); | 221 startAnimation(); |
| 221 } | 222 } |
| 222 | 223 |
| 223 namespace { | 224 namespace { |
| 224 | 225 |
| 225 sk_sp<SkShader> createPatternShader(const SkImage* image, | 226 sk_sp<CdlShader> createPatternShader(const SkImage* image, |
| 226 const SkMatrix& shaderMatrix, | 227 const SkMatrix& shaderMatrix, |
| 227 const SkPaint& paint, | 228 const CdlPaint& paint, |
| 228 const FloatSize& spacing) { | 229 const FloatSize& spacing) { |
| 229 if (spacing.isZero()) | 230 if (spacing.isZero()) |
| 230 return image->makeShader(SkShader::kRepeat_TileMode, | 231 return MakeCdlImageShader(sk_ref_sp(const_cast<SkImage*>(image)), |
| 231 SkShader::kRepeat_TileMode, &shaderMatrix); | 232 SkShader::kRepeat_TileMode, |
| 233 SkShader::kRepeat_TileMode, &shaderMatrix); |
| 232 | 234 |
| 233 // Arbitrary tiling is currently only supported for SkPictureShader, so we use | 235 // Arbitrary tiling is currently only supported for SkPictureShader, so we use |
| 234 // that instead of a plain bitmap shader to implement spacing. | 236 // that instead of a plain bitmap shader to implement spacing. |
| 235 const SkRect tileRect = SkRect::MakeWH(image->width() + spacing.width(), | 237 const SkRect tileRect = SkRect::MakeWH(image->width() + spacing.width(), |
| 236 image->height() + spacing.height()); | 238 image->height() + spacing.height()); |
| 237 | 239 |
| 238 SkPictureRecorder recorder; | 240 CdlPictureRecorder recorder; |
| 239 SkCanvas* canvas = recorder.beginRecording(tileRect); | 241 CdlCanvas* canvas = recorder.beginRecording(tileRect); |
| 240 canvas->drawImage(image, 0, 0, &paint); | 242 canvas->drawImage(image, 0, 0, &paint); |
| 241 | 243 |
| 242 return SkShader::MakePictureShader( | 244 return CdlShader::MakePictureShader( |
| 243 recorder.finishRecordingAsPicture(), SkShader::kRepeat_TileMode, | 245 recorder.finishRecordingAsPicture(), SkShader::kRepeat_TileMode, |
| 244 SkShader::kRepeat_TileMode, &shaderMatrix, nullptr); | 246 SkShader::kRepeat_TileMode, &shaderMatrix, nullptr); |
| 245 } | 247 } |
| 246 | 248 |
| 247 } // anonymous namespace | 249 } // anonymous namespace |
| 248 | 250 |
| 249 void Image::drawPattern(GraphicsContext& context, | 251 void Image::drawPattern(GraphicsContext& context, |
| 250 const FloatRect& floatSrcRect, | 252 const FloatRect& floatSrcRect, |
| 251 const FloatSize& scale, | 253 const FloatSize& scale, |
| 252 const FloatPoint& phase, | 254 const FloatPoint& phase, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 280 localMatrix.preScale(scale.width(), scale.height()); | 282 localMatrix.preScale(scale.width(), scale.height()); |
| 281 | 283 |
| 282 // Fetch this now as subsetting may swap the image. | 284 // Fetch this now as subsetting may swap the image. |
| 283 auto imageID = image->uniqueID(); | 285 auto imageID = image->uniqueID(); |
| 284 | 286 |
| 285 image = image->makeSubset(enclosingIntRect(normSrcRect)); | 287 image = image->makeSubset(enclosingIntRect(normSrcRect)); |
| 286 if (!image) | 288 if (!image) |
| 287 return; | 289 return; |
| 288 | 290 |
| 289 { | 291 { |
| 290 SkPaint paint = context.fillPaint(); | 292 CdlPaint paint = context.fillPaint(); |
| 291 paint.setColor(SK_ColorBLACK); | 293 paint.setColor(SK_ColorBLACK); |
| 292 paint.setBlendMode(compositeOp); | 294 paint.setBlendMode(compositeOp); |
| 293 paint.setFilterQuality( | 295 paint.setFilterQuality( |
| 294 context.computeFilterQuality(this, destRect, normSrcRect)); | 296 context.computeFilterQuality(this, destRect, normSrcRect)); |
| 295 paint.setAntiAlias(context.shouldAntialias()); | 297 paint.setAntiAlias(context.shouldAntialias()); |
| 296 paint.setShader(createPatternShader( | 298 paint.setShader(createPatternShader( |
| 297 image.get(), localMatrix, paint, | 299 image.get(), localMatrix, paint, |
| 298 FloatSize(repeatSpacing.width() / scale.width(), | 300 FloatSize(repeatSpacing.width() / scale.width(), |
| 299 repeatSpacing.height() / scale.height()))); | 301 repeatSpacing.height() / scale.height()))); |
| 300 context.drawRect(destRect, paint); | 302 context.drawRect(destRect, paint); |
| 301 } | 303 } |
| 302 | 304 |
| 303 if (currentFrameIsLazyDecoded()) | 305 if (currentFrameIsLazyDecoded()) |
| 304 PlatformInstrumentation::didDrawLazyPixelRef(imageID); | 306 PlatformInstrumentation::didDrawLazyPixelRef(imageID); |
| 305 } | 307 } |
| 306 | 308 |
| 307 PassRefPtr<Image> Image::imageForDefaultFrame() { | 309 PassRefPtr<Image> Image::imageForDefaultFrame() { |
| 308 RefPtr<Image> image(this); | 310 RefPtr<Image> image(this); |
| 309 | 311 |
| 310 return image.release(); | 312 return image.release(); |
| 311 } | 313 } |
| 312 | 314 |
| 313 bool Image::isTextureBacked() { | 315 bool Image::isTextureBacked() { |
| 314 sk_sp<SkImage> image = imageForCurrentFrame(); | 316 sk_sp<SkImage> image = imageForCurrentFrame(); |
| 315 return image ? image->isTextureBacked() : false; | 317 return image ? image->isTextureBacked() : false; |
| 316 } | 318 } |
| 317 | 319 |
| 318 bool Image::applyShader(SkPaint& paint, const SkMatrix& localMatrix) { | 320 bool Image::applyShader(CdlPaint& paint, const SkMatrix& localMatrix) { |
| 319 // Default shader impl: attempt to build a shader based on the current frame | 321 // Default shader impl: attempt to build a shader based on the current frame |
| 320 // SkImage. | 322 // SkImage. |
| 321 sk_sp<SkImage> image = imageForCurrentFrame(); | 323 sk_sp<SkImage> image = imageForCurrentFrame(); |
| 322 if (!image) | 324 if (!image) |
| 323 return false; | 325 return false; |
| 324 | 326 |
| 325 paint.setShader(image->makeShader(SkShader::kRepeat_TileMode, | 327 paint.setShader(MakeCdlImageShader(image, SkShader::kRepeat_TileMode, |
| 326 SkShader::kRepeat_TileMode, &localMatrix)); | 328 SkShader::kRepeat_TileMode, &localMatrix)); |
| 327 | 329 |
| 328 // Animation is normally refreshed in draw() impls, which we don't call when | 330 // Animation is normally refreshed in draw() impls, which we don't call when |
| 329 // painting via shaders. | 331 // painting via shaders. |
| 330 startAnimation(); | 332 startAnimation(); |
| 331 | 333 |
| 332 return true; | 334 return true; |
| 333 } | 335 } |
| 334 | 336 |
| 335 FloatRect Image::computeTileContaining(const FloatPoint& point, | 337 FloatRect Image::computeTileContaining(const FloatPoint& point, |
| 336 const FloatSize& tileSize, | 338 const FloatSize& tileSize, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 359 FloatRect subset = dest; | 361 FloatRect subset = dest; |
| 360 subset.setX((dest.x() - tile.x()) / scale.width()); | 362 subset.setX((dest.x() - tile.x()) / scale.width()); |
| 361 subset.setY((dest.y() - tile.y()) / scale.height()); | 363 subset.setY((dest.y() - tile.y()) / scale.height()); |
| 362 subset.setWidth(dest.width() / scale.width()); | 364 subset.setWidth(dest.width() / scale.width()); |
| 363 subset.setHeight(dest.height() / scale.height()); | 365 subset.setHeight(dest.height() / scale.height()); |
| 364 | 366 |
| 365 return subset; | 367 return subset; |
| 366 } | 368 } |
| 367 | 369 |
| 368 } // namespace blink | 370 } // namespace blink |
| OLD | NEW |