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

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: Rebase (again) 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 bool skSurfacesUseColorSpace,
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_skSurfacesUseColorSpace(skSurfacesUseColorSpace),
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());
157 DCHECK(m_colorSpace.IsValid());
155 // Used by browser tests to detect the use of a Canvas2DLayerBridge. 158 // Used by browser tests to detect the use of a Canvas2DLayerBridge.
156 TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation", 159 TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation",
157 TRACE_EVENT_SCOPE_GLOBAL); 160 TRACE_EVENT_SCOPE_GLOBAL);
158 startRecording(); 161 startRecording();
159 } 162 }
160 163
161 Canvas2DLayerBridge::~Canvas2DLayerBridge() { 164 Canvas2DLayerBridge::~Canvas2DLayerBridge() {
162 DCHECK(m_destructionInProgress); 165 DCHECK(m_destructionInProgress);
163 #if USE_IOSURFACE_FOR_2D_CANVAS 166 #if USE_IOSURFACE_FOR_2D_CANVAS
164 clearCHROMIUMImageCache(); 167 clearCHROMIUMImageCache();
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 274
272 info.m_imageInfo = imageInfo; 275 info.m_imageInfo = imageInfo;
273 bool isOverlayCandidate = true; 276 bool isOverlayCandidate = true;
274 bool secureOutputOnly = false; 277 bool secureOutputOnly = false;
275 info.m_mailbox = mailbox; 278 info.m_mailbox = mailbox;
276 279
277 *outMailbox = 280 *outMailbox =
278 cc::TextureMailbox(mailbox, syncToken, textureTarget, gfx::Size(m_size), 281 cc::TextureMailbox(mailbox, syncToken, textureTarget, gfx::Size(m_size),
279 isOverlayCandidate, secureOutputOnly); 282 isOverlayCandidate, secureOutputOnly);
280 if (RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) { 283 if (RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) {
281 gfx::ColorSpace colorSpace = 284 outMailbox->set_color_space(m_colorSpace);
282 gfx::ColorSpace::FromSkColorSpace(m_colorSpace); 285 imageInfo->m_gpuMemoryBuffer->SetColorSpaceForScanout(m_colorSpace);
283 outMailbox->set_color_space(colorSpace);
284 imageInfo->m_gpuMemoryBuffer->SetColorSpaceForScanout(colorSpace);
285 } 286 }
286 287
287 gl->BindTexture(GC3D_TEXTURE_RECTANGLE_ARB, 0); 288 gl->BindTexture(GC3D_TEXTURE_RECTANGLE_ARB, 0);
288 289
289 // Because we are changing the texture binding without going through skia, 290 // Because we are changing the texture binding without going through skia,
290 // we must dirty the context. 291 // we must dirty the context.
291 grContext->resetContext(kTextureBinding_GrGLBackendState); 292 grContext->resetContext(kTextureBinding_GrGLBackendState);
292 293
293 return true; 294 return true;
294 } 295 }
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 &copyPaint); // GPU readback 519 &copyPaint); // GPU readback
519 m_hibernationImage = tempHibernationSurface->makeImageSnapshot(); 520 m_hibernationImage = tempHibernationSurface->makeImageSnapshot();
520 m_surface.reset(); // destroy the GPU-backed buffer 521 m_surface.reset(); // destroy the GPU-backed buffer
521 m_layer->clearTexture(); 522 m_layer->clearTexture();
522 #if USE_IOSURFACE_FOR_2D_CANVAS 523 #if USE_IOSURFACE_FOR_2D_CANVAS
523 clearCHROMIUMImageCache(); 524 clearCHROMIUMImageCache();
524 #endif // USE_IOSURFACE_FOR_2D_CANVAS 525 #endif // USE_IOSURFACE_FOR_2D_CANVAS
525 m_logger->didStartHibernating(); 526 m_logger->didStartHibernating();
526 } 527 }
527 528
529 sk_sp<SkColorSpace> Canvas2DLayerBridge::skSurfaceColorSpace() const {
530 if (m_skSurfacesUseColorSpace)
531 return m_colorSpace.ToSkColorSpace();
532 return nullptr;
533 }
534
528 void Canvas2DLayerBridge::reportSurfaceCreationFailure() { 535 void Canvas2DLayerBridge::reportSurfaceCreationFailure() {
529 if (!m_surfaceCreationFailedAtLeastOnce) { 536 if (!m_surfaceCreationFailedAtLeastOnce) {
530 // Only count the failure once per instance so that the histogram may 537 // Only count the failure once per instance so that the histogram may
531 // reflect the proportion of Canvas2DLayerBridge instances with surface 538 // reflect the proportion of Canvas2DLayerBridge instances with surface
532 // allocation failures. 539 // allocation failures.
533 CanvasMetrics::countCanvasContextUsage( 540 CanvasMetrics::countCanvasContextUsage(
534 CanvasMetrics::GPUAccelerated2DCanvasSurfaceCreationFailed); 541 CanvasMetrics::GPUAccelerated2DCanvasSurfaceCreationFailed);
535 m_surfaceCreationFailedAtLeastOnce = true; 542 m_surfaceCreationFailedAtLeastOnce = true;
536 } 543 }
537 } 544 }
(...skipping 10 matching lines...) Expand all
548 bool wantAcceleration = shouldAccelerate(hint); 555 bool wantAcceleration = shouldAccelerate(hint);
549 if (CANVAS2D_BACKGROUND_RENDER_SWITCH_TO_CPU && isHidden() && 556 if (CANVAS2D_BACKGROUND_RENDER_SWITCH_TO_CPU && isHidden() &&
550 wantAcceleration) { 557 wantAcceleration) {
551 wantAcceleration = false; 558 wantAcceleration = false;
552 m_softwareRenderingWhileHidden = true; 559 m_softwareRenderingWhileHidden = true;
553 } 560 }
554 561
555 bool surfaceIsAccelerated; 562 bool surfaceIsAccelerated;
556 m_surface = createSkSurface( 563 m_surface = createSkSurface(
557 wantAcceleration ? m_contextProvider->grContext() : nullptr, m_size, 564 wantAcceleration ? m_contextProvider->grContext() : nullptr, m_size,
558 m_msaaSampleCount, m_opacityMode, m_colorSpace, m_colorType, 565 m_msaaSampleCount, m_opacityMode, skSurfaceColorSpace(), m_colorType,
559 &surfaceIsAccelerated); 566 &surfaceIsAccelerated);
560 567
561 if (m_surface) { 568 if (m_surface) {
562 // Always save an initial frame, to support resetting the top level matrix 569 // Always save an initial frame, to support resetting the top level matrix
563 // and clip. 570 // and clip.
564 m_surface->getCanvas()->save(); 571 m_surface->getCanvas()->save();
565 } else { 572 } else {
566 reportSurfaceCreationFailure(); 573 reportSurfaceCreationFailure();
567 } 574 }
568 575
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 gpu::gles2::GLES2Interface* sharedGL = nullptr; 860 gpu::gles2::GLES2Interface* sharedGL = nullptr;
854 m_layer->clearTexture(); 861 m_layer->clearTexture();
855 m_contextProvider = WTF::wrapUnique( 862 m_contextProvider = WTF::wrapUnique(
856 Platform::current()->createSharedOffscreenGraphicsContext3DProvider()); 863 Platform::current()->createSharedOffscreenGraphicsContext3DProvider());
857 if (m_contextProvider) 864 if (m_contextProvider)
858 sharedGL = m_contextProvider->contextGL(); 865 sharedGL = m_contextProvider->contextGL();
859 866
860 if (sharedGL && sharedGL->GetGraphicsResetStatusKHR() == GL_NO_ERROR) { 867 if (sharedGL && sharedGL->GetGraphicsResetStatusKHR() == GL_NO_ERROR) {
861 GrContext* grCtx = m_contextProvider->grContext(); 868 GrContext* grCtx = m_contextProvider->grContext();
862 bool surfaceIsAccelerated; 869 bool surfaceIsAccelerated;
863 sk_sp<PaintSurface> surface( 870 sk_sp<PaintSurface> surface(createSkSurface(
864 createSkSurface(grCtx, m_size, m_msaaSampleCount, m_opacityMode, 871 grCtx, m_size, m_msaaSampleCount, m_opacityMode, skSurfaceColorSpace(),
865 m_colorSpace, m_colorType, &surfaceIsAccelerated)); 872 m_colorType, &surfaceIsAccelerated));
866
867 if (!m_surface) 873 if (!m_surface)
868 reportSurfaceCreationFailure(); 874 reportSurfaceCreationFailure();
869 875
870 // The current paradigm does not support switching from accelerated to 876 // The current paradigm does not support switching from accelerated to
871 // non-accelerated, which would be tricky due to changes to the layer tree, 877 // 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. 878 // which can only happen at specific times during the document lifecycle.
873 // Therefore, we can only accept the restored surface if it is accelerated. 879 // Therefore, we can only accept the restored surface if it is accelerated.
874 if (surface && surfaceIsAccelerated) { 880 if (surface && surfaceIsAccelerated) {
875 m_surface = std::move(surface); 881 m_surface = std::move(surface);
876 // FIXME: draw sad canvas picture into new buffer crbug.com/243842 882 // FIXME: draw sad canvas picture into new buffer crbug.com/243842
877 } 883 }
878 } 884 }
879 if (m_imageBuffer) 885 if (m_imageBuffer)
880 m_imageBuffer->updateGPUMemoryUsage(); 886 m_imageBuffer->updateGPUMemoryUsage();
881 887
882 return m_surface.get(); 888 return m_surface.get();
883 } 889 }
884 890
885 static gfx::ColorSpace SkColorSpaceToColorSpace(
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( 891 bool Canvas2DLayerBridge::PrepareTextureMailbox(
911 cc::TextureMailbox* outMailbox, 892 cc::TextureMailbox* outMailbox,
912 std::unique_ptr<cc::SingleReleaseCallback>* outReleaseCallback) { 893 std::unique_ptr<cc::SingleReleaseCallback>* outReleaseCallback) {
913 if (m_destructionInProgress) { 894 if (m_destructionInProgress) {
914 // It can be hit in the following sequence. 895 // It can be hit in the following sequence.
915 // 1. Canvas draws something. 896 // 1. Canvas draws something.
916 // 2. The compositor begins the frame. 897 // 2. The compositor begins the frame.
917 // 3. Javascript makes a context be lost. 898 // 3. Javascript makes a context be lost.
918 // 4. Here. 899 // 4. Here.
919 return false; 900 return false;
(...skipping 21 matching lines...) Expand all
941 // Early exit if canvas was not drawn to since last prepareMailbox. 922 // Early exit if canvas was not drawn to since last prepareMailbox.
942 GLenum filter = getGLFilter(); 923 GLenum filter = getGLFilter();
943 if (image->uniqueID() == m_lastImageId && filter == m_lastFilter) 924 if (image->uniqueID() == m_lastImageId && filter == m_lastFilter)
944 return false; 925 return false;
945 m_lastImageId = image->uniqueID(); 926 m_lastImageId = image->uniqueID();
946 m_lastFilter = filter; 927 m_lastFilter = filter;
947 928
948 if (!prepareMailboxFromImage(std::move(image), outMailbox)) 929 if (!prepareMailboxFromImage(std::move(image), outMailbox))
949 return false; 930 return false;
950 outMailbox->set_nearest_neighbor(getGLFilter() == GL_NEAREST); 931 outMailbox->set_nearest_neighbor(getGLFilter() == GL_NEAREST);
951 gfx::ColorSpace colorSpace = SkColorSpaceToColorSpace(m_colorSpace.get()); 932 outMailbox->set_color_space(m_colorSpace);
952 outMailbox->set_color_space(colorSpace);
953 933
954 auto func = 934 auto func =
955 WTF::bind(&Canvas2DLayerBridge::mailboxReleased, 935 WTF::bind(&Canvas2DLayerBridge::mailboxReleased,
956 m_weakPtrFactory.createWeakPtr(), outMailbox->mailbox()); 936 m_weakPtrFactory.createWeakPtr(), outMailbox->mailbox());
957 *outReleaseCallback = 937 *outReleaseCallback =
958 cc::SingleReleaseCallback::Create(convertToBaseCallback(std::move(func))); 938 cc::SingleReleaseCallback::Create(convertToBaseCallback(std::move(func)));
959 return true; 939 return true;
960 } 940 }
961 941
962 void Canvas2DLayerBridge::mailboxReleased(const gpu::Mailbox& mailbox, 942 void Canvas2DLayerBridge::mailboxReleased(const gpu::Mailbox& mailbox,
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 default; 1129 default;
1150 1130
1151 void Canvas2DLayerBridge::Logger::reportHibernationEvent( 1131 void Canvas2DLayerBridge::Logger::reportHibernationEvent(
1152 HibernationEvent event) { 1132 HibernationEvent event) {
1153 DEFINE_STATIC_LOCAL(EnumerationHistogram, hibernationHistogram, 1133 DEFINE_STATIC_LOCAL(EnumerationHistogram, hibernationHistogram,
1154 ("Canvas.HibernationEvents", HibernationEventCount)); 1134 ("Canvas.HibernationEvents", HibernationEventCount));
1155 hibernationHistogram.count(event); 1135 hibernationHistogram.count(event);
1156 } 1136 }
1157 1137
1158 } // namespace blink 1138 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698