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

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

Issue 2212163002: Add some plumbing for the color management of canvases (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase again Created 4 years, 4 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
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 67
68 namespace blink { 68 namespace blink {
69 69
70 std::unique_ptr<ImageBuffer> ImageBuffer::create(std::unique_ptr<ImageBufferSurf ace> surface) 70 std::unique_ptr<ImageBuffer> ImageBuffer::create(std::unique_ptr<ImageBufferSurf ace> surface)
71 { 71 {
72 if (!surface->isValid()) 72 if (!surface->isValid())
73 return nullptr; 73 return nullptr;
74 return wrapUnique(new ImageBuffer(std::move(surface))); 74 return wrapUnique(new ImageBuffer(std::move(surface)));
75 } 75 }
76 76
77 std::unique_ptr<ImageBuffer> ImageBuffer::create(const IntSize& size, OpacityMod e opacityMode, ImageInitializationMode initializationMode) 77 std::unique_ptr<ImageBuffer> ImageBuffer::create(const IntSize& size, OpacityMod e opacityMode, ImageInitializationMode initializationMode, sk_sp<SkColorSpace> c olorSpace)
78 { 78 {
79 std::unique_ptr<ImageBufferSurface> surface(wrapUnique(new UnacceleratedImag eBufferSurface(size, opacityMode, initializationMode))); 79 std::unique_ptr<ImageBufferSurface> surface(wrapUnique(new UnacceleratedImag eBufferSurface(size, opacityMode, initializationMode, std::move(colorSpace))));
80 if (!surface->isValid()) 80 if (!surface->isValid())
81 return nullptr; 81 return nullptr;
82 return wrapUnique(new ImageBuffer(std::move(surface))); 82 return wrapUnique(new ImageBuffer(std::move(surface)));
83 } 83 }
84 84
85 ImageBuffer::ImageBuffer(std::unique_ptr<ImageBufferSurface> surface) 85 ImageBuffer::ImageBuffer(std::unique_ptr<ImageBufferSurface> surface)
86 : m_weakPtrFactory(this) 86 : m_weakPtrFactory(this)
87 , m_snapshotState(InitialSnapshotState) 87 , m_snapshotState(InitialSnapshotState)
88 , m_surface(std::move(surface)) 88 , m_surface(std::move(surface))
89 , m_client(0) 89 , m_client(0)
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 // the GPU memory usage needs to be updated too. 418 // the GPU memory usage needs to be updated too.
419 DCHECK_GT(s_globalAcceleratedImageBufferCount, 0u); 419 DCHECK_GT(s_globalAcceleratedImageBufferCount, 0u);
420 s_globalAcceleratedImageBufferCount--; 420 s_globalAcceleratedImageBufferCount--;
421 s_globalGPUMemoryUsage -= m_gpuMemoryUsage; 421 s_globalGPUMemoryUsage -= m_gpuMemoryUsage;
422 m_gpuMemoryUsage = 0; 422 m_gpuMemoryUsage = 0;
423 } 423 }
424 } 424 }
425 425
426 class UnacceleratedSurfaceFactory : public RecordingImageBufferFallbackSurfaceFa ctory { 426 class UnacceleratedSurfaceFactory : public RecordingImageBufferFallbackSurfaceFa ctory {
427 public: 427 public:
428 virtual std::unique_ptr<ImageBufferSurface> createSurface(const IntSize& siz e, OpacityMode opacityMode) 428 virtual std::unique_ptr<ImageBufferSurface> createSurface(const IntSize& siz e, OpacityMode opacityMode, sk_sp<SkColorSpace> colorSpace)
429 { 429 {
430 return wrapUnique(new UnacceleratedImageBufferSurface(size, opacityMode) ); 430 return wrapUnique(new UnacceleratedImageBufferSurface(size, opacityMode, InitializeImagePixels, colorSpace));
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 // Get current frame.
442 SkImage* image = m_surface->newImageSnapshot(PreferNoAcceleration, SnapshotR easonPaint).get(); 442 SkImage* image = m_surface->newImageSnapshot(PreferNoAcceleration, SnapshotR easonPaint).get();
443 443
444 // Create and configure a recording (unaccelerated) surface. 444 // Create and configure a recording (unaccelerated) surface.
445 std::unique_ptr<RecordingImageBufferFallbackSurfaceFactory> surfaceFactory = wrapUnique(new UnacceleratedSurfaceFactory()); 445 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())); 446 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); 447 surface->canvas()->drawImage(image, 0, 0);
448 surface->setImageBuffer(this); 448 surface->setImageBuffer(this);
449 449
450 // Replace the current surface with the new surface. 450 // Replace the current surface with the new surface.
451 m_surface = std::move(surface); 451 m_surface = std::move(surface);
452 452
453 didDisableAcceleration(); 453 didDisableAcceleration();
454 } 454 }
455 455
456 bool ImageDataBuffer::encodeImage(const String& mimeType, const double& quality, Vector<unsigned char>* encodedImage) const 456 bool ImageDataBuffer::encodeImage(const String& mimeType, const double& quality, Vector<unsigned char>* encodedImage) const
(...skipping 21 matching lines...) Expand all
478 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); 478 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
479 479
480 Vector<unsigned char> result; 480 Vector<unsigned char> result;
481 if (!encodeImage(mimeType, quality, &result)) 481 if (!encodeImage(mimeType, quality, &result))
482 return "data:,"; 482 return "data:,";
483 483
484 return "data:" + mimeType + ";base64," + base64Encode(result); 484 return "data:" + mimeType + ";base64," + base64Encode(result);
485 } 485 }
486 486
487 } // namespace blink 487 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698