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

Side by Side Diff: src/core/SkPictureShader.cpp

Issue 1855733002: change flattenable factory to return sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 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 | « src/core/SkPathEffect.cpp ('k') | src/core/SkReadBuffer.h » ('j') | 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 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkPictureShader.h" 8 #include "SkPictureShader.h"
9 9
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 } 103 }
104 104
105 sk_sp<SkShader> SkPictureShader::Make(sk_sp<SkPicture> picture, TileMode tmx, Ti leMode tmy, 105 sk_sp<SkShader> SkPictureShader::Make(sk_sp<SkPicture> picture, TileMode tmx, Ti leMode tmy,
106 const SkMatrix* localMatrix, const SkRect* tile) { 106 const SkMatrix* localMatrix, const SkRect* tile) {
107 if (!picture || picture->cullRect().isEmpty() || (tile && tile->isEmpty())) { 107 if (!picture || picture->cullRect().isEmpty() || (tile && tile->isEmpty())) {
108 return SkShader::MakeEmptyShader(); 108 return SkShader::MakeEmptyShader();
109 } 109 }
110 return sk_sp<SkShader>(new SkPictureShader(std::move(picture), tmx, tmy, loc alMatrix, tile)); 110 return sk_sp<SkShader>(new SkPictureShader(std::move(picture), tmx, tmy, loc alMatrix, tile));
111 } 111 }
112 112
113 SkFlattenable* SkPictureShader::CreateProc(SkReadBuffer& buffer) { 113 sk_sp<SkFlattenable> SkPictureShader::CreateProc(SkReadBuffer& buffer) {
114 SkMatrix lm; 114 SkMatrix lm;
115 buffer.readMatrix(&lm); 115 buffer.readMatrix(&lm);
116 TileMode mx = (TileMode)buffer.read32(); 116 TileMode mx = (TileMode)buffer.read32();
117 TileMode my = (TileMode)buffer.read32(); 117 TileMode my = (TileMode)buffer.read32();
118 SkRect tile; 118 SkRect tile;
119 buffer.readRect(&tile); 119 buffer.readRect(&tile);
120 120
121 sk_sp<SkPicture> picture; 121 sk_sp<SkPicture> picture;
122 122
123 if (buffer.isCrossProcess() && SkPicture::PictureIOSecurityPrecautionsEnable d()) { 123 if (buffer.isCrossProcess() && SkPicture::PictureIOSecurityPrecautionsEnable d()) {
124 if (buffer.isVersionLT(SkReadBuffer::kPictureShaderHasPictureBool_Versio n)) { 124 if (buffer.isVersionLT(SkReadBuffer::kPictureShaderHasPictureBool_Versio n)) {
125 // Older code blindly serialized pictures. We don't trust them. 125 // Older code blindly serialized pictures. We don't trust them.
126 buffer.validate(false); 126 buffer.validate(false);
127 return nullptr; 127 return nullptr;
128 } 128 }
129 // Newer code won't serialize pictures in disallow-cross-process-picture mode. 129 // Newer code won't serialize pictures in disallow-cross-process-picture mode.
130 // Assert that they didn't serialize anything except a false here. 130 // Assert that they didn't serialize anything except a false here.
131 buffer.validate(!buffer.readBool()); 131 buffer.validate(!buffer.readBool());
132 } else { 132 } else {
133 // Old code always serialized the picture. New code writes a 'true' fir st if it did. 133 // Old code always serialized the picture. New code writes a 'true' fir st if it did.
134 if (buffer.isVersionLT(SkReadBuffer::kPictureShaderHasPictureBool_Versio n) || 134 if (buffer.isVersionLT(SkReadBuffer::kPictureShaderHasPictureBool_Versio n) ||
135 buffer.readBool()) { 135 buffer.readBool()) {
136 picture = SkPicture::MakeFromBuffer(buffer); 136 picture = SkPicture::MakeFromBuffer(buffer);
137 } 137 }
138 } 138 }
139 return SkPictureShader::Make(picture, mx, my, &lm, &tile).release(); 139 return SkPictureShader::Make(picture, mx, my, &lm, &tile);
140 } 140 }
141 141
142 void SkPictureShader::flatten(SkWriteBuffer& buffer) const { 142 void SkPictureShader::flatten(SkWriteBuffer& buffer) const {
143 buffer.writeMatrix(this->getLocalMatrix()); 143 buffer.writeMatrix(this->getLocalMatrix());
144 buffer.write32(fTmx); 144 buffer.write32(fTmx);
145 buffer.write32(fTmy); 145 buffer.write32(fTmy);
146 buffer.writeRect(fTile); 146 buffer.writeRect(fTile);
147 147
148 // The deserialization code won't trust that our serialized picture is safe to deserialize. 148 // The deserialization code won't trust that our serialized picture is safe to deserialize.
149 // So write a 'false' telling it that we're not serializing a picture. 149 // So write a 'false' telling it that we're not serializing a picture.
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 if (context) { 327 if (context) {
328 maxTextureSize = context->caps()->maxTextureSize(); 328 maxTextureSize = context->caps()->maxTextureSize();
329 } 329 }
330 sk_sp<SkShader> bitmapShader(this->refBitmapShader(viewM, localMatrix, maxTe xtureSize)); 330 sk_sp<SkShader> bitmapShader(this->refBitmapShader(viewM, localMatrix, maxTe xtureSize));
331 if (!bitmapShader) { 331 if (!bitmapShader) {
332 return nullptr; 332 return nullptr;
333 } 333 }
334 return bitmapShader->asFragmentProcessor(context, viewM, nullptr, fq); 334 return bitmapShader->asFragmentProcessor(context, viewM, nullptr, fq);
335 } 335 }
336 #endif 336 #endif
OLDNEW
« no previous file with comments | « src/core/SkPathEffect.cpp ('k') | src/core/SkReadBuffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698