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

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

Issue 2888603002: Replace uses of legacy SkImageGenerator API (Closed)
Patch Set: Use ternary Created 3 years, 7 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
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/DecodingImageGenerator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 // getAsSkData() may require copying, but the clients of this function are 58 // getAsSkData() may require copying, but the clients of this function are
59 // serializers, which want the data even if it requires copying, and even 59 // serializers, which want the data even if it requires copying, and even
60 // if the data is incomplete. (Otherwise they would potentially need to 60 // if the data is incomplete. (Otherwise they would potentially need to
61 // decode the partial image in order to re-encode it.) 61 // decode the partial image in order to re-encode it.)
62 return data_->GetAsSkData().release(); 62 return data_->GetAsSkData().release();
63 } 63 }
64 64
65 static void doColorSpaceXform(const SkImageInfo& dst_info, 65 static void doColorSpaceXform(const SkImageInfo& dst_info,
66 void* pixels, 66 void* pixels,
67 size_t row_bytes, 67 size_t row_bytes,
68 SkColorSpace* src_color_space) { 68 SkColorSpace* src_color_space,
69 SkTransferFunctionBehavior behavior) {
69 TRACE_EVENT0("blink", "DecodingImageGenerator::getPixels - apply xform"); 70 TRACE_EVENT0("blink", "DecodingImageGenerator::getPixels - apply xform");
70 std::unique_ptr<SkColorSpaceXform> xform = 71 std::unique_ptr<SkColorSpaceXform> xform =
71 SkColorSpaceXform::New(src_color_space, dst_info.colorSpace()); 72 SkColorSpaceXform::New(src_color_space, dst_info.colorSpace());
72 73
74 const bool post_xform_premul =
75 (dst_info.alphaType() == kPremul_SkAlphaType) &&
76 (behavior == SkTransferFunctionBehavior::kIgnore);
77
73 uint32_t* row = reinterpret_cast<uint32_t*>(pixels); 78 uint32_t* row = reinterpret_cast<uint32_t*>(pixels);
74 for (int y = 0; y < dst_info.height(); y++) { 79 for (int y = 0; y < dst_info.height(); y++) {
75 SkColorSpaceXform::ColorFormat format = 80 SkColorSpaceXform::ColorFormat format =
76 SkColorSpaceXform::kRGBA_8888_ColorFormat; 81 SkColorSpaceXform::kRGBA_8888_ColorFormat;
77 if (kN32_SkColorType == kBGRA_8888_SkColorType) { 82 if (kN32_SkColorType == kBGRA_8888_SkColorType) {
78 format = SkColorSpaceXform::kBGRA_8888_ColorFormat; 83 format = SkColorSpaceXform::kBGRA_8888_ColorFormat;
79 } 84 }
80 SkAlphaType alpha_type = 85 SkAlphaType alpha_type =
81 dst_info.isOpaque() ? kOpaque_SkAlphaType : kUnpremul_SkAlphaType; 86 post_xform_premul ? kUnpremul_SkAlphaType : dst_info.alphaType();
82 bool xformed = 87 bool xformed =
83 xform->apply(format, row, format, row, dst_info.width(), alpha_type); 88 xform->apply(format, row, format, row, dst_info.width(), alpha_type);
84 DCHECK(xformed); 89 DCHECK(xformed);
85 90
86 // To be compatible with dst space blending, premultiply in the dst space. 91 // To be compatible with dst space blending, premultiply in the dst space.
87 if (kPremul_SkAlphaType == dst_info.alphaType()) { 92 if (post_xform_premul) {
88 for (int x = 0; x < dst_info.width(); x++) { 93 for (int x = 0; x < dst_info.width(); x++) {
89 row[x] = 94 row[x] =
90 SkPreMultiplyARGB(SkGetPackedA32(row[x]), SkGetPackedR32(row[x]), 95 SkPreMultiplyARGB(SkGetPackedA32(row[x]), SkGetPackedR32(row[x]),
91 SkGetPackedG32(row[x]), SkGetPackedB32(row[x])); 96 SkGetPackedG32(row[x]), SkGetPackedB32(row[x]));
92 } 97 }
93 } 98 }
94 99
95 row = reinterpret_cast<uint32_t*>( 100 row = reinterpret_cast<uint32_t*>(
96 (reinterpret_cast<uint8_t*>(row) + row_bytes)); 101 (reinterpret_cast<uint8_t*>(row) + row_bytes));
97 } 102 }
98 } 103 }
99 104
100 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& dst_info, 105 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& dst_info,
101 void* pixels, 106 void* pixels,
102 size_t row_bytes, 107 size_t row_bytes,
103 SkPMColor*, 108 const Options& options) {
104 int*) {
105 TRACE_EVENT1("blink", "DecodingImageGenerator::getPixels", "frame index", 109 TRACE_EVENT1("blink", "DecodingImageGenerator::getPixels", "frame index",
106 static_cast<int>(frame_index_)); 110 static_cast<int>(frame_index_));
107 111
108 // Implementation doesn't support scaling yet, so make sure we're not given a 112 // Implementation doesn't support scaling yet, so make sure we're not given a
109 // different size. 113 // different size.
110 if (dst_info.dimensions() != getInfo().dimensions()) { 114 if (dst_info.dimensions() != getInfo().dimensions()) {
111 return false; 115 return false;
112 } 116 }
113 117
114 if (dst_info.colorType() != kN32_SkColorType) { 118 if (dst_info.colorType() != kN32_SkColorType) {
(...skipping 20 matching lines...) Expand all
135 decode_info = decode_info.makeAlphaType(kUnpremul_SkAlphaType); 139 decode_info = decode_info.makeAlphaType(kUnpremul_SkAlphaType);
136 } 140 }
137 141
138 PlatformInstrumentation::WillDecodeLazyPixelRef(uniqueID()); 142 PlatformInstrumentation::WillDecodeLazyPixelRef(uniqueID());
139 bool decoded = frame_generator_->DecodeAndScale( 143 bool decoded = frame_generator_->DecodeAndScale(
140 data_.Get(), all_data_received_, frame_index_, decode_info, pixels, 144 data_.Get(), all_data_received_, frame_index_, decode_info, pixels,
141 row_bytes, alpha_option); 145 row_bytes, alpha_option);
142 PlatformInstrumentation::DidDecodeLazyPixelRef(); 146 PlatformInstrumentation::DidDecodeLazyPixelRef();
143 147
144 if (decoded && needs_color_xform) { 148 if (decoded && needs_color_xform) {
145 doColorSpaceXform(dst_info, pixels, row_bytes, decode_color_space); 149 doColorSpaceXform(dst_info, pixels, row_bytes, decode_color_space,
150 options.fBehavior);
146 } 151 }
147 152
148 return decoded; 153 return decoded;
149 } 154 }
150 155
151 bool DecodingImageGenerator::onQueryYUV8(SkYUVSizeInfo* size_info, 156 bool DecodingImageGenerator::onQueryYUV8(SkYUVSizeInfo* size_info,
152 SkYUVColorSpace* color_space) const { 157 SkYUVColorSpace* color_space) const {
153 // YUV decoding does not currently support progressive decoding. See comment 158 // YUV decoding does not currently support progressive decoding. See comment
154 // in ImageFrameGenerator.h. 159 // in ImageFrameGenerator.h.
155 if (!can_yuv_decode_ || !all_data_received_) 160 if (!can_yuv_decode_ || !all_data_received_)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 ImageFrameGenerator::Create(SkISize::Make(size.Width(), size.Height()), 209 ImageFrameGenerator::Create(SkISize::Make(size.Width(), size.Height()),
205 false, decoder->GetColorBehavior()); 210 false, decoder->GetColorBehavior());
206 if (!frame) 211 if (!frame)
207 return nullptr; 212 return nullptr;
208 213
209 return new DecodingImageGenerator(frame, info, segment_reader.Release(), true, 214 return new DecodingImageGenerator(frame, info, segment_reader.Release(), true,
210 0); 215 0);
211 } 216 }
212 217
213 } // namespace blink 218 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/DecodingImageGenerator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698