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

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: 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)));
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 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 // the GPU memory usage needs to be updated too. 401 // the GPU memory usage needs to be updated too.
402 DCHECK_GT(s_globalAcceleratedImageBufferCount, 0u); 402 DCHECK_GT(s_globalAcceleratedImageBufferCount, 0u);
403 s_globalAcceleratedImageBufferCount--; 403 s_globalAcceleratedImageBufferCount--;
404 s_globalGPUMemoryUsage -= m_gpuMemoryUsage; 404 s_globalGPUMemoryUsage -= m_gpuMemoryUsage;
405 m_gpuMemoryUsage = 0; 405 m_gpuMemoryUsage = 0;
406 } 406 }
407 } 407 }
408 408
409 class UnacceleratedSurfaceFactory : public RecordingImageBufferFallbackSurfaceFa ctory { 409 class UnacceleratedSurfaceFactory : public RecordingImageBufferFallbackSurfaceFa ctory {
410 public: 410 public:
411 virtual std::unique_ptr<ImageBufferSurface> createSurface(const IntSize& siz e, OpacityMode opacityMode) 411 virtual std::unique_ptr<ImageBufferSurface> createSurface(const IntSize& siz e, OpacityMode opacityMode, sk_sp<SkColorSpace> colorSpace)
412 { 412 {
413 return wrapUnique(new UnacceleratedImageBufferSurface(size, opacityMode) ); 413 return wrapUnique(new UnacceleratedImageBufferSurface(size, opacityMode, InitializeImagePixels, colorSpace));
414 } 414 }
415 415
416 virtual ~UnacceleratedSurfaceFactory() { } 416 virtual ~UnacceleratedSurfaceFactory() { }
417 }; 417 };
418 418
419 void ImageBuffer::disableAcceleration() 419 void ImageBuffer::disableAcceleration()
420 { 420 {
421 if (!isAccelerated()) 421 if (!isAccelerated())
422 return; 422 return;
423 423
424 // Get current frame. 424 // Get current frame.
425 SkImage* image = m_surface->newImageSnapshot(PreferNoAcceleration, SnapshotR easonPaint).get(); 425 SkImage* image = m_surface->newImageSnapshot(PreferNoAcceleration, SnapshotR easonPaint).get();
426 426
427 // Create and configure a recording (unaccelerated) surface. 427 // Create and configure a recording (unaccelerated) surface.
428 std::unique_ptr<RecordingImageBufferFallbackSurfaceFactory> surfaceFactory = wrapUnique(new UnacceleratedSurfaceFactory()); 428 std::unique_ptr<RecordingImageBufferFallbackSurfaceFactory> surfaceFactory = wrapUnique(new UnacceleratedSurfaceFactory());
429 std::unique_ptr<ImageBufferSurface> surface = wrapUnique(new RecordingImageB ufferSurface(m_surface->size(), std::move(surfaceFactory), m_surface->getOpacity Mode())); 429 std::unique_ptr<ImageBufferSurface> surface = wrapUnique(new RecordingImageB ufferSurface(m_surface->size(), std::move(surfaceFactory), m_surface->getOpacity Mode(), m_surface->colorSpace()));
430 surface->canvas()->drawImage(image, 0, 0); 430 surface->canvas()->drawImage(image, 0, 0);
431 surface->setImageBuffer(this); 431 surface->setImageBuffer(this);
432 432
433 // Replace the current surface with the new surface. 433 // Replace the current surface with the new surface.
434 m_surface = std::move(surface); 434 m_surface = std::move(surface);
435 435
436 didDisableAcceleration(); 436 didDisableAcceleration();
437 } 437 }
438 438
439 bool ImageDataBuffer::encodeImage(const String& mimeType, const double& quality, Vector<unsigned char>* encodedImage) const 439 bool ImageDataBuffer::encodeImage(const String& mimeType, const double& quality, Vector<unsigned char>* encodedImage) const
(...skipping 21 matching lines...) Expand all
461 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); 461 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
462 462
463 Vector<unsigned char> result; 463 Vector<unsigned char> result;
464 if (!encodeImage(mimeType, quality, &result)) 464 if (!encodeImage(mimeType, quality, &result))
465 return "data:,"; 465 return "data:,";
466 466
467 return "data:" + mimeType + ";base64," + base64Encode(result); 467 return "data:" + mimeType + ";base64," + base64Encode(result);
468 } 468 }
469 469
470 } // namespace blink 470 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698