| OLD | NEW |
| 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 874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 } | 885 } |
| 886 | 886 |
| 887 namespace { | 887 namespace { |
| 888 | 888 |
| 889 class UnacceleratedSurfaceFactory | 889 class UnacceleratedSurfaceFactory |
| 890 : public RecordingImageBufferFallbackSurfaceFactory { | 890 : public RecordingImageBufferFallbackSurfaceFactory { |
| 891 public: | 891 public: |
| 892 virtual std::unique_ptr<ImageBufferSurface> CreateSurface( | 892 virtual std::unique_ptr<ImageBufferSurface> CreateSurface( |
| 893 const IntSize& size, | 893 const IntSize& size, |
| 894 OpacityMode opacity_mode, | 894 OpacityMode opacity_mode, |
| 895 sk_sp<SkColorSpace> color_space, | 895 const CanvasColorParams& color_params) { |
| 896 SkColorType color_type) { | |
| 897 return WTF::WrapUnique(new UnacceleratedImageBufferSurface( | 896 return WTF::WrapUnique(new UnacceleratedImageBufferSurface( |
| 898 size, opacity_mode, kInitializeImagePixels, color_space, color_type)); | 897 size, opacity_mode, kInitializeImagePixels, color_params)); |
| 899 } | 898 } |
| 900 | 899 |
| 901 virtual ~UnacceleratedSurfaceFactory() {} | 900 virtual ~UnacceleratedSurfaceFactory() {} |
| 902 }; | 901 }; |
| 903 | 902 |
| 904 } // namespace | 903 } // namespace |
| 905 | 904 |
| 906 bool HTMLCanvasElement::ShouldUseDisplayList() { | 905 bool HTMLCanvasElement::ShouldUseDisplayList() { |
| 907 if (context_->ColorSpace() != kLegacyCanvasColorSpace) | 906 // Rasterization of web contents will blend in the output space. Only embed |
| 907 // the canvas as a display list if it intended to do output space blending as |
| 908 // well. |
| 909 if (!context_->color_params().UsesOutputSpaceBlending()) |
| 908 return false; | 910 return false; |
| 909 | 911 |
| 910 if (RuntimeEnabledFeatures::forceDisplayList2dCanvasEnabled()) | 912 if (RuntimeEnabledFeatures::forceDisplayList2dCanvasEnabled()) |
| 911 return true; | 913 return true; |
| 912 | 914 |
| 913 if (!RuntimeEnabledFeatures::displayList2dCanvasEnabled()) | 915 if (!RuntimeEnabledFeatures::displayList2dCanvasEnabled()) |
| 914 return false; | 916 return false; |
| 915 | 917 |
| 916 return true; | 918 return true; |
| 917 } | 919 } |
| 918 | 920 |
| 919 std::unique_ptr<ImageBufferSurface> | 921 std::unique_ptr<ImageBufferSurface> |
| 920 HTMLCanvasElement::CreateWebGLImageBufferSurface(OpacityMode opacity_mode) { | 922 HTMLCanvasElement::CreateWebGLImageBufferSurface(OpacityMode opacity_mode) { |
| 921 DCHECK(Is3d()); | 923 DCHECK(Is3d()); |
| 922 // If 3d, but the use of the canvas will be for non-accelerated content | 924 // If 3d, but the use of the canvas will be for non-accelerated content |
| 923 // then make a non-accelerated ImageBuffer. This means copying the internal | 925 // then make a non-accelerated ImageBuffer. This means copying the internal |
| 924 // Image will require a pixel readback, but that is unavoidable in this case. | 926 // Image will require a pixel readback, but that is unavoidable in this case. |
| 925 auto surface = WTF::WrapUnique(new AcceleratedImageBufferSurface( | 927 auto surface = WTF::WrapUnique(new AcceleratedImageBufferSurface( |
| 926 size(), opacity_mode, context_->SkSurfaceColorSpace(), | 928 size(), opacity_mode, context_->color_params())); |
| 927 context_->ColorType())); | |
| 928 if (surface->IsValid()) | 929 if (surface->IsValid()) |
| 929 return std::move(surface); | 930 return std::move(surface); |
| 930 return nullptr; | 931 return nullptr; |
| 931 } | 932 } |
| 932 | 933 |
| 933 std::unique_ptr<ImageBufferSurface> | 934 std::unique_ptr<ImageBufferSurface> |
| 934 HTMLCanvasElement::CreateAcceleratedImageBufferSurface(OpacityMode opacity_mode, | 935 HTMLCanvasElement::CreateAcceleratedImageBufferSurface(OpacityMode opacity_mode, |
| 935 int* msaa_sample_count) { | 936 int* msaa_sample_count) { |
| 936 if (GetDocument().GetSettings()) { | 937 if (GetDocument().GetSettings()) { |
| 937 *msaa_sample_count = | 938 *msaa_sample_count = |
| 938 GetDocument().GetSettings()->GetAccelerated2dCanvasMSAASampleCount(); | 939 GetDocument().GetSettings()->GetAccelerated2dCanvasMSAASampleCount(); |
| 939 } | 940 } |
| 940 | 941 |
| 941 // Avoid creating |contextProvider| until we're sure we want to try use it, | 942 // Avoid creating |contextProvider| until we're sure we want to try use it, |
| 942 // since it costs us GPU memory. | 943 // since it costs us GPU memory. |
| 943 std::unique_ptr<WebGraphicsContext3DProvider> context_provider( | 944 std::unique_ptr<WebGraphicsContext3DProvider> context_provider( |
| 944 Platform::Current()->CreateSharedOffscreenGraphicsContext3DProvider()); | 945 Platform::Current()->CreateSharedOffscreenGraphicsContext3DProvider()); |
| 945 if (!context_provider) { | 946 if (!context_provider) { |
| 946 CanvasMetrics::CountCanvasContextUsage( | 947 CanvasMetrics::CountCanvasContextUsage( |
| 947 CanvasMetrics::kAccelerated2DCanvasGPUContextLost); | 948 CanvasMetrics::kAccelerated2DCanvasGPUContextLost); |
| 948 return nullptr; | 949 return nullptr; |
| 949 } | 950 } |
| 950 | 951 |
| 951 if (context_provider->IsSoftwareRendering()) | 952 if (context_provider->IsSoftwareRendering()) |
| 952 return nullptr; // Don't use accelerated canvas with swiftshader. | 953 return nullptr; // Don't use accelerated canvas with swiftshader. |
| 953 | 954 |
| 954 std::unique_ptr<ImageBufferSurface> surface = | 955 std::unique_ptr<ImageBufferSurface> surface = |
| 955 WTF::WrapUnique(new Canvas2DImageBufferSurface( | 956 WTF::WrapUnique(new Canvas2DImageBufferSurface( |
| 956 std::move(context_provider), size(), *msaa_sample_count, opacity_mode, | 957 std::move(context_provider), size(), *msaa_sample_count, opacity_mode, |
| 957 Canvas2DLayerBridge::kEnableAcceleration, context_->GfxColorSpace(), | 958 Canvas2DLayerBridge::kEnableAcceleration, context_->color_params())); |
| 958 context_->SkSurfacesUseColorSpace(), context_->ColorType())); | |
| 959 if (!surface->IsValid()) { | 959 if (!surface->IsValid()) { |
| 960 CanvasMetrics::CountCanvasContextUsage( | 960 CanvasMetrics::CountCanvasContextUsage( |
| 961 CanvasMetrics::kGPUAccelerated2DCanvasImageBufferCreationFailed); | 961 CanvasMetrics::kGPUAccelerated2DCanvasImageBufferCreationFailed); |
| 962 return nullptr; | 962 return nullptr; |
| 963 } | 963 } |
| 964 | 964 |
| 965 CanvasMetrics::CountCanvasContextUsage( | 965 CanvasMetrics::CountCanvasContextUsage( |
| 966 CanvasMetrics::kGPUAccelerated2DCanvasImageBufferCreated); | 966 CanvasMetrics::kGPUAccelerated2DCanvasImageBufferCreated); |
| 967 return surface; | 967 return surface; |
| 968 } | 968 } |
| 969 | 969 |
| 970 std::unique_ptr<ImageBufferSurface> | 970 std::unique_ptr<ImageBufferSurface> |
| 971 HTMLCanvasElement::CreateUnacceleratedImageBufferSurface( | 971 HTMLCanvasElement::CreateUnacceleratedImageBufferSurface( |
| 972 OpacityMode opacity_mode) { | 972 OpacityMode opacity_mode) { |
| 973 if (ShouldUseDisplayList()) { | 973 if (ShouldUseDisplayList()) { |
| 974 auto surface = WTF::WrapUnique(new RecordingImageBufferSurface( | 974 auto surface = WTF::WrapUnique(new RecordingImageBufferSurface( |
| 975 size(), WTF::WrapUnique(new UnacceleratedSurfaceFactory), opacity_mode, | 975 size(), WTF::WrapUnique(new UnacceleratedSurfaceFactory), opacity_mode, |
| 976 context_->SkSurfaceColorSpace(), context_->ColorType())); | 976 context_->color_params())); |
| 977 if (surface->IsValid()) { | 977 if (surface->IsValid()) { |
| 978 CanvasMetrics::CountCanvasContextUsage( | 978 CanvasMetrics::CountCanvasContextUsage( |
| 979 CanvasMetrics::kDisplayList2DCanvasImageBufferCreated); | 979 CanvasMetrics::kDisplayList2DCanvasImageBufferCreated); |
| 980 return std::move(surface); | 980 return std::move(surface); |
| 981 } | 981 } |
| 982 // We fallback to a non-display-list surface without recording a metric | 982 // We fallback to a non-display-list surface without recording a metric |
| 983 // here. | 983 // here. |
| 984 } | 984 } |
| 985 | 985 |
| 986 auto surface_factory = WTF::MakeUnique<UnacceleratedSurfaceFactory>(); | 986 auto surface_factory = WTF::MakeUnique<UnacceleratedSurfaceFactory>(); |
| 987 auto surface = surface_factory->CreateSurface(size(), opacity_mode, | 987 auto surface = surface_factory->CreateSurface(size(), opacity_mode, |
| 988 context_->SkSurfaceColorSpace(), | 988 context_->color_params()); |
| 989 context_->ColorType()); | |
| 990 if (surface->IsValid()) { | 989 if (surface->IsValid()) { |
| 991 CanvasMetrics::CountCanvasContextUsage( | 990 CanvasMetrics::CountCanvasContextUsage( |
| 992 CanvasMetrics::kUnaccelerated2DCanvasImageBufferCreated); | 991 CanvasMetrics::kUnaccelerated2DCanvasImageBufferCreated); |
| 993 return surface; | 992 return surface; |
| 994 } | 993 } |
| 995 | 994 |
| 996 CanvasMetrics::CountCanvasContextUsage( | 995 CanvasMetrics::CountCanvasContextUsage( |
| 997 CanvasMetrics::kUnaccelerated2DCanvasImageBufferCreationFailed); | 996 CanvasMetrics::kUnaccelerated2DCanvasImageBufferCreationFailed); |
| 998 return nullptr; | 997 return nullptr; |
| 999 } | 998 } |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1480 // Creates a placeholder layer first before Surface is created. | 1479 // Creates a placeholder layer first before Surface is created. |
| 1481 surface_layer_bridge_->CreateSolidColorLayer(); | 1480 surface_layer_bridge_->CreateSolidColorLayer(); |
| 1482 } | 1481 } |
| 1483 } | 1482 } |
| 1484 | 1483 |
| 1485 void HTMLCanvasElement::OnWebLayerReplaced() { | 1484 void HTMLCanvasElement::OnWebLayerReplaced() { |
| 1486 SetNeedsCompositingUpdate(); | 1485 SetNeedsCompositingUpdate(); |
| 1487 } | 1486 } |
| 1488 | 1487 |
| 1489 } // namespace blink | 1488 } // namespace blink |
| OLD | NEW |