Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2548)

Unified Diff: experimental/skpdiff/SkCLImageDiffer.cpp

Issue 19374006: make OpenCL optional for skpdiff (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: this-> Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « experimental/skpdiff/SkCLImageDiffer.h ('k') | experimental/skpdiff/SkDifferentPixelsMetric.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: experimental/skpdiff/SkCLImageDiffer.cpp
diff --git a/experimental/skpdiff/SkCLImageDiffer.cpp b/experimental/skpdiff/SkCLImageDiffer.cpp
index 0c27e0989b6c852fdfbf169821cfc0a5fbb2a721..d1e6958ab9f77cb1324ab545d19bc3699f87fe85 100644
--- a/experimental/skpdiff/SkCLImageDiffer.cpp
+++ b/experimental/skpdiff/SkCLImageDiffer.cpp
@@ -1,4 +1,3 @@
-
/*
* Copyright 2013 Google Inc.
*
@@ -18,7 +17,6 @@ SkCLImageDiffer::SkCLImageDiffer() {
fIsGood = false;
}
-
bool SkCLImageDiffer::init(cl_device_id device, cl_context context) {
fContext = context;
fDevice = device;
@@ -122,139 +120,3 @@ bool SkCLImageDiffer::makeImage2D(SkBitmap* bitmap, cl_mem* image) {
return true;
}
-
-
-////////////////////////////////////////////////////////////////
-
-struct SkDifferentPixelsImageDiffer::QueuedDiff {
- bool finished;
- double result;
- int numDiffPixels;
- SkIPoint* poi;
- cl_mem baseline;
- cl_mem test;
- cl_mem resultsBuffer;
- cl_mem poiBuffer;
-};
-
-const char* SkDifferentPixelsImageDiffer::getName() {
- return "different_pixels";
-}
-
-int SkDifferentPixelsImageDiffer::queueDiff(SkBitmap * baseline, SkBitmap * test) {
- int diffID = fQueuedDiffs.count();
- double startTime = get_seconds();
- QueuedDiff* diff = fQueuedDiffs.push();
-
- // If we never end up running the kernel, include some safe defaults in the result.
- diff->finished = false;
- diff->result = -1.0;
- diff->numDiffPixels = 0;
- diff->poi = NULL;
-
- // Ensure the images are comparable
- if (baseline->width() != test->width() || baseline->height() != test->height() ||
- baseline->width() <= 0 || baseline->height() <= 0) {
- diff->finished = true;
- return diffID;
- }
-
- // Upload images to the CL device
- if (!this->makeImage2D(baseline, &diff->baseline) || !this->makeImage2D(test, &diff->test)) {
- diff->finished = true;
- fIsGood = false;
- return -1;
- }
-
- // A small hack that makes calculating percentage difference easier later on.
- diff->result = 1.0 / ((double)baseline->width() * baseline->height());
-
- // Make a buffer to store results into. It must be initialized with pointers to memory.
- static const int kZero = 0;
- // We know OpenCL won't write to it because we use CL_MEM_COPY_HOST_PTR
- diff->resultsBuffer = clCreateBuffer(fContext, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,
- sizeof(int), (int*)&kZero, NULL);
-
- diff->poiBuffer = clCreateBuffer(fContext, CL_MEM_WRITE_ONLY,
- sizeof(int) * 2 * baseline->width() * baseline->height(),
- NULL, NULL);
-
- // Set all kernel arguments
- cl_int setArgErr = clSetKernelArg(fKernel, 0, sizeof(cl_mem), &diff->baseline);
- setArgErr |= clSetKernelArg(fKernel, 1, sizeof(cl_mem), &diff->test);
- setArgErr |= clSetKernelArg(fKernel, 2, sizeof(cl_mem), &diff->resultsBuffer);
- setArgErr |= clSetKernelArg(fKernel, 3, sizeof(cl_mem), &diff->poiBuffer);
- if (CL_SUCCESS != setArgErr) {
- SkDebugf("Set arg failed: %s\n", cl_error_to_string(setArgErr));
- fIsGood = false;
- return -1;
- }
-
- // Queue this diff on the CL device
- cl_event event;
- const size_t workSize[] = { baseline->width(), baseline->height() };
- cl_int enqueueErr;
- enqueueErr = clEnqueueNDRangeKernel(fCommandQueue, fKernel, 2, NULL, workSize,
- NULL, 0, NULL, &event);
- if (CL_SUCCESS != enqueueErr) {
- SkDebugf("Enqueue failed: %s\n", cl_error_to_string(enqueueErr));
- fIsGood = false;
- return -1;
- }
-
- // This makes things totally synchronous. Actual queue is not ready yet
- clWaitForEvents(1, &event);
- diff->finished = true;
-
- // Immediate read back the results
- clEnqueueReadBuffer(fCommandQueue, diff->resultsBuffer, CL_TRUE, 0,
- sizeof(int), &diff->numDiffPixels, 0, NULL, NULL);
- diff->result *= (double)diff->numDiffPixels;
- diff->result = (1.0 - diff->result);
-
- diff->poi = SkNEW_ARRAY(SkIPoint, diff->numDiffPixels);
- clEnqueueReadBuffer(fCommandQueue, diff->poiBuffer, CL_TRUE, 0,
- sizeof(SkIPoint) * diff->numDiffPixels, diff->poi, 0, NULL, NULL);
-
- // Release all the buffers created
- clReleaseMemObject(diff->poiBuffer);
- clReleaseMemObject(diff->resultsBuffer);
- clReleaseMemObject(diff->baseline);
- clReleaseMemObject(diff->test);
-
- SkDebugf("Time: %f\n", (get_seconds() - startTime));
-
- return diffID;
-}
-
-void SkDifferentPixelsImageDiffer::deleteDiff(int id) {
- QueuedDiff* diff = &fQueuedDiffs[id];
- if (NULL != diff->poi) {
- SkDELETE_ARRAY(diff->poi);
- diff->poi = NULL;
- }
-}
-
-bool SkDifferentPixelsImageDiffer::isFinished(int id) {
- return fQueuedDiffs[id].finished;
-}
-
-double SkDifferentPixelsImageDiffer::getResult(int id) {
- return fQueuedDiffs[id].result;
-}
-
-int SkDifferentPixelsImageDiffer::getPointsOfInterestCount(int id) {
- return fQueuedDiffs[id].numDiffPixels;
-}
-
-SkIPoint* SkDifferentPixelsImageDiffer::getPointsOfInterest(int id) {
- return fQueuedDiffs[id].poi;
-}
-
-bool SkDifferentPixelsImageDiffer::onInit() {
- if (!loadKernelFile("experimental/skpdiff/diff_pixels.cl", "diff", &fKernel)) {
- return false;
- }
-
- return true;
-}
« no previous file with comments | « experimental/skpdiff/SkCLImageDiffer.h ('k') | experimental/skpdiff/SkDifferentPixelsMetric.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698