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

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

Issue 2679323005: Update callsites to new SkColorSpace API, delete legacy flag (Closed)
Patch Set: Formatting Created 3 years, 10 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 return nullptr; 74 return nullptr;
75 return WTF::wrapUnique(new ImageBuffer(std::move(surface))); 75 return WTF::wrapUnique(new ImageBuffer(std::move(surface)));
76 } 76 }
77 77
78 std::unique_ptr<ImageBuffer> ImageBuffer::create( 78 std::unique_ptr<ImageBuffer> ImageBuffer::create(
79 const IntSize& size, 79 const IntSize& size,
80 OpacityMode opacityMode, 80 OpacityMode opacityMode,
81 ImageInitializationMode initializationMode, 81 ImageInitializationMode initializationMode,
82 sk_sp<SkColorSpace> colorSpace) { 82 sk_sp<SkColorSpace> colorSpace) {
83 SkColorType colorType = kN32_SkColorType; 83 SkColorType colorType = kN32_SkColorType;
84 if (colorSpace && 84 if (colorSpace && SkColorSpace::Equals(colorSpace.get(),
85 SkColorSpace::Equals( 85 SkColorSpace::MakeSRGBLinear().get()))
86 colorSpace.get(),
87 SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named).get()))
88 colorType = kRGBA_F16_SkColorType; 86 colorType = kRGBA_F16_SkColorType;
89 87
90 std::unique_ptr<ImageBufferSurface> surface(WTF::wrapUnique( 88 std::unique_ptr<ImageBufferSurface> surface(WTF::wrapUnique(
91 new UnacceleratedImageBufferSurface(size, opacityMode, initializationMode, 89 new UnacceleratedImageBufferSurface(size, opacityMode, initializationMode,
92 std::move(colorSpace), colorType))); 90 std::move(colorSpace), colorType)));
93 91
94 if (!surface->isValid()) 92 if (!surface->isValid())
95 return nullptr; 93 return nullptr;
96 return WTF::wrapUnique(new ImageBuffer(std::move(surface))); 94 return WTF::wrapUnique(new ImageBuffer(std::move(surface)));
97 } 95 }
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 : kUnpremul_SkAlphaType; 400 : kUnpremul_SkAlphaType;
403 // The workaround path use a canvas draw under the hood, which can only 401 // The workaround path use a canvas draw under the hood, which can only
404 // use N32 at this time. 402 // use N32 at this time.
405 SkColorType colorType = 403 SkColorType colorType =
406 useF16Workaround ? kN32_SkColorType : kRGBA_8888_SkColorType; 404 useF16Workaround ? kN32_SkColorType : kRGBA_8888_SkColorType;
407 405
408 // Only use sRGB when the surface has a color space. Converting untagged 406 // Only use sRGB when the surface has a color space. Converting untagged
409 // pixels to a particular color space is not well-defined in Skia. 407 // pixels to a particular color space is not well-defined in Skia.
410 sk_sp<SkColorSpace> colorSpace = nullptr; 408 sk_sp<SkColorSpace> colorSpace = nullptr;
411 if (m_surface->colorSpace()) { 409 if (m_surface->colorSpace()) {
412 colorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); 410 colorSpace = SkColorSpace::MakeSRGB();
413 } 411 }
414 412
415 SkImageInfo info = SkImageInfo::Make(rect.width(), rect.height(), colorType, 413 SkImageInfo info = SkImageInfo::Make(rect.width(), rect.height(), colorType,
416 alphaType, std::move(colorSpace)); 414 alphaType, std::move(colorSpace));
417 415
418 snapshot->readPixels(info, result.data(), bytesPerPixel * rect.width(), 416 snapshot->readPixels(info, result.data(), bytesPerPixel * rect.width(),
419 rect.x(), rect.y()); 417 rect.x(), rect.y());
420 418
421 if (useF16Workaround) { 419 if (useF16Workaround) {
422 uint32_t* pixel = (uint32_t*)result.data(); 420 uint32_t* pixel = (uint32_t*)result.data();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType 485 alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType
488 : kUnpremul_SkAlphaType; 486 : kUnpremul_SkAlphaType;
489 } 487 }
490 488
491 SkImageInfo info; 489 SkImageInfo info;
492 if (m_surface->colorSpace()) { 490 if (m_surface->colorSpace()) {
493 info = SkImageInfo::Make(sourceRect.width(), sourceRect.height(), 491 info = SkImageInfo::Make(sourceRect.width(), sourceRect.height(),
494 m_surface->colorType(), alphaType, 492 m_surface->colorType(), alphaType,
495 m_surface->colorSpace()); 493 m_surface->colorSpace());
496 } else { 494 } else {
497 info = SkImageInfo::Make( 495 info = SkImageInfo::Make(sourceRect.width(), sourceRect.height(),
498 sourceRect.width(), sourceRect.height(), kRGBA_8888_SkColorType, 496 kRGBA_8888_SkColorType, alphaType,
499 alphaType, SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named)); 497 SkColorSpace::MakeSRGB());
500 } 498 }
501 m_surface->writePixels(info, srcAddr, srcBytesPerRow, destX, destY); 499 m_surface->writePixels(info, srcAddr, srcBytesPerRow, destX, destY);
502 } 500 }
503 501
504 void ImageBuffer::updateGPUMemoryUsage() const { 502 void ImageBuffer::updateGPUMemoryUsage() const {
505 if (this->isAccelerated()) { 503 if (this->isAccelerated()) {
506 // If image buffer is accelerated, we should keep track of GPU memory usage. 504 // If image buffer is accelerated, we should keep track of GPU memory usage.
507 int gpuBufferCount = 2; 505 int gpuBufferCount = 2;
508 CheckedNumeric<intptr_t> checkedGPUUsage = 506 CheckedNumeric<intptr_t> checkedGPUUsage =
509 SkColorTypeBytesPerPixel(m_surface->colorType()) * gpuBufferCount; 507 SkColorTypeBytesPerPixel(m_surface->colorType()) * gpuBufferCount;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 DCHECK(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); 614 DCHECK(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
617 615
618 Vector<unsigned char> result; 616 Vector<unsigned char> result;
619 if (!encodeImage(mimeType, quality, &result)) 617 if (!encodeImage(mimeType, quality, &result))
620 return "data:,"; 618 return "data:,";
621 619
622 return "data:" + mimeType + ";base64," + base64Encode(result); 620 return "data:" + mimeType + ";base64," + base64Encode(result);
623 } 621 }
624 622
625 } // namespace blink 623 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698