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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/ImageBuffer.cpp

Issue 2362363002: Cancel GPU acceleration for 2D canvas when drawing very large images (Closed)
Patch Set: fix sqrt Created 4 years, 2 months 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
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/ExpensiveCanvasHeuristicParameters.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2008, Google Inc. All rights reserved. 2 * Copyright (c) 2008, Google Inc. All rights reserved.
3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> 3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. 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 are 7 * modification, are permitted provided that the following conditions are
8 * met: 8 * met:
9 * 9 *
10 * * Redistributions of source code must retain the above copyright 10 * * Redistributions of source code must retain the above copyright
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 } 431 }
432 432
433 virtual ~UnacceleratedSurfaceFactory() { } 433 virtual ~UnacceleratedSurfaceFactory() { }
434 }; 434 };
435 435
436 void ImageBuffer::disableAcceleration() 436 void ImageBuffer::disableAcceleration()
437 { 437 {
438 if (!isAccelerated()) 438 if (!isAccelerated())
439 return; 439 return;
440 440
441 // Get current frame. 441 sk_sp<SkImage> image = m_surface->newImageSnapshot(PreferNoAcceleration, Sna pshotReasonPaint);
442 SkImage* image = m_surface->newImageSnapshot(PreferNoAcceleration, SnapshotR easonPaint).get(); 442 // Using a GPU-backed image with RecordingImageBufferSurface
443 // will fail at playback time.
444 image = image->makeNonTextureImage();
443 445
444 // Create and configure a recording (unaccelerated) surface. 446 // Create and configure a recording (unaccelerated) surface.
445 std::unique_ptr<RecordingImageBufferFallbackSurfaceFactory> surfaceFactory = wrapUnique(new UnacceleratedSurfaceFactory()); 447 std::unique_ptr<RecordingImageBufferFallbackSurfaceFactory> surfaceFactory = wrapUnique(new UnacceleratedSurfaceFactory());
446 std::unique_ptr<ImageBufferSurface> surface = wrapUnique(new RecordingImageB ufferSurface(m_surface->size(), std::move(surfaceFactory), m_surface->getOpacity Mode(), m_surface->colorSpace())); 448 std::unique_ptr<ImageBufferSurface> surface = wrapUnique(new RecordingImageB ufferSurface(m_surface->size(), std::move(surfaceFactory), m_surface->getOpacity Mode(), m_surface->colorSpace()));
447 surface->canvas()->drawImage(image, 0, 0); 449 surface->canvas()->drawImage(image.get(), 0, 0);
448 surface->setImageBuffer(this); 450 surface->setImageBuffer(this);
449 451 if (m_client)
450 // Replace the current surface with the new surface. 452 m_client->restoreCanvasMatrixClipStack(surface->canvas());
451 m_surface = std::move(surface); 453 m_surface = std::move(surface);
452 454
453 didDisableAcceleration(); 455 didDisableAcceleration();
454 } 456 }
455 457
456 bool ImageDataBuffer::encodeImage(const String& mimeType, const double& quality, Vector<unsigned char>* encodedImage) const 458 bool ImageDataBuffer::encodeImage(const String& mimeType, const double& quality, Vector<unsigned char>* encodedImage) const
457 { 459 {
458 if (mimeType == "image/jpeg") { 460 if (mimeType == "image/jpeg") {
459 if (!JPEGImageEncoder::encode(*this, quality, encodedImage)) 461 if (!JPEGImageEncoder::encode(*this, quality, encodedImage))
460 return false; 462 return false;
(...skipping 17 matching lines...) Expand all
478 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); 480 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
479 481
480 Vector<unsigned char> result; 482 Vector<unsigned char> result;
481 if (!encodeImage(mimeType, quality, &result)) 483 if (!encodeImage(mimeType, quality, &result))
482 return "data:,"; 484 return "data:,";
483 485
484 return "data:" + mimeType + ";base64," + base64Encode(result); 486 return "data:" + mimeType + ";base64," + base64Encode(result);
485 } 487 }
486 488
487 } // namespace blink 489 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/ExpensiveCanvasHeuristicParameters.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698