Flutter Engine
The Flutter Engine
CodecExactReadTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2017 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
11#include "include/core/SkData.h"
16#include "tests/Test.h"
17#include "tools/Resources.h"
18
19#include <cstring>
20#include <initializer_list>
21#include <memory>
22#include <utility>
23
24namespace {
25// This class wraps another SkStream. It does not own the underlying stream, so
26// that the underlying stream can be reused starting from where the first
27// client left off. This mimics Android's JavaInputStreamAdaptor.
28class UnowningStream : public SkStream {
29public:
30 explicit UnowningStream(SkStream* stream)
31 : fStream(stream)
32 {}
33
34 size_t read(void* buf, size_t bytes) override {
35 return fStream->read(buf, bytes);
36 }
37
38 bool rewind() override {
39 return fStream->rewind();
40 }
41
42 bool isAtEnd() const override {
43 return fStream->isAtEnd();
44 }
45private:
46 SkStream* fStream; // Unowned.
47};
48} // namespace
49
50// Test that some SkCodecs do not attempt to read input beyond the logical
51// end of the data. Some other SkCodecs do, but some Android apps rely on not
52// doing so for PNGs. Test on other formats that work.
53DEF_TEST(Codec_end, r) {
54 for (const char* path : { "images/plane.png",
55 "images/yellow_rose.png",
56 "images/plane_interlaced.png",
57 "images/mandrill.wbmp",
58 "images/randPixels.bmp",
59 }) {
61 if (!data) {
62 continue;
63 }
64
65 const int kNumImages = 2;
66 const size_t size = data->size();
67 sk_sp<SkData> multiData = SkData::MakeUninitialized(size * kNumImages);
68 void* dst = multiData->writable_data();
69 for (int i = 0; i < kNumImages; i++) {
70 memcpy(SkTAddOffset<void>(dst, size * i), data->data(), size);
71 }
72 data.reset();
73
74 SkMemoryStream stream(std::move(multiData));
75 for (int i = 0; i < kNumImages; ++i) {
76 std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(
77 std::make_unique<UnowningStream>(&stream)));
78 if (!codec) {
79 ERRORF(r, "Failed to create a codec from %s, iteration %i", path, i);
80 continue;
81 }
82
83 auto info = codec->getInfo().makeColorType(kN32_SkColorType);
84 SkBitmap bm;
85 bm.allocPixels(info);
86
87 auto result = codec->getPixels(bm.info(), bm.getPixels(), bm.rowBytes());
89 ERRORF(r, "Failed to getPixels from %s, iteration %i error %i", path, i, result);
90 continue;
91 }
92 }
93 }
94}
DEF_TEST(Codec_end, r)
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
sk_sp< SkData > GetResourceAsData(const char *resource)
Definition: Resources.cpp:42
#define ERRORF(r,...)
Definition: Test.h:293
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition: SkBitmap.cpp:258
size_t rowBytes() const
Definition: SkBitmap.h:238
void * getPixels() const
Definition: SkBitmap.h:283
const SkImageInfo & info() const
Definition: SkBitmap.h:139
static std::unique_ptr< SkCodec > MakeFromStream(std::unique_ptr< SkStream >, SkSpan< const SkCodecs::Decoder > decoders, Result *=nullptr, SkPngChunkReader *=nullptr, SelectionPolicy selectionPolicy=SelectionPolicy::kPreferStillImage)
Definition: SkCodec.cpp:163
@ kSuccess
Definition: SkCodec.h:80
static sk_sp< SkData > MakeUninitialized(size_t length)
Definition: SkData.cpp:116
void * writable_data()
Definition: SkData.h:52
virtual bool rewind()
Definition: SkStream.h:100
virtual bool isAtEnd() const =0
virtual size_t read(void *buffer, size_t size)=0
GAsyncResult * result
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
dst
Definition: cp.py:12
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63