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

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

Issue 2660393002: Use gfx::ColorSpace instead of SkColorSpace in Blink (Closed)
Patch Set: 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) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 // The id of the texture bound to the CHROMIUM image. 79 // The id of the texture bound to the CHROMIUM image.
80 const GLuint m_textureId; 80 const GLuint m_textureId;
81 }; 81 };
82 #endif // USE_IOSURFACE_FOR_2D_CANVAS 82 #endif // USE_IOSURFACE_FOR_2D_CANVAS
83 83
84 static sk_sp<SkSurface> createSkSurface(GrContext* gr, 84 static sk_sp<SkSurface> createSkSurface(GrContext* gr,
85 const IntSize& size, 85 const IntSize& size,
86 int msaaSampleCount, 86 int msaaSampleCount,
87 OpacityMode opacityMode, 87 OpacityMode opacityMode,
88 sk_sp<SkColorSpace> colorSpace, 88 sk_sp<SkColorSpace> skSurfaceColorSpace,
89 SkColorType colorType, 89 SkColorType colorType,
90 bool* surfaceIsAccelerated) { 90 bool* surfaceIsAccelerated) {
91 if (gr) 91 if (gr)
92 gr->resetContext(); 92 gr->resetContext();
93 93
94 SkAlphaType alphaType = 94 SkAlphaType alphaType =
95 (Opaque == opacityMode) ? kOpaque_SkAlphaType : kPremul_SkAlphaType; 95 (Opaque == opacityMode) ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
96 SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), colorType, 96 SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), colorType,
97 alphaType, colorSpace); 97 alphaType, skSurfaceColorSpace);
98 SkSurfaceProps disableLCDProps(0, kUnknown_SkPixelGeometry); 98 SkSurfaceProps disableLCDProps(0, kUnknown_SkPixelGeometry);
99 sk_sp<SkSurface> surface; 99 sk_sp<SkSurface> surface;
100 100
101 if (gr) { 101 if (gr) {
102 *surfaceIsAccelerated = true; 102 *surfaceIsAccelerated = true;
103 surface = SkSurface::MakeRenderTarget( 103 surface = SkSurface::MakeRenderTarget(
104 gr, SkBudgeted::kNo, info, msaaSampleCount, 104 gr, SkBudgeted::kNo, info, msaaSampleCount,
105 Opaque == opacityMode ? 0 : &disableLCDProps); 105 Opaque == opacityMode ? 0 : &disableLCDProps);
106 } 106 }
107 107
(...skipping 12 matching lines...) Expand all
120 } 120 }
121 return surface; 121 return surface;
122 } 122 }
123 123
124 Canvas2DLayerBridge::Canvas2DLayerBridge( 124 Canvas2DLayerBridge::Canvas2DLayerBridge(
125 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider, 125 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider,
126 const IntSize& size, 126 const IntSize& size,
127 int msaaSampleCount, 127 int msaaSampleCount,
128 OpacityMode opacityMode, 128 OpacityMode opacityMode,
129 AccelerationMode accelerationMode, 129 AccelerationMode accelerationMode,
130 sk_sp<SkColorSpace> colorSpace, 130 const gfx::ColorSpace& colorSpace,
131 sk_sp<SkColorSpace> skSurfaceColorSpace,
131 SkColorType colorType) 132 SkColorType colorType)
132 : m_contextProvider(std::move(contextProvider)), 133 : m_contextProvider(std::move(contextProvider)),
133 m_logger(WTF::wrapUnique(new Logger)), 134 m_logger(WTF::wrapUnique(new Logger)),
134 m_weakPtrFactory(this), 135 m_weakPtrFactory(this),
135 m_imageBuffer(0), 136 m_imageBuffer(0),
136 m_msaaSampleCount(msaaSampleCount), 137 m_msaaSampleCount(msaaSampleCount),
137 m_bytesAllocated(0), 138 m_bytesAllocated(0),
138 m_haveRecordedDrawCommands(false), 139 m_haveRecordedDrawCommands(false),
139 m_destructionInProgress(false), 140 m_destructionInProgress(false),
140 m_filterQuality(kLow_SkFilterQuality), 141 m_filterQuality(kLow_SkFilterQuality),
141 m_isHidden(false), 142 m_isHidden(false),
142 m_isDeferralEnabled(true), 143 m_isDeferralEnabled(true),
143 m_isRegisteredTaskObserver(false), 144 m_isRegisteredTaskObserver(false),
144 m_renderingTaskCompletedForCurrentFrame(false), 145 m_renderingTaskCompletedForCurrentFrame(false),
145 m_softwareRenderingWhileHidden(false), 146 m_softwareRenderingWhileHidden(false),
146 m_lastImageId(0), 147 m_lastImageId(0),
147 m_lastFilter(GL_LINEAR), 148 m_lastFilter(GL_LINEAR),
148 m_accelerationMode(accelerationMode), 149 m_accelerationMode(accelerationMode),
149 m_opacityMode(opacityMode), 150 m_opacityMode(opacityMode),
150 m_size(size), 151 m_size(size),
151 m_colorSpace(colorSpace), 152 m_colorSpace(colorSpace),
153 m_skSurfaceColorSpace(skSurfaceColorSpace),
152 m_colorType(colorType) { 154 m_colorType(colorType) {
153 DCHECK(m_contextProvider); 155 DCHECK(m_contextProvider);
154 DCHECK(!m_contextProvider->isSoftwareRendering()); 156 DCHECK(!m_contextProvider->isSoftwareRendering());
155 // Used by browser tests to detect the use of a Canvas2DLayerBridge. 157 // Used by browser tests to detect the use of a Canvas2DLayerBridge.
156 TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation", 158 TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation",
157 TRACE_EVENT_SCOPE_GLOBAL); 159 TRACE_EVENT_SCOPE_GLOBAL);
158 startRecording(); 160 startRecording();
159 } 161 }
160 162
161 Canvas2DLayerBridge::~Canvas2DLayerBridge() { 163 Canvas2DLayerBridge::~Canvas2DLayerBridge() {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 273
272 info.m_imageInfo = imageInfo; 274 info.m_imageInfo = imageInfo;
273 bool isOverlayCandidate = true; 275 bool isOverlayCandidate = true;
274 bool secureOutputOnly = false; 276 bool secureOutputOnly = false;
275 info.m_mailbox = mailbox; 277 info.m_mailbox = mailbox;
276 278
277 *outMailbox = 279 *outMailbox =
278 cc::TextureMailbox(mailbox, syncToken, textureTarget, gfx::Size(m_size), 280 cc::TextureMailbox(mailbox, syncToken, textureTarget, gfx::Size(m_size),
279 isOverlayCandidate, secureOutputOnly); 281 isOverlayCandidate, secureOutputOnly);
280 if (RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) { 282 if (RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) {
281 gfx::ColorSpace colorSpace = 283 outMailbox->set_color_space(m_colorSpace);
282 gfx::ColorSpace::FromSkColorSpace(m_colorSpace); 284 imageInfo->m_gpuMemoryBuffer->SetColorSpaceForScanout(m_colorSpace);
283 outMailbox->set_color_space(colorSpace);
284 imageInfo->m_gpuMemoryBuffer->SetColorSpaceForScanout(colorSpace);
285 } 285 }
286 286
287 gl->BindTexture(GC3D_TEXTURE_RECTANGLE_ARB, 0); 287 gl->BindTexture(GC3D_TEXTURE_RECTANGLE_ARB, 0);
288 288
289 // Because we are changing the texture binding without going through skia, 289 // Because we are changing the texture binding without going through skia,
290 // we must dirty the context. 290 // we must dirty the context.
291 grContext->resetContext(kTextureBinding_GrGLBackendState); 291 grContext->resetContext(kTextureBinding_GrGLBackendState);
292 292
293 return true; 293 return true;
294 } 294 }
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 bool wantAcceleration = shouldAccelerate(hint); 548 bool wantAcceleration = shouldAccelerate(hint);
549 if (CANVAS2D_BACKGROUND_RENDER_SWITCH_TO_CPU && isHidden() && 549 if (CANVAS2D_BACKGROUND_RENDER_SWITCH_TO_CPU && isHidden() &&
550 wantAcceleration) { 550 wantAcceleration) {
551 wantAcceleration = false; 551 wantAcceleration = false;
552 m_softwareRenderingWhileHidden = true; 552 m_softwareRenderingWhileHidden = true;
553 } 553 }
554 554
555 bool surfaceIsAccelerated; 555 bool surfaceIsAccelerated;
556 m_surface = createSkSurface( 556 m_surface = createSkSurface(
557 wantAcceleration ? m_contextProvider->grContext() : nullptr, m_size, 557 wantAcceleration ? m_contextProvider->grContext() : nullptr, m_size,
558 m_msaaSampleCount, m_opacityMode, m_colorSpace, m_colorType, 558 m_msaaSampleCount, m_opacityMode, m_skSurfaceColorSpace, m_colorType,
559 &surfaceIsAccelerated); 559 &surfaceIsAccelerated);
560 560
561 if (m_surface) { 561 if (m_surface) {
562 // Always save an initial frame, to support resetting the top level matrix 562 // Always save an initial frame, to support resetting the top level matrix
563 // and clip. 563 // and clip.
564 m_surface->getCanvas()->save(); 564 m_surface->getCanvas()->save();
565 } else { 565 } else {
566 reportSurfaceCreationFailure(); 566 reportSurfaceCreationFailure();
567 } 567 }
568 568
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 gpu::gles2::GLES2Interface* sharedGL = nullptr; 853 gpu::gles2::GLES2Interface* sharedGL = nullptr;
854 m_layer->clearTexture(); 854 m_layer->clearTexture();
855 m_contextProvider = WTF::wrapUnique( 855 m_contextProvider = WTF::wrapUnique(
856 Platform::current()->createSharedOffscreenGraphicsContext3DProvider()); 856 Platform::current()->createSharedOffscreenGraphicsContext3DProvider());
857 if (m_contextProvider) 857 if (m_contextProvider)
858 sharedGL = m_contextProvider->contextGL(); 858 sharedGL = m_contextProvider->contextGL();
859 859
860 if (sharedGL && sharedGL->GetGraphicsResetStatusKHR() == GL_NO_ERROR) { 860 if (sharedGL && sharedGL->GetGraphicsResetStatusKHR() == GL_NO_ERROR) {
861 GrContext* grCtx = m_contextProvider->grContext(); 861 GrContext* grCtx = m_contextProvider->grContext();
862 bool surfaceIsAccelerated; 862 bool surfaceIsAccelerated;
863 sk_sp<SkSurface> surface( 863 sk_sp<SkSurface> surface(createSkSurface(
864 createSkSurface(grCtx, m_size, m_msaaSampleCount, m_opacityMode, 864 grCtx, m_size, m_msaaSampleCount, m_opacityMode, m_skSurfaceColorSpace,
865 m_colorSpace, m_colorType, &surfaceIsAccelerated)); 865 m_colorType, &surfaceIsAccelerated));
866 866
867 if (!m_surface) 867 if (!m_surface)
868 reportSurfaceCreationFailure(); 868 reportSurfaceCreationFailure();
869 869
870 // The current paradigm does not support switching from accelerated to 870 // The current paradigm does not support switching from accelerated to
871 // non-accelerated, which would be tricky due to changes to the layer tree, 871 // non-accelerated, which would be tricky due to changes to the layer tree,
872 // which can only happen at specific times during the document lifecycle. 872 // which can only happen at specific times during the document lifecycle.
873 // Therefore, we can only accept the restored surface if it is accelerated. 873 // Therefore, we can only accept the restored surface if it is accelerated.
874 if (surface && surfaceIsAccelerated) { 874 if (surface && surfaceIsAccelerated) {
875 m_surface = std::move(surface); 875 m_surface = std::move(surface);
876 // FIXME: draw sad canvas picture into new buffer crbug.com/243842 876 // FIXME: draw sad canvas picture into new buffer crbug.com/243842
877 } 877 }
878 } 878 }
879 if (m_imageBuffer) 879 if (m_imageBuffer)
880 m_imageBuffer->updateGPUMemoryUsage(); 880 m_imageBuffer->updateGPUMemoryUsage();
881 881
882 return m_surface.get(); 882 return m_surface.get();
883 } 883 }
884 884
885 static gfx::ColorSpace SkColorSpaceToColorSpace(
ccameron 2017/01/30 22:50:49 Also avoiding this conversion is part of the motiv
886 const SkColorSpace* skColorSpace) {
887 // TODO(crbug.com/634102): Eliminate this clumsy conversion by unifying
888 // SkColorSpace and gfx::ColorSpace.
889 if (!skColorSpace)
890 return gfx::ColorSpace();
891
892 gfx::ColorSpace::TransferID transferID =
893 gfx::ColorSpace::TransferID::UNSPECIFIED;
894 if (skColorSpace->gammaCloseToSRGB()) {
895 transferID = gfx::ColorSpace::TransferID::IEC61966_2_1;
896 } else if (skColorSpace->gammaIsLinear()) {
897 transferID = gfx::ColorSpace::TransferID::LINEAR;
898 } else {
899 // TODO(crbug.com/634102): Not all curve type are supported
900 DCHECK(false);
901 }
902
903 // TODO(crbug.com/634102): No primary conversions are performed.
904 // Rec-709 is assumed.
905 return gfx::ColorSpace(gfx::ColorSpace::PrimaryID::BT709, transferID,
906 gfx::ColorSpace::MatrixID::RGB,
907 gfx::ColorSpace::RangeID::FULL);
908 }
909
910 bool Canvas2DLayerBridge::PrepareTextureMailbox( 885 bool Canvas2DLayerBridge::PrepareTextureMailbox(
911 cc::TextureMailbox* outMailbox, 886 cc::TextureMailbox* outMailbox,
912 std::unique_ptr<cc::SingleReleaseCallback>* outReleaseCallback) { 887 std::unique_ptr<cc::SingleReleaseCallback>* outReleaseCallback) {
913 if (m_destructionInProgress) { 888 if (m_destructionInProgress) {
914 // It can be hit in the following sequence. 889 // It can be hit in the following sequence.
915 // 1. Canvas draws something. 890 // 1. Canvas draws something.
916 // 2. The compositor begins the frame. 891 // 2. The compositor begins the frame.
917 // 3. Javascript makes a context be lost. 892 // 3. Javascript makes a context be lost.
918 // 4. Here. 893 // 4. Here.
919 return false; 894 return false;
(...skipping 21 matching lines...) Expand all
941 // Early exit if canvas was not drawn to since last prepareMailbox. 916 // Early exit if canvas was not drawn to since last prepareMailbox.
942 GLenum filter = getGLFilter(); 917 GLenum filter = getGLFilter();
943 if (image->uniqueID() == m_lastImageId && filter == m_lastFilter) 918 if (image->uniqueID() == m_lastImageId && filter == m_lastFilter)
944 return false; 919 return false;
945 m_lastImageId = image->uniqueID(); 920 m_lastImageId = image->uniqueID();
946 m_lastFilter = filter; 921 m_lastFilter = filter;
947 922
948 if (!prepareMailboxFromImage(std::move(image), outMailbox)) 923 if (!prepareMailboxFromImage(std::move(image), outMailbox))
949 return false; 924 return false;
950 outMailbox->set_nearest_neighbor(getGLFilter() == GL_NEAREST); 925 outMailbox->set_nearest_neighbor(getGLFilter() == GL_NEAREST);
951 gfx::ColorSpace colorSpace = SkColorSpaceToColorSpace(m_colorSpace.get()); 926 outMailbox->set_color_space(m_colorSpace);
952 outMailbox->set_color_space(colorSpace);
953 927
954 auto func = 928 auto func =
955 WTF::bind(&Canvas2DLayerBridge::mailboxReleased, 929 WTF::bind(&Canvas2DLayerBridge::mailboxReleased,
956 m_weakPtrFactory.createWeakPtr(), outMailbox->mailbox()); 930 m_weakPtrFactory.createWeakPtr(), outMailbox->mailbox());
957 *outReleaseCallback = 931 *outReleaseCallback =
958 cc::SingleReleaseCallback::Create(convertToBaseCallback(std::move(func))); 932 cc::SingleReleaseCallback::Create(convertToBaseCallback(std::move(func)));
959 return true; 933 return true;
960 } 934 }
961 935
962 void Canvas2DLayerBridge::mailboxReleased(const gpu::Mailbox& mailbox, 936 void Canvas2DLayerBridge::mailboxReleased(const gpu::Mailbox& mailbox,
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 default; 1123 default;
1150 1124
1151 void Canvas2DLayerBridge::Logger::reportHibernationEvent( 1125 void Canvas2DLayerBridge::Logger::reportHibernationEvent(
1152 HibernationEvent event) { 1126 HibernationEvent event) {
1153 DEFINE_STATIC_LOCAL(EnumerationHistogram, hibernationHistogram, 1127 DEFINE_STATIC_LOCAL(EnumerationHistogram, hibernationHistogram,
1154 ("Canvas.HibernationEvents", HibernationEventCount)); 1128 ("Canvas.HibernationEvents", HibernationEventCount));
1155 hibernationHistogram.count(event); 1129 hibernationHistogram.count(event);
1156 } 1130 }
1157 1131
1158 } // namespace blink 1132 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698