OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2011 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 #include "SkMovie.h" | |
8 #include "SkCanvas.h" | |
9 #include "SkPaint.h" | |
10 | |
11 // We should never see this in normal operation since our time values are | |
12 // 0-based. So we use it as a sentinal. | |
13 #define UNINITIALIZED_MSEC ((SkMSec)-1) | |
14 | |
15 SkMovie::SkMovie() | |
16 { | |
17 fInfo.fDuration = UNINITIALIZED_MSEC; // uninitialized | |
18 fCurrTime = UNINITIALIZED_MSEC; // uninitialized | |
19 fNeedBitmap = true; | |
20 } | |
21 | |
22 void SkMovie::ensureInfo() | |
23 { | |
24 if (fInfo.fDuration == UNINITIALIZED_MSEC && !this->onGetInfo(&fInfo)) | |
25 memset(&fInfo, 0, sizeof(fInfo)); // failure | |
26 } | |
27 | |
28 SkMSec SkMovie::duration() | |
29 { | |
30 this->ensureInfo(); | |
31 return fInfo.fDuration; | |
32 } | |
33 | |
34 int SkMovie::width() | |
35 { | |
36 this->ensureInfo(); | |
37 return fInfo.fWidth; | |
38 } | |
39 | |
40 int SkMovie::height() | |
41 { | |
42 this->ensureInfo(); | |
43 return fInfo.fHeight; | |
44 } | |
45 | |
46 int SkMovie::isOpaque() | |
47 { | |
48 this->ensureInfo(); | |
49 return fInfo.fIsOpaque; | |
50 } | |
51 | |
52 bool SkMovie::setTime(SkMSec time) | |
53 { | |
54 SkMSec dur = this->duration(); | |
55 if (time > dur) | |
56 time = dur; | |
57 | |
58 bool changed = false; | |
59 if (time != fCurrTime) | |
60 { | |
61 fCurrTime = time; | |
62 changed = this->onSetTime(time); | |
63 fNeedBitmap |= changed; | |
64 } | |
65 return changed; | |
66 } | |
67 | |
68 const SkBitmap& SkMovie::bitmap() | |
69 { | |
70 if (fCurrTime == UNINITIALIZED_MSEC) // uninitialized | |
71 this->setTime(0); | |
72 | |
73 if (fNeedBitmap) | |
74 { | |
75 if (!this->onGetBitmap(&fBitmap)) // failure | |
76 fBitmap.reset(); | |
77 fNeedBitmap = false; | |
78 } | |
79 return fBitmap; | |
80 } | |
81 | |
82 //////////////////////////////////////////////////////////////////// | |
83 | |
84 #include "SkStream.h" | |
85 | |
86 SkMovie* SkMovie::DecodeMemory(const void* data, size_t length) { | |
87 SkMemoryStream stream(data, length, false); | |
88 return SkMovie::DecodeStream(&stream); | |
89 } | |
90 | |
91 SkMovie* SkMovie::DecodeFile(const char path[]) { | |
92 std::unique_ptr<SkStreamRewindable> stream = SkStream::MakeFromFile(path); | |
93 return stream ? SkMovie::DecodeStream(stream.get()) : nullptr; | |
94 } | |
OLD | NEW |