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

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: minor corrections 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 66
67 namespace blink { 67 namespace blink {
68 68
69 std::unique_ptr<ImageBuffer> ImageBuffer::create(std::unique_ptr<ImageBufferSurf ace> surface) 69 std::unique_ptr<ImageBuffer> ImageBuffer::create(std::unique_ptr<ImageBufferSurf ace> surface)
70 { 70 {
71 if (!surface->isValid()) 71 if (!surface->isValid())
72 return nullptr; 72 return nullptr;
73 return wrapUnique(new ImageBuffer(std::move(surface))); 73 return wrapUnique(new ImageBuffer(std::move(surface)));
74 } 74 }
75 75
76 std::unique_ptr<ImageBuffer> ImageBuffer::create(const IntSize& size, OpacityMod e opacityMode, ImageInitializationMode initializationMode) 76 std::unique_ptr<ImageBuffer> ImageBuffer::create(const IntSize& size, OpacityMod e opacityMode, ImageInitializationMode initializationMode, sk_sp<SkColorSpace> c olorSpace)
77 { 77 {
78 std::unique_ptr<ImageBufferSurface> surface(wrapUnique(new UnacceleratedImag eBufferSurface(size, opacityMode, initializationMode))); 78 std::unique_ptr<ImageBufferSurface> surface(wrapUnique(new UnacceleratedImag eBufferSurface(size, opacityMode, initializationMode, colorSpace)));
Stephen White 2016/08/11 20:41:27 Could we use std::move() here too?
Justin Novosad 2016/08/12 17:40:18 Done.
79 if (!surface->isValid()) 79 if (!surface->isValid())
80 return nullptr; 80 return nullptr;
81 return wrapUnique(new ImageBuffer(std::move(surface))); 81 return wrapUnique(new ImageBuffer(std::move(surface)));
82 } 82 }
83 83
84 ImageBuffer::ImageBuffer(std::unique_ptr<ImageBufferSurface> surface) 84 ImageBuffer::ImageBuffer(std::unique_ptr<ImageBufferSurface> surface)
85 : m_weakPtrFactory(this) 85 : m_weakPtrFactory(this)
86 , m_snapshotState(InitialSnapshotState) 86 , m_snapshotState(InitialSnapshotState)
87 , m_surface(std::move(surface)) 87 , m_surface(std::move(surface))
88 , m_client(0) 88 , m_client(0)
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 // the GPU memory usage needs to be updated too. 404 // the GPU memory usage needs to be updated too.
405 DCHECK_GT(s_globalAcceleratedImageBufferCount, 0u); 405 DCHECK_GT(s_globalAcceleratedImageBufferCount, 0u);
406 s_globalAcceleratedImageBufferCount--; 406 s_globalAcceleratedImageBufferCount--;
407 s_globalGPUMemoryUsage -= m_gpuMemoryUsage; 407 s_globalGPUMemoryUsage -= m_gpuMemoryUsage;
408 m_gpuMemoryUsage = 0; 408 m_gpuMemoryUsage = 0;
409 } 409 }
410 } 410 }
411 411
412 class UnacceleratedSurfaceFactory : public RecordingImageBufferFallbackSurfaceFa ctory { 412 class UnacceleratedSurfaceFactory : public RecordingImageBufferFallbackSurfaceFa ctory {
413 public: 413 public:
414 virtual std::unique_ptr<ImageBufferSurface> createSurface(const IntSize& siz e, OpacityMode opacityMode) 414 virtual std::unique_ptr<ImageBufferSurface> createSurface(const IntSize& siz e, OpacityMode opacityMode, sk_sp<SkColorSpace> colorSpace)
415 { 415 {
416 return wrapUnique(new UnacceleratedImageBufferSurface(size, opacityMode) ); 416 return wrapUnique(new UnacceleratedImageBufferSurface(size, opacityMode, InitializeImagePixels, colorSpace));
417 } 417 }
418 418
419 virtual ~UnacceleratedSurfaceFactory() { } 419 virtual ~UnacceleratedSurfaceFactory() { }
420 }; 420 };
421 421
422 void ImageBuffer::disableAcceleration() 422 void ImageBuffer::disableAcceleration()
423 { 423 {
424 if (!isAccelerated()) 424 if (!isAccelerated())
425 return; 425 return;
426 426
427 // Get current frame. 427 // Get current frame.
428 SkImage* image = m_surface->newImageSnapshot(PreferNoAcceleration, SnapshotR easonPaint).get(); 428 SkImage* image = m_surface->newImageSnapshot(PreferNoAcceleration, SnapshotR easonPaint).get();
429 429
430 // Create and configure a recording (unaccelerated) surface. 430 // Create and configure a recording (unaccelerated) surface.
431 std::unique_ptr<RecordingImageBufferFallbackSurfaceFactory> surfaceFactory = wrapUnique(new UnacceleratedSurfaceFactory()); 431 std::unique_ptr<RecordingImageBufferFallbackSurfaceFactory> surfaceFactory = wrapUnique(new UnacceleratedSurfaceFactory());
432 std::unique_ptr<ImageBufferSurface> surface = wrapUnique(new RecordingImageB ufferSurface(m_surface->size(), std::move(surfaceFactory), m_surface->getOpacity Mode())); 432 std::unique_ptr<ImageBufferSurface> surface = wrapUnique(new RecordingImageB ufferSurface(m_surface->size(), std::move(surfaceFactory), m_surface->getOpacity Mode(), m_surface->colorSpace()));
433 surface->canvas()->drawImage(image, 0, 0); 433 surface->canvas()->drawImage(image, 0, 0);
434 surface->setImageBuffer(this); 434 surface->setImageBuffer(this);
435 435
436 // Replace the current surface with the new surface. 436 // Replace the current surface with the new surface.
437 m_surface = std::move(surface); 437 m_surface = std::move(surface);
438 438
439 didDisableAcceleration(); 439 didDisableAcceleration();
440 } 440 }
441 441
442 bool ImageDataBuffer::encodeImage(const String& mimeType, const double& quality, Vector<unsigned char>* encodedImage) const 442 bool ImageDataBuffer::encodeImage(const String& mimeType, const double& quality, Vector<unsigned char>* encodedImage) const
(...skipping 21 matching lines...) Expand all
464 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); 464 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
465 465
466 Vector<unsigned char> result; 466 Vector<unsigned char> result;
467 if (!encodeImage(mimeType, quality, &result)) 467 if (!encodeImage(mimeType, quality, &result))
468 return "data:,"; 468 return "data:,";
469 469
470 return "data:" + mimeType + ";base64," + base64Encode(result); 470 return "data:" + mimeType + ";base64," + base64Encode(result);
471 } 471 }
472 472
473 } // namespace blink 473 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698