OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SampleCode.h" | 8 #include "SampleCode.h" |
9 #include "SkDumpCanvas.h" | 9 #include "SkDumpCanvas.h" |
10 #include "SkView.h" | 10 #include "SkView.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 BBoxType fBBox; | 116 BBoxType fBBox; |
117 SkSize fTileSize; | 117 SkSize fTileSize; |
118 | 118 |
119 SkPicture* LoadPicture(const char path[], BBoxType bbox) { | 119 SkPicture* LoadPicture(const char path[], BBoxType bbox) { |
120 SkAutoTUnref<SkPicture> pic; | 120 SkAutoTUnref<SkPicture> pic; |
121 | 121 |
122 SkBitmap bm; | 122 SkBitmap bm; |
123 if (SkImageDecoder::DecodeFile(path, &bm)) { | 123 if (SkImageDecoder::DecodeFile(path, &bm)) { |
124 bm.setImmutable(); | 124 bm.setImmutable(); |
125 SkPictureRecorder recorder; | 125 SkPictureRecorder recorder; |
126 SkCanvas* can = recorder.beginRecording(bm.width(), bm.height(), NUL
L, 0); | 126 SkCanvas* can = recorder.beginRecording(SkIntToScalar(bm.width()), |
| 127 SkIntToScalar(bm.height()), |
| 128 NULL, 0); |
127 can->drawBitmap(bm, 0, 0, NULL); | 129 can->drawBitmap(bm, 0, 0, NULL); |
128 pic.reset(recorder.endRecording()); | 130 pic.reset(recorder.endRecording()); |
129 } else { | 131 } else { |
130 SkFILEStream stream(path); | 132 SkFILEStream stream(path); |
131 if (stream.isValid()) { | 133 if (stream.isValid()) { |
132 pic.reset(SkPicture::CreateFromStream(&stream)); | 134 pic.reset(SkPicture::CreateFromStream(&stream)); |
133 } else { | 135 } else { |
134 SkDebugf("coun't load picture at \"path\"\n", path); | 136 SkDebugf("coun't load picture at \"path\"\n", path); |
135 } | 137 } |
136 | 138 |
137 if (false) { | 139 if (false) { |
138 SkSurface* surf = SkSurface::NewRasterPMColor(pic->width(), pic-
>height()); | 140 SkSurface* surf = SkSurface::NewRasterPMColor(SkScalarCeilToInt(
pic->cullRect().width()), |
| 141 SkScalarCeilToInt(
pic->cullRect().height())); |
139 surf->getCanvas()->drawPicture(pic); | 142 surf->getCanvas()->drawPicture(pic); |
140 surf->unref(); | 143 surf->unref(); |
141 } | 144 } |
142 if (false) { // re-record | 145 if (false) { // re-record |
143 SkPictureRecorder recorder; | 146 SkPictureRecorder recorder; |
144 pic->draw(recorder.beginRecording(pic->width(), pic->height(), N
ULL, 0)); | 147 pic->draw(recorder.beginRecording(pic->cullRect().width(), |
| 148 pic->cullRect().height(), |
| 149 NULL, 0)); |
145 SkAutoTUnref<SkPicture> p2(recorder.endRecording()); | 150 SkAutoTUnref<SkPicture> p2(recorder.endRecording()); |
146 | 151 |
147 SkString path2(path); | 152 SkString path2(path); |
148 path2.append(".new.skp"); | 153 path2.append(".new.skp"); |
149 SkFILEWStream writer(path2.c_str()); | 154 SkFILEWStream writer(path2.c_str()); |
150 p2->serialize(&writer); | 155 p2->serialize(&writer); |
151 } | 156 } |
152 } | 157 } |
153 | 158 |
154 if (NULL == pic) { | 159 if (NULL == pic) { |
(...skipping 15 matching lines...) Expand all Loading... |
170 gridInfo.fOffset = SkIPoint::Make(0, 0); | 175 gridInfo.fOffset = SkIPoint::Make(0, 0); |
171 gridInfo.fTileInterval = fTileSize.toRound(); | 176 gridInfo.fTileInterval = fTileSize.toRound(); |
172 factory.reset(SkNEW_ARGS(SkTileGridFactory, (gridInfo))); | 177 factory.reset(SkNEW_ARGS(SkTileGridFactory, (gridInfo))); |
173 break; | 178 break; |
174 } | 179 } |
175 default: | 180 default: |
176 SkASSERT(false); | 181 SkASSERT(false); |
177 } | 182 } |
178 | 183 |
179 SkPictureRecorder recorder; | 184 SkPictureRecorder recorder; |
180 pic->draw(recorder.beginRecording(pic->width(), pic->height(), factory.g
et(), 0)); | 185 pic->draw(recorder.beginRecording(pic->cullRect().width(), |
| 186 pic->cullRect().height(), |
| 187 factory.get(), 0)); |
181 return recorder.endRecording(); | 188 return recorder.endRecording(); |
182 } | 189 } |
183 | 190 |
184 typedef SampleView INHERITED; | 191 typedef SampleView INHERITED; |
185 }; | 192 }; |
186 | 193 |
187 SampleView* CreateSamplePictFileView(const char filename[]); | 194 SampleView* CreateSamplePictFileView(const char filename[]); |
188 SampleView* CreateSamplePictFileView(const char filename[]) { | 195 SampleView* CreateSamplePictFileView(const char filename[]) { |
189 return new PictFileView(filename); | 196 return new PictFileView(filename); |
190 } | 197 } |
191 | 198 |
192 ////////////////////////////////////////////////////////////////////////////// | 199 ////////////////////////////////////////////////////////////////////////////// |
193 | 200 |
194 #if 0 | 201 #if 0 |
195 static SkView* MyFactory() { return new PictFileView; } | 202 static SkView* MyFactory() { return new PictFileView; } |
196 static SkViewRegister reg(MyFactory); | 203 static SkViewRegister reg(MyFactory); |
197 #endif | 204 #endif |
OLD | NEW |