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

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp

Issue 2425113002: Fix the linear-rgb canvas color space so that it renders (Closed)
Patch Set: 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2007 Alp Toker <alp@atoker.com> 3 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
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 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 924
925 return true; 925 return true;
926 } 926 }
927 927
928 class UnacceleratedSurfaceFactory 928 class UnacceleratedSurfaceFactory
929 : public RecordingImageBufferFallbackSurfaceFactory { 929 : public RecordingImageBufferFallbackSurfaceFactory {
930 public: 930 public:
931 virtual std::unique_ptr<ImageBufferSurface> createSurface( 931 virtual std::unique_ptr<ImageBufferSurface> createSurface(
932 const IntSize& size, 932 const IntSize& size,
933 OpacityMode opacityMode, 933 OpacityMode opacityMode,
934 sk_sp<SkColorSpace> colorSpace) { 934 sk_sp<SkColorSpace> colorSpace,
935 SkColorType colorType) {
935 return wrapUnique(new UnacceleratedImageBufferSurface( 936 return wrapUnique(new UnacceleratedImageBufferSurface(
936 size, opacityMode, InitializeImagePixels, colorSpace)); 937 size, opacityMode, InitializeImagePixels, colorSpace, colorType));
937 } 938 }
938 939
939 virtual ~UnacceleratedSurfaceFactory() {} 940 virtual ~UnacceleratedSurfaceFactory() {}
940 }; 941 };
941 942
942 bool HTMLCanvasElement::shouldUseDisplayList(const IntSize& deviceSize) { 943 bool HTMLCanvasElement::shouldUseDisplayList(const IntSize& deviceSize) {
943 if (RuntimeEnabledFeatures::forceDisplayList2dCanvasEnabled()) 944 if (RuntimeEnabledFeatures::forceDisplayList2dCanvasEnabled())
944 return true; 945 return true;
945 946
946 if (!RuntimeEnabledFeatures::displayList2dCanvasEnabled()) 947 if (!RuntimeEnabledFeatures::displayList2dCanvasEnabled())
947 return false; 948 return false;
948 949
949 return true; 950 return true;
950 } 951 }
951 952
952 std::unique_ptr<ImageBufferSurface> 953 std::unique_ptr<ImageBufferSurface>
953 HTMLCanvasElement::createWebGLImageBufferSurface( 954 HTMLCanvasElement::createWebGLImageBufferSurface(const IntSize& deviceSize,
954 const IntSize& deviceSize, 955 OpacityMode opacityMode) {
955 OpacityMode opacityMode,
956 sk_sp<SkColorSpace> colorSpace) {
957 DCHECK(is3D()); 956 DCHECK(is3D());
958 // If 3d, but the use of the canvas will be for non-accelerated content 957 // If 3d, but the use of the canvas will be for non-accelerated content
959 // then make a non-accelerated ImageBuffer. This means copying the internal 958 // then make a non-accelerated ImageBuffer. This means copying the internal
960 // Image will require a pixel readback, but that is unavoidable in this case. 959 // Image will require a pixel readback, but that is unavoidable in this case.
961 auto surface = wrapUnique(new AcceleratedImageBufferSurface( 960 auto surface = wrapUnique(new AcceleratedImageBufferSurface(
962 deviceSize, opacityMode, std::move(colorSpace))); 961 deviceSize, opacityMode, m_context->skColorSpace(),
962 m_context->colorType()));
963 if (surface->isValid()) 963 if (surface->isValid())
964 return std::move(surface); 964 return std::move(surface);
965 return nullptr; 965 return nullptr;
966 } 966 }
967 967
968 std::unique_ptr<ImageBufferSurface> 968 std::unique_ptr<ImageBufferSurface>
969 HTMLCanvasElement::createAcceleratedImageBufferSurface( 969 HTMLCanvasElement::createAcceleratedImageBufferSurface(
970 const IntSize& deviceSize, 970 const IntSize& deviceSize,
971 OpacityMode opacityMode, 971 OpacityMode opacityMode,
972 sk_sp<SkColorSpace> colorSpace,
973 int* msaaSampleCount) { 972 int* msaaSampleCount) {
974 if (!shouldAccelerate(deviceSize)) 973 if (!shouldAccelerate(deviceSize))
975 return nullptr; 974 return nullptr;
976 975
977 if (document().settings()) 976 if (document().settings())
978 *msaaSampleCount = 977 *msaaSampleCount =
979 document().settings()->accelerated2dCanvasMSAASampleCount(); 978 document().settings()->accelerated2dCanvasMSAASampleCount();
980 979
981 // Avoid creating |contextProvider| until we're sure we want to try use it, 980 // Avoid creating |contextProvider| until we're sure we want to try use it,
982 // since it costs us GPU memory. 981 // since it costs us GPU memory.
983 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider( 982 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider(
984 Platform::current()->createSharedOffscreenGraphicsContext3DProvider()); 983 Platform::current()->createSharedOffscreenGraphicsContext3DProvider());
985 if (!contextProvider) { 984 if (!contextProvider) {
986 CanvasMetrics::countCanvasContextUsage( 985 CanvasMetrics::countCanvasContextUsage(
987 CanvasMetrics::Accelerated2DCanvasGPUContextLost); 986 CanvasMetrics::Accelerated2DCanvasGPUContextLost);
988 return nullptr; 987 return nullptr;
989 } 988 }
990 989
991 if (contextProvider->isSoftwareRendering()) 990 if (contextProvider->isSoftwareRendering())
992 return nullptr; // Don't use accelerated canvas with swiftshader. 991 return nullptr; // Don't use accelerated canvas with swiftshader.
993 992
994 std::unique_ptr<ImageBufferSurface> surface = 993 std::unique_ptr<ImageBufferSurface> surface =
995 wrapUnique(new Canvas2DImageBufferSurface( 994 wrapUnique(new Canvas2DImageBufferSurface(
996 std::move(contextProvider), deviceSize, *msaaSampleCount, opacityMode, 995 std::move(contextProvider), deviceSize, *msaaSampleCount, opacityMode,
997 Canvas2DLayerBridge::EnableAcceleration, std::move(colorSpace))); 996 Canvas2DLayerBridge::EnableAcceleration, m_context->skColorSpace(),
997 m_context->colorType()));
998 if (!surface->isValid()) { 998 if (!surface->isValid()) {
999 CanvasMetrics::countCanvasContextUsage( 999 CanvasMetrics::countCanvasContextUsage(
1000 CanvasMetrics::GPUAccelerated2DCanvasImageBufferCreationFailed); 1000 CanvasMetrics::GPUAccelerated2DCanvasImageBufferCreationFailed);
1001 return nullptr; 1001 return nullptr;
1002 } 1002 }
1003 1003
1004 CanvasMetrics::countCanvasContextUsage( 1004 CanvasMetrics::countCanvasContextUsage(
1005 CanvasMetrics::GPUAccelerated2DCanvasImageBufferCreated); 1005 CanvasMetrics::GPUAccelerated2DCanvasImageBufferCreated);
1006 return surface; 1006 return surface;
1007 } 1007 }
1008 1008
1009 std::unique_ptr<ImageBufferSurface> 1009 std::unique_ptr<ImageBufferSurface>
1010 HTMLCanvasElement::createUnacceleratedImageBufferSurface( 1010 HTMLCanvasElement::createUnacceleratedImageBufferSurface(
1011 const IntSize& deviceSize, 1011 const IntSize& deviceSize,
1012 OpacityMode opacityMode, 1012 OpacityMode opacityMode) {
1013 sk_sp<SkColorSpace> colorSpace) {
1014 if (shouldUseDisplayList(deviceSize)) { 1013 if (shouldUseDisplayList(deviceSize)) {
1015 auto surface = wrapUnique(new RecordingImageBufferSurface( 1014 auto surface = wrapUnique(new RecordingImageBufferSurface(
1016 deviceSize, wrapUnique(new UnacceleratedSurfaceFactory), opacityMode, 1015 deviceSize, wrapUnique(new UnacceleratedSurfaceFactory), opacityMode,
1017 colorSpace)); 1016 m_context->skColorSpace(), m_context->colorType()));
1018 if (surface->isValid()) { 1017 if (surface->isValid()) {
1019 CanvasMetrics::countCanvasContextUsage( 1018 CanvasMetrics::countCanvasContextUsage(
1020 CanvasMetrics::DisplayList2DCanvasImageBufferCreated); 1019 CanvasMetrics::DisplayList2DCanvasImageBufferCreated);
1021 return std::move(surface); 1020 return std::move(surface);
1022 } 1021 }
1023 // We fallback to a non-display-list surface without recording a metric 1022 // We fallback to a non-display-list surface without recording a metric
1024 // here. 1023 // here.
1025 } 1024 }
1026 1025
1027 auto surfaceFactory = wrapUnique(new UnacceleratedSurfaceFactory()); 1026 auto surfaceFactory = wrapUnique(new UnacceleratedSurfaceFactory());
1028 auto surface = surfaceFactory->createSurface(deviceSize, opacityMode, 1027 auto surface = surfaceFactory->createSurface(deviceSize, opacityMode,
1029 std::move(colorSpace)); 1028 m_context->skColorSpace(),
1029 m_context->colorType());
1030 if (surface->isValid()) { 1030 if (surface->isValid()) {
1031 CanvasMetrics::countCanvasContextUsage( 1031 CanvasMetrics::countCanvasContextUsage(
1032 CanvasMetrics::Unaccelerated2DCanvasImageBufferCreated); 1032 CanvasMetrics::Unaccelerated2DCanvasImageBufferCreated);
1033 return surface; 1033 return surface;
1034 } 1034 }
1035 1035
1036 CanvasMetrics::countCanvasContextUsage( 1036 CanvasMetrics::countCanvasContextUsage(
1037 CanvasMetrics::Unaccelerated2DCanvasImageBufferCreationFailed); 1037 CanvasMetrics::Unaccelerated2DCanvasImageBufferCreationFailed);
1038 return nullptr; 1038 return nullptr;
1039 } 1039 }
(...skipping 16 matching lines...) Expand all
1056 1056
1057 OpacityMode opacityMode = 1057 OpacityMode opacityMode =
1058 !m_context || m_context->creationAttributes().alpha() ? NonOpaque 1058 !m_context || m_context->creationAttributes().alpha() ? NonOpaque
1059 : Opaque; 1059 : Opaque;
1060 int msaaSampleCount = 0; 1060 int msaaSampleCount = 0;
1061 std::unique_ptr<ImageBufferSurface> surface; 1061 std::unique_ptr<ImageBufferSurface> surface;
1062 if (externalSurface) { 1062 if (externalSurface) {
1063 if (externalSurface->isValid()) 1063 if (externalSurface->isValid())
1064 surface = std::move(externalSurface); 1064 surface = std::move(externalSurface);
1065 } else if (is3D()) { 1065 } else if (is3D()) {
1066 surface = createWebGLImageBufferSurface(size(), opacityMode, 1066 surface = createWebGLImageBufferSurface(size(), opacityMode);
1067 m_context->skColorSpace());
1068 } else { 1067 } else {
1069 surface = createAcceleratedImageBufferSurface( 1068 surface = createAcceleratedImageBufferSurface(size(), opacityMode,
1070 size(), opacityMode, m_context->skColorSpace(), &msaaSampleCount); 1069 &msaaSampleCount);
1071 if (!surface) 1070 if (!surface) {
1072 surface = createUnacceleratedImageBufferSurface( 1071 surface = createUnacceleratedImageBufferSurface(size(), opacityMode);
1073 size(), opacityMode, m_context->skColorSpace()); 1072 }
1074 } 1073 }
1075 if (!surface) 1074 if (!surface)
1076 return; 1075 return;
1077 DCHECK(surface->isValid()); 1076 DCHECK(surface->isValid());
1078 m_imageBuffer = ImageBuffer::create(std::move(surface)); 1077 m_imageBuffer = ImageBuffer::create(std::move(surface));
1079 DCHECK(m_imageBuffer); 1078 DCHECK(m_imageBuffer);
1080 m_imageBuffer->setClient(this); 1079 m_imageBuffer->setClient(this);
1081 1080
1082 m_didFailToCreateImageBuffer = false; 1081 m_didFailToCreateImageBuffer = false;
1083 1082
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
1439 mojom::blink::OffscreenCanvasSurfacePtr service; 1438 mojom::blink::OffscreenCanvasSurfacePtr service;
1440 Platform::current()->interfaceProvider()->getInterface( 1439 Platform::current()->interfaceProvider()->getInterface(
1441 mojo::GetProxy(&service)); 1440 mojo::GetProxy(&service));
1442 m_surfaceLayerBridge = 1441 m_surfaceLayerBridge =
1443 wrapUnique(new CanvasSurfaceLayerBridge(std::move(service))); 1442 wrapUnique(new CanvasSurfaceLayerBridge(std::move(service)));
1444 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), 1443 return m_surfaceLayerBridge->createSurfaceLayer(this->width(),
1445 this->height()); 1444 this->height());
1446 } 1445 }
1447 1446
1448 } // namespace blink 1447 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698