Switch to pixmap in API.

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1712653002

Review URL: https://codereview.chromium.org/1712653002
This commit is contained in:
herb 2016-02-18 13:55:02 -08:00 committed by Commit bot
parent c85d9fbc0a
commit ed545042fc
5 changed files with 34 additions and 32 deletions

View File

@ -142,8 +142,10 @@ struct SkBitmapFPGeneral final : public CommonBitmapFPBenchmark {
filterQuality = SkFilterQuality::kNone_SkFilterQuality;
}
SkPixmap srcPixmap{fInfo, fBitmap.get(), static_cast<size_t>(4 * width)};
SkLinearBitmapPipeline pipeline{
fInvert, filterQuality, fXTile, fYTile, fInfo, fBitmap.get() };
fInvert, filterQuality, fXTile, fYTile, srcPixmap};
int count = 100;

View File

@ -98,7 +98,6 @@ static void draw_rect_fp(SkCanvas* canvas, const SkRect& r, SkColor c, const SkM
bmdst.peekPixels(&pmdst);
SkPM4f* dstBits = new SkPM4f[ir.width()];
SkImageInfo info = SkImageInfo::MakeN32(ir.width(), ir.height(), kPremul_SkAlphaType);
SkMatrix inv;
bool trash = mat->invert(&inv);
@ -120,8 +119,7 @@ static void draw_rect_fp(SkCanvas* canvas, const SkRect& r, SkColor c, const SkM
SkLinearBitmapPipeline pipeline{
inv, filterQuality,
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode,
info, pmsrc.addr32()};
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, pmsrc};
for (int y = 0; y < ir.height(); y++) {
pipeline.shadeSpan4f(0, y, dstBits, ir.width());

View File

@ -8,6 +8,12 @@
#include "SkLinearBitmapPipeline.h"
#include "SkPM4f.h"
#include <algorithm>
#include <cmath>
#include <limits>
#include "SkColor.h"
#include "SkSize.h"
struct X {
explicit X(SkScalar val) : fVal{val} { }
explicit X(SkPoint pt) : fVal{pt.fX} { }
@ -191,18 +197,18 @@ public:
void pointListFew(int n, Sk4fArg xs, Sk4fArg ys) override {
SkASSERT(0 < n && n < 4);
// px00 px10 px01 px11
const Sk4f kXOffsets{0.0f, 1.0f, 0.0f, 1.0f},
kYOffsets{0.0f, 0.0f, 1.0f, 1.0f};
// px00 px10 px01 px11
const Sk4f kXOffsets{-0.5f, 0.5f, -0.5f, 0.5f},
kYOffsets{-0.5f, -0.5f, 0.5f, 0.5f};
if (n >= 1) fNext->bilerpList(Sk4f{xs[0]} + kXOffsets, Sk4f{ys[0]} + kYOffsets);
if (n >= 2) fNext->bilerpList(Sk4f{xs[1]} + kXOffsets, Sk4f{ys[1]} + kYOffsets);
if (n >= 3) fNext->bilerpList(Sk4f{xs[2]} + kXOffsets, Sk4f{ys[2]} + kYOffsets);
}
void pointList4(Sk4fArg xs, Sk4fArg ys) override {
// px00 px10 px01 px11
const Sk4f kXOffsets{0.0f, 1.0f, 0.0f, 1.0f},
kYOffsets{0.0f, 0.0f, 1.0f, 1.0f};
// px00 px10 px01 px11
const Sk4f kXOffsets{-0.5f, 0.5f, -0.5f, 0.5f},
kYOffsets{-0.5f, -0.5f, 0.5f, 0.5f};
fNext->bilerpList(Sk4f{xs[0]} + kXOffsets, Sk4f{ys[0]} + kYOffsets);
fNext->bilerpList(Sk4f{xs[1]} + kXOffsets, Sk4f{ys[1]} + kYOffsets);
fNext->bilerpList(Sk4f{xs[2]} + kXOffsets, Sk4f{ys[2]} + kYOffsets);
@ -456,21 +462,21 @@ private:
static BilerpProcessorInterface* choose_pixel_sampler(
PixelPlacerInterface* next,
const SkImageInfo& imageInfo,
const void* imageData,
const SkPixmap& srcPixmap,
SkLinearBitmapPipeline::SampleStage* sampleStage) {
const SkImageInfo& imageInfo = srcPixmap.info();
switch (imageInfo.colorType()) {
case kRGBA_8888_SkColorType:
case kBGRA_8888_SkColorType:
if (kN32_SkColorType == imageInfo.colorType()) {
if (imageInfo.profileType() == kSRGB_SkColorProfileType) {
sampleStage->Initialize<Sampler<Passthrough8888<kSRGB_SkColorProfileType>>>(
next, imageInfo.width(),
(uint32_t*)imageData);
next, static_cast<int>(srcPixmap.rowBytes() / 4),
srcPixmap.addr32());
} else {
sampleStage->Initialize<Sampler<Passthrough8888<kLinear_SkColorProfileType>>>(
next, imageInfo.width(),
(uint32_t*)imageData);
next, static_cast<int>(srcPixmap.rowBytes() / 4),
srcPixmap.addr32());
}
} else {
SkFAIL("Not implemented. No 8888 Swizzle");
@ -536,16 +542,14 @@ SkLinearBitmapPipeline::SkLinearBitmapPipeline(
const SkMatrix& inverse,
SkFilterQuality filterQuality,
SkShader::TileMode xTile, SkShader::TileMode yTile,
const SkImageInfo& srcImageInfo,
const void* srcImageData) {
SkSize size;
size = srcImageInfo.dimensions();
const SkPixmap& srcPixmap) {
SkSize size = SkSize::Make(srcPixmap.width(), srcPixmap.height());
const SkImageInfo& srcImageInfo = srcPixmap.info();
// As the stages are built, the chooser function may skip a stage. For example, with the
// identity matrix, the matrix stage is skipped, and the tilerStage is the first stage.
auto placementStage = choose_pixel_placer(srcImageInfo.alphaType(), &fPixelStage);
auto samplerStage = choose_pixel_sampler(placementStage, srcImageInfo,
srcImageData, &fSampleStage);
auto samplerStage = choose_pixel_sampler(placementStage, srcPixmap, &fSampleStage);
auto tilerStage = choose_tiler(samplerStage, size, xTile, yTile, &fTileXOrBothStage,
&fTileYStage);
auto filterStage = choose_filter(tilerStage, filterQuality, &fFilterStage);

View File

@ -8,16 +8,12 @@
#ifndef SkLinearBitmapPipeline_DEFINED
#define SkLinearBitmapPipeline_DEFINED
#include <algorithm>
#include <cmath>
#include <limits>
#include <cstdio>
#include "SkColor.h"
#include "SkImageInfo.h"
#include "SkMatrix.h"
#include "SkShader.h"
#include "SkSize.h"
#include "SkNx.h"
#include "SkShader.h"
using Sk4fArg = const Sk4f&;
@ -59,8 +55,7 @@ public:
const SkMatrix& inverse,
SkFilterQuality filterQuality,
SkShader::TileMode xTile, SkShader::TileMode yTile,
const SkImageInfo& srcImageInfo,
const void* srcImageData);
const SkPixmap& srcPixmap);
void shadeSpan4f(int x, int y, SkPM4f* dst, int count);

View File

@ -41,13 +41,15 @@ DEF_TEST(SkBitmapFP, reporter) {
const SkImageInfo info =
SkImageInfo::MakeN32Premul(width, height, kLinear_SkColorProfileType);
SkPixmap srcPixmap{info, bitmap, static_cast<size_t>(4 * width)};
SkLinearBitmapPipeline pipeline{invert, kNone_SkFilterQuality, SkShader::kClamp_TileMode,
SkShader::kClamp_TileMode, info, bitmap};
SkShader::kClamp_TileMode, srcPixmap};
int count = 10;
pipeline.shadeSpan4f(3, 6, FPbuffer, count);
#if 0
Pixel* pixelBuffer = (Pixel*)FPbuffer;
for (int i = 0; i < count; i++) {
printf("i: %d - (%g, %g, %g, %g)\n", i,
@ -56,6 +58,7 @@ DEF_TEST(SkBitmapFP, reporter) {
pixelBuffer[i][2] * 255.0f,
pixelBuffer[i][3] * 255.0f);
}
#endif
delete [] bitmap;
delete [] FPbuffer;