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

Side by Side Diff: third_party/WebKit/Source/core/svg/graphics/SVGImage.cpp

Issue 2523673004: [NOT FOR COMMIT] Fully replace SkCanvas uses.
Patch Set: Support Android build. Created 4 years 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006 Eric Seidel <eric@webkit.org> 2 * Copyright (C) 2006 Eric Seidel <eric@webkit.org>
3 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. 3 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved.
4 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 4 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 #include "platform/ScriptForbiddenScope.h" 49 #include "platform/ScriptForbiddenScope.h"
50 #include "platform/geometry/IntRect.h" 50 #include "platform/geometry/IntRect.h"
51 #include "platform/graphics/GraphicsContext.h" 51 #include "platform/graphics/GraphicsContext.h"
52 #include "platform/graphics/ImageBuffer.h" 52 #include "platform/graphics/ImageBuffer.h"
53 #include "platform/graphics/ImageObserver.h" 53 #include "platform/graphics/ImageObserver.h"
54 #include "platform/graphics/paint/ClipRecorder.h" 54 #include "platform/graphics/paint/ClipRecorder.h"
55 #include "platform/graphics/paint/CullRect.h" 55 #include "platform/graphics/paint/CullRect.h"
56 #include "platform/graphics/paint/DrawingRecorder.h" 56 #include "platform/graphics/paint/DrawingRecorder.h"
57 #include "platform/graphics/paint/SkPictureBuilder.h" 57 #include "platform/graphics/paint/SkPictureBuilder.h"
58 #include "platform/tracing/TraceEvent.h" 58 #include "platform/tracing/TraceEvent.h"
59 #include "third_party/skia/include/core/SkPicture.h" 59 #include "skia/ext/cdl_picture.h"
60 #include "wtf/PassRefPtr.h" 60 #include "wtf/PassRefPtr.h"
61 61
62 namespace blink { 62 namespace blink {
63 63
64 SVGImage::SVGImage(ImageObserver* observer) 64 SVGImage::SVGImage(ImageObserver* observer)
65 : Image(observer), 65 : Image(observer),
66 m_paintController(PaintController::create()), 66 m_paintController(PaintController::create()),
67 m_hasPendingTimelineRewind(false) {} 67 m_hasPendingTimelineRewind(false) {}
68 68
69 SVGImage::~SVGImage() { 69 SVGImage::~SVGImage() {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 return FloatSize(solutionWidth, defaultObjectSize.height()); 220 return FloatSize(solutionWidth, defaultObjectSize.height());
221 221
222 float solutionHeight = resolveHeightForRatio( 222 float solutionHeight = resolveHeightForRatio(
223 defaultObjectSize.width(), intrinsicSizingInfo.aspectRatio); 223 defaultObjectSize.width(), intrinsicSizingInfo.aspectRatio);
224 return FloatSize(defaultObjectSize.width(), solutionHeight); 224 return FloatSize(defaultObjectSize.width(), solutionHeight);
225 } 225 }
226 226
227 return defaultObjectSize; 227 return defaultObjectSize;
228 } 228 }
229 229
230 void SVGImage::drawForContainer(SkCanvas* canvas, 230 void SVGImage::drawForContainer(CdlCanvas* canvas,
231 const SkPaint& paint, 231 const CdlPaint& paint,
232 const FloatSize containerSize, 232 const FloatSize containerSize,
233 float zoom, 233 float zoom,
234 const FloatRect& dstRect, 234 const FloatRect& dstRect,
235 const FloatRect& srcRect, 235 const FloatRect& srcRect,
236 const KURL& url) { 236 const KURL& url) {
237 if (!m_page) 237 if (!m_page)
238 return; 238 return;
239 239
240 // Temporarily disable the image observer to prevent changeInRect() calls due 240 // Temporarily disable the image observer to prevent changeInRect() calls due
241 // re-laying out the image. 241 // re-laying out the image.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 286
287 SkPictureBuilder patternPicture(spacedTile, nullptr, &context); 287 SkPictureBuilder patternPicture(spacedTile, nullptr, &context);
288 { 288 {
289 DrawingRecorder patternPictureRecorder( 289 DrawingRecorder patternPictureRecorder(
290 patternPicture.context(), patternPicture, DisplayItem::Type::kSVGImage, 290 patternPicture.context(), patternPicture, DisplayItem::Type::kSVGImage,
291 spacedTile); 291 spacedTile);
292 // When generating an expanded tile, make sure we don't draw into the 292 // When generating an expanded tile, make sure we don't draw into the
293 // spacing area. 293 // spacing area.
294 if (tile != spacedTile) 294 if (tile != spacedTile)
295 patternPicture.context().clip(tile); 295 patternPicture.context().clip(tile);
296 SkPaint paint; 296 CdlPaint paint;
297 drawForContainer(patternPicture.context().canvas(), paint, containerSize, 297 drawForContainer(patternPicture.context().canvas(), paint, containerSize,
298 zoom, tile, srcRect, url); 298 zoom, tile, srcRect, url);
299 } 299 }
300 sk_sp<SkPicture> tilePicture = patternPicture.endRecording(); 300 sk_sp<CdlPicture> tilePicture = patternPicture.endRecording();
301 301
302 SkMatrix patternTransform; 302 SkMatrix patternTransform;
303 patternTransform.setTranslate(phase.x() + spacedTile.x(), 303 patternTransform.setTranslate(phase.x() + spacedTile.x(),
304 phase.y() + spacedTile.y()); 304 phase.y() + spacedTile.y());
305 305
306 SkPaint paint; 306 CdlPaint paint;
307 paint.setShader(SkShader::MakePictureShader( 307 paint.setShader(CdlShader::MakePictureShader(
308 std::move(tilePicture), SkShader::kRepeat_TileMode, 308 tilePicture, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode,
309 SkShader::kRepeat_TileMode, &patternTransform, nullptr)); 309 &patternTransform, nullptr));
310 paint.setBlendMode(compositeOp); 310 paint.setBlendMode(compositeOp);
311 paint.setColorFilter(sk_ref_sp(context.getColorFilter())); 311 paint.setColorFilter(sk_ref_sp(context.getColorFilter()));
312 context.drawRect(dstRect, paint); 312 context.drawRect(dstRect, paint);
313 } 313 }
314 314
315 sk_sp<SkImage> SVGImage::imageForCurrentFrameForContainer( 315 sk_sp<SkImage> SVGImage::imageForCurrentFrameForContainer(
316 const KURL& url, 316 const KURL& url,
317 const IntSize& containerSize) { 317 const IntSize& containerSize) {
318 if (!m_page) 318 if (!m_page)
319 return nullptr; 319 return nullptr;
320 320
321 const FloatRect containerRect((FloatPoint()), FloatSize(containerSize)); 321 const FloatRect containerRect((FloatPoint()), FloatSize(containerSize));
322 322
323 SkPictureRecorder recorder; 323 CdlPictureRecorder recorder;
324 SkCanvas* canvas = recorder.beginRecording(containerRect); 324 CdlCanvas* canvas = recorder.beginRecording(containerRect);
325 drawForContainer(canvas, SkPaint(), containerRect.size(), 1, containerRect, 325 drawForContainer(canvas, CdlPaint(), containerRect.size(), 1, containerRect,
326 containerRect, url); 326 containerRect, url);
327 327
328 return SkImage::MakeFromPicture( 328 return SkImage::MakeFromPicture(
329 recorder.finishRecordingAsPicture(), 329 ToSkPicture(recorder.finishRecordingAsPicture().get()),
330 SkISize::Make(containerSize.width(), containerSize.height()), nullptr, 330 SkISize::Make(containerSize.width(), containerSize.height()), nullptr,
331 nullptr); 331 nullptr);
332 } 332 }
333 333
334 static bool drawNeedsLayer(const SkPaint& paint) { 334 static bool drawNeedsLayer(const CdlPaint& paint) {
335 if (SkColorGetA(paint.getColor()) < 255) 335 if (SkColorGetA(paint.getColor()) < 255)
336 return true; 336 return true;
337 return !paint.isSrcOver(); 337 return !paint.isSrcOver();
338 } 338 }
339 339
340 void SVGImage::draw(SkCanvas* canvas, 340 void SVGImage::draw(CdlCanvas* canvas,
341 const SkPaint& paint, 341 const CdlPaint& paint,
342 const FloatRect& dstRect, 342 const FloatRect& dstRect,
343 const FloatRect& srcRect, 343 const FloatRect& srcRect,
344 RespectImageOrientationEnum shouldRespectImageOrientation, 344 RespectImageOrientationEnum shouldRespectImageOrientation,
345 ImageClampingMode clampMode) { 345 ImageClampingMode clampMode) {
346 if (!m_page) 346 if (!m_page)
347 return; 347 return;
348 348
349 drawInternal(canvas, paint, dstRect, srcRect, shouldRespectImageOrientation, 349 drawInternal(canvas, paint, dstRect, srcRect, shouldRespectImageOrientation,
350 clampMode, KURL()); 350 clampMode, KURL());
351 } 351 }
352 352
353 void SVGImage::drawInternal(SkCanvas* canvas, 353 void SVGImage::drawInternal(CdlCanvas* canvas,
354 const SkPaint& paint, 354 const CdlPaint& paint,
355 const FloatRect& dstRect, 355 const FloatRect& dstRect,
356 const FloatRect& srcRect, 356 const FloatRect& srcRect,
357 RespectImageOrientationEnum, 357 RespectImageOrientationEnum,
358 ImageClampingMode, 358 ImageClampingMode,
359 const KURL& url) { 359 const KURL& url) {
360 DCHECK(m_page); 360 DCHECK(m_page);
361 FrameView* view = toLocalFrame(m_page->mainFrame())->view(); 361 FrameView* view = toLocalFrame(m_page->mainFrame())->view();
362 view->resize(containerSize()); 362 view->resize(containerSize());
363 363
364 // Always call processUrlFragment, even if the url is empty, because 364 // Always call processUrlFragment, even if the url is empty, because
(...skipping 26 matching lines...) Expand all
391 transform.scale(scale.width(), scale.height()); 391 transform.scale(scale.width(), scale.height());
392 TransformRecorder transformRecorder(imagePicture.context(), imagePicture, 392 TransformRecorder transformRecorder(imagePicture.context(), imagePicture,
393 transform); 393 transform);
394 394
395 view->updateAllLifecyclePhasesExceptPaint(); 395 view->updateAllLifecyclePhasesExceptPaint();
396 view->paint(imagePicture.context(), CullRect(enclosingIntRect(srcRect))); 396 view->paint(imagePicture.context(), CullRect(enclosingIntRect(srcRect)));
397 ASSERT(!view->needsLayout()); 397 ASSERT(!view->needsLayout());
398 } 398 }
399 399
400 { 400 {
401 SkAutoCanvasRestore ar(canvas, false); 401 CdlAutoCanvasRestore ar(canvas, false);
402 if (drawNeedsLayer(paint)) { 402 if (drawNeedsLayer(paint)) {
403 SkRect layerRect = dstRect; 403 SkRect layerRect = dstRect;
404 canvas->saveLayer(&layerRect, &paint); 404 canvas->saveLayer(&layerRect, &paint);
405 } 405 }
406 sk_sp<const SkPicture> recording = imagePicture.endRecording(); 406 sk_sp<CdlPicture> recording = imagePicture.endRecording();
407 canvas->drawPicture(recording.get()); 407 canvas->drawPicture(recording.get());
408 } 408 }
409 409
410 // Start any (SMIL) animations if needed. This will restart or continue 410 // Start any (SMIL) animations if needed. This will restart or continue
411 // animations if preceded by calls to resetAnimation or stopAnimation 411 // animations if preceded by calls to resetAnimation or stopAnimation
412 // respectively. 412 // respectively.
413 startAnimation(); 413 startAnimation();
414 } 414 }
415 415
416 LayoutReplaced* SVGImage::embeddedReplacedContent() const { 416 LayoutReplaced* SVGImage::embeddedReplacedContent() const {
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 } 619 }
620 620
621 return m_page ? SizeAvailable : SizeUnavailable; 621 return m_page ? SizeAvailable : SizeUnavailable;
622 } 622 }
623 623
624 String SVGImage::filenameExtension() const { 624 String SVGImage::filenameExtension() const {
625 return "svg"; 625 return "svg";
626 } 626 }
627 627
628 } // namespace blink 628 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698