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

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

Issue 1331533002: [poc] curve-filter Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Draw layered images with a recording GraphicContext Created 5 years 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) 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2009 Apple 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 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 18 matching lines...) Expand all
29 #include "SkImageFilter.h" 29 #include "SkImageFilter.h"
30 #include "SkMatrix44.h" 30 #include "SkMatrix44.h"
31 #include "base/trace_event/trace_event_argument.h" 31 #include "base/trace_event/trace_event_argument.h"
32 #include "cc/layers/layer.h" 32 #include "cc/layers/layer.h"
33 #include "platform/DragImage.h" 33 #include "platform/DragImage.h"
34 #include "platform/JSONValues.h" 34 #include "platform/JSONValues.h"
35 #include "platform/TraceEvent.h" 35 #include "platform/TraceEvent.h"
36 #include "platform/geometry/FloatRect.h" 36 #include "platform/geometry/FloatRect.h"
37 #include "platform/geometry/LayoutRect.h" 37 #include "platform/geometry/LayoutRect.h"
38 #include "platform/graphics/BitmapImage.h" 38 #include "platform/graphics/BitmapImage.h"
39 #include "platform/graphics/ColorSpaceFilter.h"
40 #include "platform/graphics/ColorSpaceProfile.h"
39 #include "platform/graphics/FirstPaintInvalidationTracking.h" 41 #include "platform/graphics/FirstPaintInvalidationTracking.h"
40 #include "platform/graphics/GraphicsContext.h" 42 #include "platform/graphics/GraphicsContext.h"
41 #include "platform/graphics/GraphicsLayerFactory.h" 43 #include "platform/graphics/GraphicsLayerFactory.h"
44 #include "platform/graphics/GraphicsScreen.h"
42 #include "platform/graphics/Image.h" 45 #include "platform/graphics/Image.h"
46 #include "platform/graphics/ImageBuffer.h"
43 #include "platform/graphics/LinkHighlight.h" 47 #include "platform/graphics/LinkHighlight.h"
44 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" 48 #include "platform/graphics/filters/SkiaImageFilterBuilder.h"
45 #include "platform/graphics/paint/DrawingRecorder.h" 49 #include "platform/graphics/paint/DrawingRecorder.h"
46 #include "platform/graphics/paint/PaintController.h" 50 #include "platform/graphics/paint/PaintController.h"
47 #include "platform/scroll/ScrollableArea.h" 51 #include "platform/scroll/ScrollableArea.h"
48 #include "platform/text/TextStream.h" 52 #include "platform/text/TextStream.h"
49 #include "public/platform/Platform.h" 53 #include "public/platform/Platform.h"
50 #include "public/platform/WebCompositorAnimation.h" 54 #include "public/platform/WebCompositorAnimation.h"
51 #include "public/platform/WebCompositorSupport.h" 55 #include "public/platform/WebCompositorSupport.h"
52 #include "public/platform/WebFilterOperations.h" 56 #include "public/platform/WebFilterOperations.h"
(...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 1062
1059 m_contentsRect = rect; 1063 m_contentsRect = rect;
1060 updateContentsRect(); 1064 updateContentsRect();
1061 } 1065 }
1062 1066
1063 void GraphicsLayer::setContentsToImage(Image* image, RespectImageOrientationEnum respectImageOrientation) 1067 void GraphicsLayer::setContentsToImage(Image* image, RespectImageOrientationEnum respectImageOrientation)
1064 { 1068 {
1065 RefPtr<SkImage> skImage = image ? image->imageForCurrentFrame() : nullptr; 1069 RefPtr<SkImage> skImage = image ? image->imageForCurrentFrame() : nullptr;
1066 1070
1067 if (image && skImage && image->isBitmapImage()) { 1071 if (image && skImage && image->isBitmapImage()) {
1068 if (respectImageOrientation == RespectImageOrientation) { 1072 RELEASE_ASSERT(currentScreenId()); // There should be an active graphics screen.
1073
1074 if (imageColorProfilesEnabled() && toBitmapImage(image)->hasColorProfile ()) {
1075 // FIXME: maybe pass the color transform filter to the layer so it g ets applied on the GPU.
1076 // FIXME: alternative is to somehow cache this local drawing on this GraphicsLayer, which would
1077 // save having to plumb transform SkColorFilters through to the GPU process, or else have BitmapImage
1078 // cache color corrected images and provide the appropriate image he re.
1079 // FIXME: In an experiment, I passed a SkColorCubeFilter to the GPU and that works. But note that
1080 // SkColorCurveFilter does not: it gets dropped on floor somewhere a fter CC sends it to the GPU process
1081 // (maybe because SkColorCurveFilter has float-16 textures, whereas SkColorCubeFilter does not?).
1082
1083 /*
1084 bool opaque = image->currentFrameKnownToBeOpaque();
1085 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(image->size(), opaq ue ? Opaque : NonOpaque);
1086 IntRect source = IntRect(IntPoint(), image->size());
1087 image->draw(buffer->canvas(), SkPaint(), source, source, DoNotRespec tImageOrientation, Image::ClampImageToSourceRect);
1088 skImage = buffer->newSkImageSnapshot(PreferNoAcceleration);
1089 */
1090
1091 OwnPtr<PaintController> paintController = PaintController::create();
1092 GraphicsContext context(*paintController);
1093
1094 FloatRect bounds(0, 0, image->size().width(), image->size().width()) ;
1095 context.beginRecording(bounds);
1096 context.drawImage(image, IntRect(0, 0, image->size().width(), image- >size().width()));
1097 RefPtr<const SkPicture> picture = context.endRecording();
1098
1099 SkISize skISize = SkISize::Make(image->size().width(), image->size() .width());
1100 skImage = SkImage::NewFromPicture(picture.get(), skISize, nullptr, n ullptr);
1101
1102 /*
1103 FIXME: SkRef counting on the SkImage counting ASSERTs on the Mac Rel ease try: find out why.
Noel Gordon 2015/12/01 03:15:47 Need an adoptRef at the end: skImage = adoptRef
Noel Gordon 2015/12/01 03:18:09 And similarly for the skImage created @ line 1100
1104 SkPictureRecorder recorder;
1105 SkRect bounds = SkRect::MakeIWH(skImage->width(), skImage->height()) ;
1106 SkCanvas* canvas = recorder.beginRecording(bounds, nullptr, 0);
1107
1108 SkPaint defaultPaint;
1109 canvas->drawImageRect(skImage.get(), bounds, bounds, &defaultPaint, SkCanvas::kStrict_SrcRectConstraint);
1110 RefPtr<SkPicture> picture = adoptRef(recorder.endRecording());
1111
1112 SkPaint transformPaint;
1113 RefPtr<ColorSpaceProfile> screen = screenColorProfile(currentScreenI d());
1114 RefPtr<ColorSpaceProfile> source = toBitmapImage(image)->colorProfil e();
1115 if (RefPtr<SkColorFilter> colorTransform = createColorSpaceFilter(so urce.get(), screen.get()))
1116 transformPaint.setColorFilter(colorTransform.get());
1117
1118 SkISize skISize = SkISize::Make(skImage->width(), skImage->height()) ;
1119 skImage = SkImage::NewFromPicture(picture.get(), skISize, nullptr, & transformPaint);
1120 */
1121 }
1122
1123 if (skImage && respectImageOrientation == RespectImageOrientation) {
1069 ImageOrientation imageOrientation = toBitmapImage(image)->currentFra meOrientation(); 1124 ImageOrientation imageOrientation = toBitmapImage(image)->currentFra meOrientation();
1070 skImage = DragImage::resizeAndOrientImage(skImage.release(), imageOr ientation); 1125 skImage = DragImage::resizeAndOrientImage(skImage.release(), imageOr ientation);
1071 } 1126 }
1072 } 1127 }
1073 1128
1074 if (image && skImage) { 1129 if (image && skImage) {
1075 if (!m_imageLayer) { 1130 if (!m_imageLayer) {
1076 m_imageLayer = adoptPtr(Platform::current()->compositorSupport()->cr eateImageLayer()); 1131 m_imageLayer = adoptPtr(Platform::current()->compositorSupport()->cr eateImageLayer());
1077 registerContentsLayer(m_imageLayer->layer()); 1132 registerContentsLayer(m_imageLayer->layer());
1078 } 1133 }
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 { 1277 {
1223 if (!layer) { 1278 if (!layer) {
1224 fprintf(stderr, "Cannot showGraphicsLayerTree for (nil).\n"); 1279 fprintf(stderr, "Cannot showGraphicsLayerTree for (nil).\n");
1225 return; 1280 return;
1226 } 1281 }
1227 1282
1228 String output = layer->layerTreeAsText(blink::LayerTreeIncludesDebugInfo); 1283 String output = layer->layerTreeAsText(blink::LayerTreeIncludesDebugInfo);
1229 fprintf(stderr, "%s\n", output.utf8().data()); 1284 fprintf(stderr, "%s\n", output.utf8().data());
1230 } 1285 }
1231 #endif 1286 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698