skia2/gm/texdata.cpp

143 lines
4.3 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 "GrContextPriv.h"
#include "GrRenderTargetContext.h"
#include "GrTextureContext.h"
#include "GrFixedClip.h"
#include "SkColorPriv.h"
#include "SkGr.h"
#include "effects/GrPorterDuffXferProcessor.h"
#include "effects/GrSimpleTextureEffect.h"
constexpr int S = 200;
constexpr int kStride = 2 * S;
// Fill in the pixels:
// gray | white
// -------------
// black | gray
static void fill_in_pixels(SkPMColor* pixels) {
const SkPMColor gray = SkPackARGB32(0x40, 0x40, 0x40, 0x40);
const SkPMColor white = SkPackARGB32(0xff, 0xff, 0xff, 0xff);
const SkPMColor black = SkPackARGB32(0x00, 0x00, 0x00, 0x00);
int offset = 0;
// fill upper-left
for (int y = 0; y < S; ++y) {
for (int x = 0; x < S; ++x) {
pixels[offset + y * kStride + x] = gray;
}
}
// fill upper-right
offset = S;
for (int y = 0; y < S; ++y) {
for (int x = 0; x < S; ++x) {
pixels[offset + y * kStride + x] = white;
}
}
// fill lower left
offset = S * kStride;
for (int y = 0; y < S; ++y) {
for (int x = 0; x < S; ++x) {
pixels[offset + y * kStride + x] = black;
}
}
// fill lower right
offset = S * kStride + S;
for (int y = 0; y < S; ++y) {
for (int x = 0; x < S; ++x) {
pixels[offset + y * kStride + x] = gray;
}
}
}
DEF_SIMPLE_GM_BG(texdata, canvas, 2 * S, 2 * S, SK_ColorBLACK) {
GrRenderTargetContext* renderTargetContext =
canvas->internal_private_accessTopLayerRenderTargetContext();
if (!renderTargetContext) {
skiagm::GM::DrawGpuOnlyMessage(canvas);
return;
}
GrContext* context = canvas->getGrContext();
if (!context) {
return;
}
const SkImageInfo ii = SkImageInfo::Make(S, S, kBGRA_8888_SkColorType, kPremul_SkAlphaType);
SkAutoTArray<SkPMColor> gTextureData((2 * S) * (2 * S));
const SkPMColor red = SkPackARGB32(0x80, 0x80, 0x00, 0x00);
const SkPMColor blue = SkPackARGB32(0x80, 0x00, 0x00, 0x80);
const SkPMColor green = SkPackARGB32(0x80, 0x00, 0x80, 0x00);
for (int i = 0; i < 2; ++i) {
fill_in_pixels(gTextureData.get());
GrSurfaceDesc desc;
desc.fOrigin = i ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin;
desc.fWidth = 2 * S;
desc.fHeight = 2 * S;
desc.fConfig = SkImageInfo2GrPixelConfig(ii, *context->caps());
sk_sp<GrTextureProxy> proxy = GrSurfaceProxy::MakeDeferred(context->resourceProvider(),
desc, SkBudgeted::kNo,
gTextureData.get(), 0);
if (!proxy) {
return;
}
sk_sp<GrSurfaceContext> tContext = context->contextPriv().makeWrappedSurfaceContext(
std::move(proxy), nullptr);
if (!tContext) {
return;
}
// setup new clip
GrFixedClip clip(SkIRect::MakeWH(2*S, 2*S));
GrPaint paint;
paint.setPorterDuffXPFactory(SkBlendMode::kSrcOver);
SkMatrix vm;
if (i) {
vm.setRotate(90 * SK_Scalar1, S * SK_Scalar1, S * SK_Scalar1);
} else {
vm.reset();
}
paint.addColorTextureProcessor(tContext->asTextureProxyRef(), vm);
renderTargetContext->drawRect(clip, GrPaint::Clone(paint), GrAA::kNo, vm,
SkRect::MakeWH(2 * S, 2 * S));
// now update the lower right of the texture in first pass
// or upper right in second pass
for (int y = 0; y < S; ++y) {
for (int x = 0; x < S; ++x) {
gTextureData[y * kStride + x] = ((x + y) % 2) ? (i ? green : red) : blue;
}
}
if (!tContext->writePixels(ii, gTextureData.get(), 4 * kStride, S, i ? 0 : S)) {
continue;
}
renderTargetContext->drawRect(clip, std::move(paint), GrAA::kNo, vm,
SkRect::MakeWH(2 * S, 2 * S));
}
}
#endif