skia2/gm/texdata.cpp

156 lines
5.1 KiB
C++
Raw Normal View History

Automatic update of all copyright notices to reflect new license terms. I have manually examined all of these diffs and restored a few files that seem to require manual adjustment. The following files still need to be modified manually, in a separate CL: android_sample/SampleApp/AndroidManifest.xml android_sample/SampleApp/res/layout/layout.xml android_sample/SampleApp/res/menu/sample.xml android_sample/SampleApp/res/values/strings.xml android_sample/SampleApp/src/com/skia/sampleapp/SampleApp.java android_sample/SampleApp/src/com/skia/sampleapp/SampleView.java experimental/CiCarbonSampleMain.c experimental/CocoaDebugger/main.m experimental/FileReaderApp/main.m experimental/SimpleCocoaApp/main.m experimental/iOSSampleApp/Shared/SkAlertPrompt.h experimental/iOSSampleApp/Shared/SkAlertPrompt.m experimental/iOSSampleApp/SkiOSSampleApp-Base.xcconfig experimental/iOSSampleApp/SkiOSSampleApp-Debug.xcconfig experimental/iOSSampleApp/SkiOSSampleApp-Release.xcconfig gpu/src/android/GrGLDefaultInterface_android.cpp gyp/common.gypi gyp_skia include/ports/SkHarfBuzzFont.h include/views/SkOSWindow_wxwidgets.h make.bat make.py src/opts/memset.arm.S src/opts/memset16_neon.S src/opts/memset32_neon.S src/opts/opts_check_arm.cpp src/ports/SkDebug_brew.cpp src/ports/SkMemory_brew.cpp src/ports/SkOSFile_brew.cpp src/ports/SkXMLParser_empty.cpp src/utils/ios/SkImageDecoder_iOS.mm src/utils/ios/SkOSFile_iOS.mm src/utils/ios/SkStream_NSData.mm tests/FillPathTest.cpp Review URL: http://codereview.appspot.com/4816058 git-svn-id: http://skia.googlecode.com/svn/trunk@1982 2bbb7eff-a529-9590-31e7-b0007b416f81
2011-07-28 14:26:00 +00:00
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
// This test only works with the GPU backend.
#include "gm.h"
#if SK_SUPPORT_GPU
#include "GrContext.h"
#include "effects/GrSingleTextureEffect.h"
#include "SkColorPriv.h"
#include "SkDevice.h"
namespace skiagm {
extern GrContext* GetGr();
static const int S = 200;
class TexDataGM : public GM {
public:
TexDataGM() {
this->setBGColor(0xff000000);
}
protected:
virtual SkString onShortName() {
return SkString("texdata");
}
virtual SkISize onISize() {
return make_isize(2*S, 2*S);
}
virtual void onDraw(SkCanvas* canvas) {
SkDevice* device = canvas->getDevice();
GrRenderTarget* target = (GrRenderTarget*) device->accessRenderTarget();
GrContext* ctx = GetGr();
if (ctx && target) {
SkPMColor gTextureData[(2 * S) * (2 * S)];
static const int stride = 2 * S;
static const SkPMColor gray = SkPackARGB32(0x40, 0x40, 0x40, 0x40);
static const SkPMColor white = SkPackARGB32(0xff, 0xff, 0xff, 0xff);
static const SkPMColor red = SkPackARGB32(0x80, 0x80, 0x00, 0x00);
static const SkPMColor blue = SkPackARGB32(0x80, 0x00, 0x00, 0x80);
static const SkPMColor green = SkPackARGB32(0x80, 0x00, 0x80, 0x00);
static const SkPMColor black = SkPackARGB32(0x00, 0x00, 0x00, 0x00);
for (int i = 0; i < 2; ++i) {
int offset = 0;
// fill upper-left
for (int y = 0; y < S; ++y) {
for (int x = 0; x < S; ++x) {
gTextureData[offset + y * stride + x] = gray;
}
}
// fill upper-right
offset = S;
for (int y = 0; y < S; ++y) {
for (int x = 0; x < S; ++x) {
gTextureData[offset + y * stride + x] = white;
}
}
// fill lower left
offset = S * stride;
for (int y = 0; y < S; ++y) {
for (int x = 0; x < S; ++x) {
gTextureData[offset + y * stride + x] = black;
}
}
// fill lower right
offset = S * stride + S;
for (int y = 0; y < S; ++y) {
for (int x = 0; x < S; ++x) {
gTextureData[offset + y * stride + x] = gray;
}
}
GrTextureDesc desc;
// use RT flag bit because in GL it makes the texture be bottom-up
desc.fFlags = i ? kRenderTarget_GrTextureFlagBit :
kNone_GrTextureFlags;
desc.fConfig = kSkia8888_PM_GrPixelConfig;
desc.fWidth = 2 * S;
desc.fHeight = 2 * S;
GrTexture* texture =
ctx->createUncachedTexture(desc, gTextureData, 0);
if (!texture) {
return;
}
GrAutoUnref au(texture);
GrContext::AutoClip acs(ctx, GrRect::MakeWH(2*S, 2*S));
ctx->setRenderTarget(target);
GrPaint paint;
paint.reset();
paint.fColor = 0xffffffff;
paint.fSrcBlendCoeff = kOne_GrBlendCoeff;
paint.fDstBlendCoeff = kISA_GrBlendCoeff;
GrMatrix vm;
if (i) {
vm.setRotate(90 * SK_Scalar1,
S * SK_Scalar1,
S * SK_Scalar1);
} else {
vm.reset();
}
ctx->setMatrix(vm);
GrMatrix tm;
tm = vm;
GrMatrix* sampleMat = paint.textureSampler(0)->matrix();
*sampleMat = vm;
sampleMat->postIDiv(2*S, 2*S);
paint.textureSampler(0)->setCustomStage(
SkNEW_ARGS(GrSingleTextureEffect, (texture)))->unref();
ctx->drawRect(paint, GrRect::MakeWH(2*S, 2*S));
// now update the lower right of the texture in first pass
// or upper right in second pass
offset = 0;
for (int y = 0; y < S; ++y) {
for (int x = 0; x < S; ++x) {
gTextureData[offset + y * stride + x] =
((x + y) % 2) ? (i ? green : red) : blue;
}
}
texture->writePixels(S, (i ? 0 : S), S, S,
texture->config(), gTextureData,
4 * stride);
ctx->drawRect(paint, GrRect::MakeWH(2*S, 2*S));
}
}
}
private:
typedef GM INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
static GM* MyFactory(void*) { return new TexDataGM; }
static GMRegistry reg(MyFactory);
}
#endif