skia2/gm/crosscontextimage.cpp

72 lines
2.3 KiB
C++
Raw Normal View History

/*
* Copyright 2017 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "gm/gm.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkData.h"
#include "include/core/SkFilterQuality.h"
#include "include/core/SkImage.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPixmap.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkString.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrRecordingContext.h"
#include "tools/Resources.h"
class GrSurfaceDrawContext;
DEF_SIMPLE_GPU_GM_CAN_FAIL(cross_context_image, context, rtc, canvas, errorMsg,
3 * 256 + 40, 256 + 128 + 30) {
sk_sp<SkData> encodedData = GetResourceAsData("images/mandrill_256.png");
if (!encodedData) {
*errorMsg = "Could not load mandrill_256.png. Did you forget to set the resourcePath?";
return skiagm::DrawResult::kFail;
}
Reland "Migrate MakeCrossContextFromPixmap to GrDirectContext" This reverts commit ae04cc9099b367c81a11a6e77162410e7941056a. Reason for revert: Flutter g3 roll complete Original change's description: > Revert "Migrate MakeCrossContextFromPixmap to GrDirectContext" > > This reverts commit 066f7d6b1ada68217fba365d30f6dd766ca0139b. > > Reason for revert: Cant land until flutter PR 20235 reaches g3 > > Original change's description: > > Migrate MakeCrossContextFromPixmap to GrDirectContext > > > > This function isn't used by Chrome so we migrate directly. > > Flutter migration is at https://github.com/flutter/engine/pull/20235 > > > > Bug: skia:104662 > > Change-Id: I9d875acdbd162f50a6d86b3a4cae3f400e4dd38f > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/305180 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: I100a87075ffdf5c0cda78c95f1cfe3310f97630e > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:104662 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/308501 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com # Not skipping CQ checks because original CL landed > 1 day ago. Bug: skia:104662 Change-Id: I32e36aa1c70902296e7f28d0f8b52d4e55b264a4 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309320 Reviewed-by: Adlai Holler <adlai@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Adlai Holler <adlai@google.com>
2020-08-11 15:47:47 +00:00
auto dContext = context->asDirectContext();
if (!dContext) {
*errorMsg = "CrossContext image creation requires a direct context.";
return skiagm::DrawResult::kSkip;
}
sk_sp<SkImage> images[3];
images[0] = SkImage::MakeFromEncoded(encodedData);
SkBitmap bmp;
SkPixmap pixmap;
SkAssertResult(images[0]->asLegacyBitmap(&bmp) &&
bmp.peekPixels(&pixmap));
Reland "Migrate MakeCrossContextFromPixmap to GrDirectContext" This reverts commit ae04cc9099b367c81a11a6e77162410e7941056a. Reason for revert: Flutter g3 roll complete Original change's description: > Revert "Migrate MakeCrossContextFromPixmap to GrDirectContext" > > This reverts commit 066f7d6b1ada68217fba365d30f6dd766ca0139b. > > Reason for revert: Cant land until flutter PR 20235 reaches g3 > > Original change's description: > > Migrate MakeCrossContextFromPixmap to GrDirectContext > > > > This function isn't used by Chrome so we migrate directly. > > Flutter migration is at https://github.com/flutter/engine/pull/20235 > > > > Bug: skia:104662 > > Change-Id: I9d875acdbd162f50a6d86b3a4cae3f400e4dd38f > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/305180 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: I100a87075ffdf5c0cda78c95f1cfe3310f97630e > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:104662 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/308501 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com # Not skipping CQ checks because original CL landed > 1 day ago. Bug: skia:104662 Change-Id: I32e36aa1c70902296e7f28d0f8b52d4e55b264a4 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309320 Reviewed-by: Adlai Holler <adlai@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Adlai Holler <adlai@google.com>
2020-08-11 15:47:47 +00:00
images[1] = SkImage::MakeCrossContextFromPixmap(dContext, pixmap, false);
images[2] = SkImage::MakeCrossContextFromPixmap(dContext, pixmap, true);
canvas->translate(10, 10);
for (size_t i = 0; i < SK_ARRAY_COUNT(images); ++i) {
canvas->save();
canvas->drawImage(images[i], 0, 0);
canvas->translate(0, 256 + 10);
Reland "Migrate MakeCrossContextFromPixmap to GrDirectContext" This reverts commit ae04cc9099b367c81a11a6e77162410e7941056a. Reason for revert: Flutter g3 roll complete Original change's description: > Revert "Migrate MakeCrossContextFromPixmap to GrDirectContext" > > This reverts commit 066f7d6b1ada68217fba365d30f6dd766ca0139b. > > Reason for revert: Cant land until flutter PR 20235 reaches g3 > > Original change's description: > > Migrate MakeCrossContextFromPixmap to GrDirectContext > > > > This function isn't used by Chrome so we migrate directly. > > Flutter migration is at https://github.com/flutter/engine/pull/20235 > > > > Bug: skia:104662 > > Change-Id: I9d875acdbd162f50a6d86b3a4cae3f400e4dd38f > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/305180 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: I100a87075ffdf5c0cda78c95f1cfe3310f97630e > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:104662 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/308501 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com # Not skipping CQ checks because original CL landed > 1 day ago. Bug: skia:104662 Change-Id: I32e36aa1c70902296e7f28d0f8b52d4e55b264a4 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309320 Reviewed-by: Adlai Holler <adlai@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Adlai Holler <adlai@google.com>
2020-08-11 15:47:47 +00:00
canvas->drawImage(images[i]->makeSubset(SkIRect::MakeXYWH(64, 64, 128, 128), dContext),
0, 0);
canvas->translate(128, 0);
canvas->drawImageRect(images[i], SkRect::MakeWH(128, 128),
SkSamplingOptions(SkFilterMode::kLinear,
SkMipmapMode::kLinear));
canvas->restore();
canvas->translate(256 + 10, 0);
}
return skiagm::DrawResult::kOk;
}