OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "SkImageGenerator.h" | 8 #include "SkImageGenerator.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkMatrix.h" | 10 #include "SkMatrix.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 const SkPixmap& scaledPixel
s) { | 101 const SkPixmap& scaledPixel
s) { |
102 int w = scaledSize.width(); | 102 int w = scaledSize.width(); |
103 int h = scaledSize.height(); | 103 int h = scaledSize.height(); |
104 | 104 |
105 const SkScalar scaleX = SkIntToScalar(w) / this->getInfo().width(); | 105 const SkScalar scaleX = SkIntToScalar(w) / this->getInfo().width(); |
106 const SkScalar scaleY = SkIntToScalar(h) / this->getInfo().height(); | 106 const SkScalar scaleY = SkIntToScalar(h) / this->getInfo().height(); |
107 SkMatrix matrix = SkMatrix::MakeScale(scaleX, scaleY); | 107 SkMatrix matrix = SkMatrix::MakeScale(scaleX, scaleY); |
108 matrix.postTranslate(-SkIntToScalar(scaledOrigin.x()), -SkIntToScalar(scaled
Origin.y())); | 108 matrix.postTranslate(-SkIntToScalar(scaledOrigin.x()), -SkIntToScalar(scaled
Origin.y())); |
109 | 109 |
110 SkBitmap bitmap; | 110 SkBitmap bitmap; |
111 if (!bitmap.installPixels(scaledPixels.info(), scaledPixels.writable_addr(), | 111 if (!bitmap.installPixels(scaledPixels)) { |
112 scaledPixels.rowBytes())) { | |
113 return false; | 112 return false; |
114 } | 113 } |
115 | 114 |
116 bitmap.eraseColor(SK_ColorTRANSPARENT); | 115 bitmap.eraseColor(SK_ColorTRANSPARENT); |
117 SkCanvas canvas(bitmap, SkSurfaceProps(0, kUnknown_SkPixelGeometry)); | 116 SkCanvas canvas(bitmap, SkSurfaceProps(0, kUnknown_SkPixelGeometry)); |
118 matrix.preConcat(fMatrix); | 117 matrix.preConcat(fMatrix); |
119 canvas.drawPicture(fPicture, &matrix, fPaint.getMaybeNull()); | 118 canvas.drawPicture(fPicture, &matrix, fPaint.getMaybeNull()); |
120 return true; | 119 return true; |
121 } | 120 } |
122 | 121 |
(...skipping 29 matching lines...) Expand all Loading... |
152 } | 151 } |
153 surface->getCanvas()->clear(0); // does NewRenderTarget promise to do this f
or us? | 152 surface->getCanvas()->clear(0); // does NewRenderTarget promise to do this f
or us? |
154 surface->getCanvas()->drawPicture(fPicture, &matrix, fPaint.getMaybeNull()); | 153 surface->getCanvas()->drawPicture(fPicture, &matrix, fPaint.getMaybeNull()); |
155 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); | 154 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); |
156 if (!image.get()) { | 155 if (!image.get()) { |
157 return nullptr; | 156 return nullptr; |
158 } | 157 } |
159 return SkSafeRef(image->getTexture()); | 158 return SkSafeRef(image->getTexture()); |
160 } | 159 } |
161 #endif | 160 #endif |
OLD | NEW |