Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
video_decoder.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2019 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
9#include "gm/gm.h"
12
13class VideoDecoderGM : public skiagm::GM {
14 SkVideoDecoder fDecoder;
15
16public:
18
19protected:
20 SkString getName() const override { return SkString("videodecoder"); }
21
22 SkISize getISize() override { return SkISize::Make(1024, 768); }
23
24 void onOnceBeforeDraw() override {
25 if (!fDecoder.loadStream(SkStream::MakeFromFile("/skia/ice.mp4"))) {
26 SkDebugf("could not load movie file\n");
27 }
28 SkDebugf("duration %g\n", fDecoder.duration());
29 }
30
31 void onDraw(SkCanvas* canvas) override {
32 auto* rContext = canvas->recordingContext();
33 if (!rContext) {
34 return;
35 }
36
37 fDecoder.setGrContext(rContext); // context can change over time in viewer
38
39 double timeStamp;
40 auto img = fDecoder.nextImage(&timeStamp);
41 if (!img) {
42 (void)fDecoder.rewind();
43 img = fDecoder.nextImage(&timeStamp);
44 }
45 if (img) {
46 if (0) {
47 SkDebugf("ts %g\n", timeStamp);
48 }
49 canvas->drawImage(img, 10, 10);
50 }
51 }
52
53 bool onAnimate(double nanos) override {
54 return true;
55 }
56
57private:
58 using INHERITED = GM;
59};
60DEF_GM( return new VideoDecoderGM; )
61
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
virtual GrRecordingContext * recordingContext() const
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition SkCanvas.h:1528
static std::unique_ptr< SkStreamAsset > MakeFromFile(const char path[])
Definition SkStream.cpp:922
double duration() const
void setGrContext(GrRecordingContext *rContext)
bool loadStream(std::unique_ptr< SkStream >)
sk_sp< SkImage > nextImage(double *timeStamp=nullptr)
void onOnceBeforeDraw() override
SkISize getISize() override
void onDraw(SkCanvas *canvas) override
bool onAnimate(double nanos) override
SkString getName() const override
GM(SkColor backgroundColor=SK_ColorWHITE)
Definition gm.cpp:81
#define DEF_GM(CODE)
Definition gm.h:40
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20