| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 110 |
| 111 void onDrawContent(SkCanvas* canvas) override { | 111 void onDrawContent(SkCanvas* canvas) override { |
| 112 SkASSERT(static_cast<int>(fBBox) < kBBoxTypeCount); | 112 SkASSERT(static_cast<int>(fBBox) < kBBoxTypeCount); |
| 113 SkPicture** picture = fPictures + fBBox; | 113 SkPicture** picture = fPictures + fBBox; |
| 114 | 114 |
| 115 #ifdef SK_GLYPHCACHE_TRACK_HASH_STATS | 115 #ifdef SK_GLYPHCACHE_TRACK_HASH_STATS |
| 116 SkGraphics::PurgeFontCache(); | 116 SkGraphics::PurgeFontCache(); |
| 117 #endif | 117 #endif |
| 118 | 118 |
| 119 if (!*picture) { | 119 if (!*picture) { |
| 120 *picture = LoadPicture(fFilename.c_str(), fBBox); | 120 *picture = LoadPicture(fFilename.c_str(), fBBox).release(); |
| 121 } | 121 } |
| 122 if (*picture) { | 122 if (*picture) { |
| 123 SkCounterDrawFilter filter(fCount); | 123 SkCounterDrawFilter filter(fCount); |
| 124 if (fCount > 0) { | 124 if (fCount > 0) { |
| 125 canvas->setDrawFilter(&filter); | 125 canvas->setDrawFilter(&filter); |
| 126 } | 126 } |
| 127 canvas->drawPicture(*picture); | 127 canvas->drawPicture(*picture); |
| 128 canvas->setDrawFilter(nullptr); | 128 canvas->setDrawFilter(nullptr); |
| 129 } | 129 } |
| 130 | 130 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 142 kLast_BBoxType = kRTree_BBoxType, | 142 kLast_BBoxType = kRTree_BBoxType, |
| 143 }; | 143 }; |
| 144 static const int kBBoxTypeCount = kLast_BBoxType + 1; | 144 static const int kBBoxTypeCount = kLast_BBoxType + 1; |
| 145 | 145 |
| 146 SkString fFilename; | 146 SkString fFilename; |
| 147 SkPicture* fPictures[kBBoxTypeCount]; | 147 SkPicture* fPictures[kBBoxTypeCount]; |
| 148 BBoxType fBBox; | 148 BBoxType fBBox; |
| 149 SkSize fTileSize; | 149 SkSize fTileSize; |
| 150 int fCount; | 150 int fCount; |
| 151 | 151 |
| 152 SkPicture* LoadPicture(const char path[], BBoxType bbox) { | 152 sk_sp<SkPicture> LoadPicture(const char path[], BBoxType bbox) { |
| 153 SkAutoTUnref<SkPicture> pic; | 153 sk_sp<SkPicture> pic; |
| 154 | 154 |
| 155 SkBitmap bm; | 155 SkBitmap bm; |
| 156 if (SkImageDecoder::DecodeFile(path, &bm)) { | 156 if (SkImageDecoder::DecodeFile(path, &bm)) { |
| 157 bm.setImmutable(); | 157 bm.setImmutable(); |
| 158 SkPictureRecorder recorder; | 158 SkPictureRecorder recorder; |
| 159 SkCanvas* can = recorder.beginRecording(SkIntToScalar(bm.width()), | 159 SkCanvas* can = recorder.beginRecording(SkIntToScalar(bm.width()), |
| 160 SkIntToScalar(bm.height()), | 160 SkIntToScalar(bm.height()), |
| 161 nullptr, 0); | 161 nullptr, 0); |
| 162 can->drawBitmap(bm, 0, 0, nullptr); | 162 can->drawBitmap(bm, 0, 0, nullptr); |
| 163 pic.reset(recorder.endRecording()); | 163 pic = recorder.finishRecordingAsPicture(); |
| 164 } else { | 164 } else { |
| 165 SkFILEStream stream(path); | 165 SkFILEStream stream(path); |
| 166 if (stream.isValid()) { | 166 if (stream.isValid()) { |
| 167 pic.reset(SkPicture::CreateFromStream(&stream)); | 167 pic = SkPicture::MakeFromStream(&stream); |
| 168 } else { | 168 } else { |
| 169 SkDebugf("coun't load picture at \"path\"\n", path); | 169 SkDebugf("coun't load picture at \"path\"\n", path); |
| 170 } | 170 } |
| 171 | 171 |
| 172 if (false) { // re-record | 172 if (false) { // re-record |
| 173 SkPictureRecorder recorder; | 173 SkPictureRecorder recorder; |
| 174 pic->playback(recorder.beginRecording(pic->cullRect().width(), | 174 pic->playback(recorder.beginRecording(pic->cullRect().width(), |
| 175 pic->cullRect().height(), | 175 pic->cullRect().height(), |
| 176 nullptr, 0)); | 176 nullptr, 0)); |
| 177 SkAutoTUnref<SkPicture> p2(recorder.endRecording()); | 177 sk_sp<SkPicture> p2(recorder.finishRecordingAsPicture()); |
| 178 | 178 |
| 179 SkString path2(path); | 179 SkString path2(path); |
| 180 path2.append(".new.skp"); | 180 path2.append(".new.skp"); |
| 181 SkFILEWStream writer(path2.c_str()); | 181 SkFILEWStream writer(path2.c_str()); |
| 182 p2->serialize(&writer); | 182 p2->serialize(&writer); |
| 183 } | 183 } |
| 184 } | 184 } |
| 185 | 185 |
| 186 if (nullptr == pic) { | 186 if (nullptr == pic) { |
| 187 return nullptr; | 187 return nullptr; |
| 188 } | 188 } |
| 189 | 189 |
| 190 SkAutoTDelete<SkBBHFactory> factory; | 190 SkAutoTDelete<SkBBHFactory> factory; |
| 191 switch (bbox) { | 191 switch (bbox) { |
| 192 case kNo_BBoxType: | 192 case kNo_BBoxType: |
| 193 // no bbox playback necessary | 193 // no bbox playback necessary |
| 194 return pic.release(); | 194 return std::move(pic); |
| 195 case kRTree_BBoxType: | 195 case kRTree_BBoxType: |
| 196 factory.reset(new SkRTreeFactory); | 196 factory.reset(new SkRTreeFactory); |
| 197 break; | 197 break; |
| 198 default: | 198 default: |
| 199 SkASSERT(false); | 199 SkASSERT(false); |
| 200 } | 200 } |
| 201 | 201 |
| 202 SkPictureRecorder recorder; | 202 SkPictureRecorder recorder; |
| 203 pic->playback(recorder.beginRecording(pic->cullRect().width(), | 203 pic->playback(recorder.beginRecording(pic->cullRect().width(), |
| 204 pic->cullRect().height(), | 204 pic->cullRect().height(), |
| 205 factory.get(), 0)); | 205 factory.get(), 0)); |
| 206 return recorder.endRecording(); | 206 return recorder.finishRecordingAsPicture(); |
| 207 } | 207 } |
| 208 | 208 |
| 209 typedef SampleView INHERITED; | 209 typedef SampleView INHERITED; |
| 210 }; | 210 }; |
| 211 | 211 |
| 212 SampleView* CreateSamplePictFileView(const char filename[]); | 212 SampleView* CreateSamplePictFileView(const char filename[]); |
| 213 SampleView* CreateSamplePictFileView(const char filename[]) { | 213 SampleView* CreateSamplePictFileView(const char filename[]) { |
| 214 return new PictFileView(filename); | 214 return new PictFileView(filename); |
| 215 } | 215 } |
| 216 | 216 |
| 217 ////////////////////////////////////////////////////////////////////////////// | 217 ////////////////////////////////////////////////////////////////////////////// |
| 218 | 218 |
| 219 #if 0 | 219 #if 0 |
| 220 static SkView* MyFactory() { return new PictFileView; } | 220 static SkView* MyFactory() { return new PictFileView; } |
| 221 static SkViewRegister reg(MyFactory); | 221 static SkViewRegister reg(MyFactory); |
| 222 #endif | 222 #endif |
| OLD | NEW |