2019-01-15 18:24:45 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkTypes.h" // IWYU pragma: keep
|
|
|
|
|
|
|
|
#if !defined(SK_BUILD_FOR_GOOGLE3)
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkData.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkImage.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkImageInfo.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
2019-04-24 17:46:06 +00:00
|
|
|
#include "third_party/etc1/etc1.h"
|
2019-01-15 18:24:45 +00:00
|
|
|
|
2019-05-01 21:28:53 +00:00
|
|
|
class GrContext;
|
|
|
|
class GrRenderTargetContext;
|
2019-01-15 18:24:45 +00:00
|
|
|
|
|
|
|
// Basic test of Ganesh's ETC1 support
|
2019-02-07 22:23:36 +00:00
|
|
|
class ETC1GM : public skiagm::GpuGM {
|
2019-01-15 18:24:45 +00:00
|
|
|
public:
|
|
|
|
ETC1GM() {
|
|
|
|
this->setBGColor(0xFFCCCCCC);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkString onShortName() override {
|
|
|
|
return SkString("etc1");
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize onISize() override {
|
|
|
|
return SkISize::Make(kTexWidth + 2*kPad, kTexHeight + 2*kPad);
|
|
|
|
}
|
|
|
|
|
|
|
|
void onOnceBeforeDraw() override {
|
|
|
|
SkBitmap bm;
|
|
|
|
SkImageInfo ii = SkImageInfo::Make(kTexWidth, kTexHeight, kRGB_565_SkColorType,
|
|
|
|
kOpaque_SkAlphaType);
|
|
|
|
bm.allocPixels(ii);
|
|
|
|
|
|
|
|
bm.erase(SK_ColorBLUE, SkIRect::MakeWH(kTexWidth, kTexHeight));
|
|
|
|
|
|
|
|
for (int y = 0; y < kTexHeight; y += 4) {
|
|
|
|
for (int x = 0; x < kTexWidth; x += 4) {
|
|
|
|
bm.erase((x+y) % 8 ? SK_ColorRED : SK_ColorGREEN, SkIRect::MakeXYWH(x, y, 4, 4));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int size = etc1_get_encoded_data_size(bm.width(), bm.height());
|
2019-01-18 15:36:32 +00:00
|
|
|
fETC1Data = SkData::MakeUninitialized(size);
|
2019-01-15 18:24:45 +00:00
|
|
|
|
2019-01-18 15:36:32 +00:00
|
|
|
unsigned char* pixels = (unsigned char*) fETC1Data->writable_data();
|
2019-01-15 18:24:45 +00:00
|
|
|
|
|
|
|
if (etc1_encode_image((unsigned char*) bm.getAddr16(0, 0),
|
|
|
|
bm.width(), bm.height(), 2, bm.rowBytes(), pixels)) {
|
2019-01-18 15:36:32 +00:00
|
|
|
fETC1Data = nullptr;
|
2019-01-15 18:24:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-07 23:20:09 +00:00
|
|
|
void onDraw(GrContext* context, GrRenderTargetContext*, SkCanvas* canvas) override {
|
2019-01-18 15:36:32 +00:00
|
|
|
sk_sp<SkImage> image = SkImage::MakeFromCompressed(context, fETC1Data,
|
|
|
|
kTexWidth, kTexHeight,
|
|
|
|
SkImage::kETC1_CompressionType);
|
2019-01-15 18:24:45 +00:00
|
|
|
|
2019-01-18 15:36:32 +00:00
|
|
|
canvas->drawImage(image, 0, 0);
|
2019-01-15 18:24:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static const int kPad = 8;
|
|
|
|
static const int kTexWidth = 16;
|
|
|
|
static const int kTexHeight = 20;
|
|
|
|
|
2019-01-18 15:36:32 +00:00
|
|
|
sk_sp<SkData> fETC1Data;
|
2019-01-15 18:24:45 +00:00
|
|
|
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
DEF_GM(return new ETC1GM;)
|
|
|
|
|
|
|
|
#endif
|