Flutter Engine
The Flutter Engine
Functions
GrAtlasTools.cpp File Reference
#include "tools/gpu/ganesh/GrAtlasTools.h"
#include "include/core/SkAlphaType.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkColorType.h"
#include "include/core/SkDataTable.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkStream.h"
#include "include/core/SkString.h"
#include "include/encode/SkPngEncoder.h"
#include "include/gpu/GrDirectContext.h"
#include "include/private/base/SkDebug.h"
#include "src/gpu/ganesh/GrDirectContextPriv.h"
#include "src/gpu/ganesh/GrSurfaceProxy.h"
#include "src/gpu/ganesh/GrSurfaceProxyView.h"
#include "src/gpu/ganesh/SurfaceContext.h"
#include <cstdio>
#include <utility>

Go to the source code of this file.

Functions

static bool save_pixels (GrDirectContext *dContext, GrSurfaceProxyView view, GrColorType colorType, const char *filename)
 

Function Documentation

◆ save_pixels()

static bool save_pixels ( GrDirectContext dContext,
GrSurfaceProxyView  view,
GrColorType  colorType,
const char *  filename 
)
static

Write the contents of the surface proxy to a PNG. Returns true if successful.

Parameters
filenameFull path to desired file

Definition at line 33 of file GrAtlasTools.cpp.

36 {
37 if (!view.proxy()) {
38 return false;
39 }
40
41 auto ii = SkImageInfo::Make(
43 SkBitmap bm;
44 if (!bm.tryAllocPixels(ii)) {
45 return false;
46 }
47
48 auto sContext =
49 dContext->priv().makeSC(std::move(view), {colorType, kUnknown_SkAlphaType, nullptr});
50 if (!sContext || !sContext->asTextureProxy()) {
51 return false;
52 }
53
54 bool result = sContext->readPixels(dContext, bm.pixmap(), {0, 0});
55 if (!result) {
56 SkDebugf("------ failed to read pixels for %s\n", filename);
57 return false;
58 }
59
60 // remove any previous version of this file
61 remove(filename);
62
63 SkFILEWStream file(filename);
64 if (!file.isValid()) {
65 SkDebugf("------ failed to create file: %s\n", filename);
66 remove(filename); // remove any partial file
67 return false;
68 }
69
70 if (!SkPngEncoder::Encode(&file, bm.pixmap(), {})) {
71 SkDebugf("------ failed to encode %s\n", filename);
72 remove(filename); // remove any partial file
73 return false;
74 }
75
76 return true;
77}
@ kUnknown_SkAlphaType
uninitialized
Definition: SkAlphaType.h:27
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
GrDirectContextPriv priv()
std::unique_ptr< skgpu::ganesh::SurfaceContext > makeSC(GrSurfaceProxyView readView, const GrColorInfo &)
GrSurfaceProxy * proxy() const
SkISize dimensions() const
const SkPixmap & pixmap() const
Definition: SkBitmap.h:133
bool tryAllocPixels(const SkImageInfo &info, size_t rowBytes)
Definition: SkBitmap.cpp:271
GAsyncResult * result
SK_API bool Encode(SkWStream *dst, const SkPixmap &src, const Options &options)
def remove(*paths)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)